-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
275 lines (231 loc) · 13.5 KB
/
build.zig
File metadata and controls
275 lines (231 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const options = b.addOptions();
const enable_debug_shadows = b.option(bool, "debug_shadows", "Enable debug shadow visualization resources") orelse false;
options.addOption(bool, "debug_shadows", enable_debug_shadows);
const smoke_test = b.option(bool, "smoke-test", "Enable automated smoke test mode (auto-loads world and exits)") orelse false;
options.addOption(bool, "smoke_test", smoke_test);
const skip_present = b.option(bool, "skip-present", "Skip presentation (headless mode) to avoid driver crashes") orelse false;
options.addOption(bool, "skip_present", skip_present);
const screenshot_path = b.option([]const u8, "screenshot-path", "Capture a PPM screenshot after N frames and exit (menu mode)") orelse "";
options.addOption([]const u8, "screenshot_path", screenshot_path);
const benchmark = b.option(bool, "benchmark", "Enable benchmark mode") orelse false;
options.addOption(bool, "benchmark", benchmark);
const benchmark_preset = b.option([]const u8, "benchmark-preset", "Graphics preset to benchmark (low, medium, high, ultra, extreme)") orelse "medium";
options.addOption([]const u8, "benchmark_preset", benchmark_preset);
const benchmark_duration = b.option(u32, "benchmark-duration", "Benchmark duration in seconds") orelse 60;
options.addOption(u32, "benchmark_duration", benchmark_duration);
const benchmark_output = b.option([]const u8, "benchmark-output", "Benchmark JSON output path") orelse "benchmark_results.json";
options.addOption([]const u8, "benchmark_output", benchmark_output);
const zig_math = b.createModule(.{
.root_source_file = b.path("libs/zig-math/math.zig"),
.target = target,
.optimize = optimize,
});
const zig_noise = b.createModule(.{
.root_source_file = b.path("libs/zig-noise/noise.zig"),
.target = target,
.optimize = optimize,
});
const root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
root_module.addImport("zig-math", zig_math);
root_module.addImport("zig-noise", zig_noise);
root_module.addOptions("build_options", options);
root_module.addIncludePath(b.path("libs/stb"));
const exe = b.addExecutable(.{
.name = "zigcraft",
.root_module = root_module,
});
exe.linkLibC();
exe.addCSourceFile(.{
.file = b.path("libs/stb/stb_image_impl.c"),
.flags = &.{"-std=c99"},
});
exe.linkSystemLibrary("sdl3");
exe.linkSystemLibrary("vulkan");
b.installArtifact(exe);
const shader_cmd = b.addSystemCommand(&.{ "sh", "-c", "for f in assets/shaders/vulkan/*.vert assets/shaders/vulkan/*.frag assets/shaders/vulkan/*.comp; do glslangValidator -V \"$f\" -o \"$f.spv\"; done" });
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
run_cmd.step.dependOn(&shader_cmd.step);
run_cmd.setCwd(b.path("."));
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const benchmark_options = b.addOptions();
benchmark_options.addOption(bool, "debug_shadows", enable_debug_shadows);
benchmark_options.addOption(bool, "smoke_test", false);
benchmark_options.addOption(bool, "skip_present", true);
benchmark_options.addOption([]const u8, "screenshot_path", "");
benchmark_options.addOption(bool, "benchmark", true);
benchmark_options.addOption([]const u8, "benchmark_preset", benchmark_preset);
benchmark_options.addOption(u32, "benchmark_duration", benchmark_duration);
benchmark_options.addOption([]const u8, "benchmark_output", benchmark_output);
const benchmark_root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
benchmark_root_module.addImport("zig-math", zig_math);
benchmark_root_module.addImport("zig-noise", zig_noise);
benchmark_root_module.addOptions("build_options", benchmark_options);
benchmark_root_module.addIncludePath(b.path("libs/stb"));
const benchmark_exe = b.addExecutable(.{
.name = "benchmark",
.root_module = benchmark_root_module,
});
benchmark_exe.linkLibC();
benchmark_exe.addCSourceFile(.{
.file = b.path("libs/stb/stb_image_impl.c"),
.flags = &.{"-std=c99"},
});
benchmark_exe.linkSystemLibrary("sdl3");
benchmark_exe.linkSystemLibrary("vulkan");
b.installArtifact(benchmark_exe);
const benchmark_run_cmd = b.addRunArtifact(benchmark_exe);
benchmark_run_cmd.step.dependOn(b.getInstallStep());
benchmark_run_cmd.step.dependOn(&shader_cmd.step);
benchmark_run_cmd.setCwd(b.path("."));
const benchmark_step = b.step("benchmark", "Run benchmark harness");
benchmark_step.dependOn(&benchmark_run_cmd.step);
const test_root_module = b.createModule(.{
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
});
test_root_module.addImport("zig-math", zig_math);
test_root_module.addImport("zig-noise", zig_noise);
test_root_module.addOptions("build_options", options);
const exe_tests = b.addTest(.{
.root_module = test_root_module,
});
exe_tests.linkLibC();
exe_tests.linkSystemLibrary("sdl3");
exe_tests.linkSystemLibrary("vulkan");
exe_tests.addIncludePath(b.path("libs/stb"));
const test_step = b.step("test", "Run unit tests");
const run_exe_tests = b.addRunArtifact(exe_tests);
run_exe_tests.step.dependOn(&shader_cmd.step);
test_step.dependOn(&run_exe_tests.step);
const integration_root_module = b.createModule(.{
.root_source_file = b.path("src/integration_test.zig"),
.target = target,
.optimize = optimize,
});
integration_root_module.addImport("zig-math", zig_math);
integration_root_module.addImport("zig-noise", zig_noise);
integration_root_module.addOptions("build_options", options);
integration_root_module.addIncludePath(b.path("libs/stb"));
const exe_integration_tests = b.addTest(.{
.root_module = integration_root_module,
});
exe_integration_tests.linkLibC();
exe_integration_tests.addCSourceFile(.{
.file = b.path("libs/stb/stb_image_impl.c"),
.flags = &.{"-std=c99"},
});
exe_integration_tests.linkSystemLibrary("sdl3");
exe_integration_tests.linkSystemLibrary("vulkan");
const test_integration_step = b.step("test-integration", "Run integration smoke test");
const run_integration_tests = b.addRunArtifact(exe_integration_tests);
run_integration_tests.stdio_limit = .unlimited;
run_integration_tests.step.dependOn(&shader_cmd.step);
test_integration_step.dependOn(&run_integration_tests.step);
// Robust Vulkan demo executable
const robust_demo = b.addExecutable(.{
.name = "robust-demo",
.root_module = b.createModule(.{
.root_source_file = b.path("src/robust_demo.zig"),
.target = target,
.optimize = optimize,
}),
});
robust_demo.root_module.addOptions("build_options", options);
robust_demo.linkLibC();
robust_demo.linkSystemLibrary("sdl3");
robust_demo.linkSystemLibrary("vulkan");
robust_demo.addIncludePath(b.path("libs/stb"));
b.installArtifact(robust_demo);
const integration_robustness = b.addExecutable(.{
.name = "test-robustness",
.root_module = b.createModule(.{
.root_source_file = b.path("src/integration_test_robustness.zig"),
.target = target,
.optimize = optimize,
}),
});
integration_robustness.root_module.addOptions("build_options", options);
integration_robustness.linkLibC();
integration_robustness.linkSystemLibrary("sdl3"); // Needed for C imports if any
const test_robustness_run = b.addRunArtifact(integration_robustness);
// Ensure robust-demo is built first
test_robustness_run.step.dependOn(&b.addInstallArtifact(robust_demo, .{}).step);
const test_robustness_step = b.step("test-robustness", "Run robustness integration test");
test_robustness_step.dependOn(&test_robustness_run.step);
const run_robust_cmd = b.addRunArtifact(robust_demo);
run_robust_cmd.step.dependOn(b.getInstallStep());
const run_robust_step = b.step("run-robust", "Run the GPU robustness demo");
run_robust_step.dependOn(&run_robust_cmd.step);
const validate_vulkan_terrain_vert = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/terrain.vert" });
const validate_vulkan_terrain_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/terrain.frag" });
const validate_vulkan_shadow_vert = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/shadow.vert" });
const validate_vulkan_shadow_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/shadow.frag" });
const validate_vulkan_sky_vert = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/sky.vert" });
const validate_vulkan_sky_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/sky.frag" });
const validate_vulkan_ui_vert = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/ui.vert" });
const validate_vulkan_ui_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/ui.frag" });
const validate_vulkan_ui_tex_vert = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/ui_tex.vert" });
const validate_vulkan_ui_tex_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/ui_tex.frag" });
const validate_vulkan_cloud_vert = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/cloud.vert" });
const validate_vulkan_cloud_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/cloud.frag" });
const validate_vulkan_debug_shadow_vert = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/debug_shadow.vert" });
const validate_vulkan_debug_shadow_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/debug_shadow.frag" });
const validate_vulkan_ssao_vert = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/ssao.vert" });
const validate_vulkan_ssao_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/ssao.frag" });
const validate_vulkan_ssao_blur_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/ssao_blur.frag" });
const validate_vulkan_g_pass_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/g_pass.frag" });
const validate_vulkan_taa_vert = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/taa.vert" });
const validate_vulkan_taa_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/taa.frag" });
const validate_vulkan_lpv_inject_comp = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/lpv_inject.comp" });
const validate_vulkan_lpv_propagate_comp = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/lpv_propagate.comp" });
const validate_vulkan_culling_comp = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/culling.comp" });
const validate_vulkan_depth_pyramid_comp = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/depth_pyramid.comp" });
const validate_vulkan_water_vert = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/water.vert" });
const validate_vulkan_water_frag = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/water.frag" });
const validate_vulkan_mesh_comp = b.addSystemCommand(&.{ "glslangValidator", "-V", "assets/shaders/vulkan/mesh.comp" });
test_step.dependOn(&validate_vulkan_terrain_vert.step);
test_step.dependOn(&validate_vulkan_terrain_frag.step);
test_step.dependOn(&validate_vulkan_shadow_vert.step);
test_step.dependOn(&validate_vulkan_shadow_frag.step);
test_step.dependOn(&validate_vulkan_sky_vert.step);
test_step.dependOn(&validate_vulkan_sky_frag.step);
test_step.dependOn(&validate_vulkan_ui_vert.step);
test_step.dependOn(&validate_vulkan_ui_frag.step);
test_step.dependOn(&validate_vulkan_ui_tex_vert.step);
test_step.dependOn(&validate_vulkan_ui_tex_frag.step);
test_step.dependOn(&validate_vulkan_cloud_vert.step);
test_step.dependOn(&validate_vulkan_cloud_frag.step);
test_step.dependOn(&validate_vulkan_debug_shadow_vert.step);
test_step.dependOn(&validate_vulkan_debug_shadow_frag.step);
test_step.dependOn(&validate_vulkan_ssao_vert.step);
test_step.dependOn(&validate_vulkan_ssao_frag.step);
test_step.dependOn(&validate_vulkan_ssao_blur_frag.step);
test_step.dependOn(&validate_vulkan_g_pass_frag.step);
test_step.dependOn(&validate_vulkan_taa_vert.step);
test_step.dependOn(&validate_vulkan_taa_frag.step);
test_step.dependOn(&validate_vulkan_lpv_inject_comp.step);
test_step.dependOn(&validate_vulkan_lpv_propagate_comp.step);
test_step.dependOn(&validate_vulkan_culling_comp.step);
test_step.dependOn(&validate_vulkan_depth_pyramid_comp.step);
test_step.dependOn(&validate_vulkan_water_vert.step);
test_step.dependOn(&validate_vulkan_water_frag.step);
test_step.dependOn(&validate_vulkan_mesh_comp.step);
}