-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
719 lines (642 loc) · 44.2 KB
/
build.zig
File metadata and controls
719 lines (642 loc) · 44.2 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
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 enable_imgui = b.option(bool, "imgui", "Enable Dear ImGui debug UI integration") orelse true;
options.addOption(bool, "imgui", enable_imgui);
const engine_ui_options = b.addOptions();
engine_ui_options.addOption(bool, "imgui", enable_imgui);
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 chunk_debug_mode = b.option(bool, "chunk-debug-mode", "Disable LOD, water, caves, and decorations for chunk-only debugging") orelse false;
options.addOption(bool, "chunk_debug_mode", chunk_debug_mode);
const chunk_debug_enable = b.option([]const u8, "chunk-debug-enable", "Re-enable one subsystem in chunk-debug-mode (lod, water, caves, decorations)") orelse "";
options.addOption([]const u8, "chunk_debug_enable", chunk_debug_enable);
const auto_world = b.option([]const u8, "auto-world", "Auto-open a world generator directly by id or alias (normal, overworld, overworld-v2, flat, test)") orelse "";
options.addOption([]const u8, "auto_world", auto_world);
const auto_preset = b.option([]const u8, "auto-preset", "Graphics preset to apply for auto-world launches (low, medium, high, ultra, extreme)") orelse "";
options.addOption([]const u8, "auto_preset", auto_preset);
const startup_diagnostic_seconds = b.option(u32, "startup-diagnostic-seconds", "Wait N seconds after auto-world startup, log chunk counts, and exit") orelse 0;
options.addOption(u32, "startup_diagnostic_seconds", startup_diagnostic_seconds);
const world_lod_options = b.addOptions();
world_lod_options.addOption(u32, "startup_diagnostic_seconds", startup_diagnostic_seconds);
const world_runtime_options = b.addOptions();
world_runtime_options.addOption(u32, "startup_diagnostic_seconds", startup_diagnostic_seconds);
world_runtime_options.addOption(bool, "world_runtime_module", true);
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 monitor_index = b.option(i32, "monitor-index", "Open the game window on a specific SDL display index (0-based, -1 = default)") orelse -1;
options.addOption(i32, "monitor_index", monitor_index);
const monitor_name = b.option([]const u8, "monitor-name", "Move the game window to a named Hyprland monitor (e.g. DP-2)") orelse "";
options.addOption([]const u8, "monitor_name", monitor_name);
const window_video_driver = b.option([]const u8, "window-video-driver", "SDL video driver override for the game window (x11, wayland, or empty)") orelse "";
options.addOption([]const u8, "window_video_driver", window_video_driver);
const window_no_focus = b.option(bool, "window-no-focus", "Create the game window without taking keyboard focus") orelse false;
options.addOption(bool, "window_no_focus", window_no_focus);
const engine_graphics_options = b.addOptions();
engine_graphics_options.addOption(bool, "debug_shadows", enable_debug_shadows);
engine_graphics_options.addOption(bool, "chunk_debug_mode", chunk_debug_mode);
engine_graphics_options.addOption([]const u8, "chunk_debug_enable", chunk_debug_enable);
engine_graphics_options.addOption(bool, "skip_present", skip_present);
const screenshot_path = b.option([]const u8, "screenshot-path", "Capture a PNG screenshot after N frames and exit") orelse "";
options.addOption([]const u8, "screenshot_path", screenshot_path);
const screenshot_frame = b.option(u32, "screenshot-frame", "Frame number to capture when screenshot-path is set") orelse 120;
options.addOption(u32, "screenshot_frame", screenshot_frame);
const screenshot_delay_seconds = b.option(u32, "screenshot-delay-seconds", "Seconds to wait after screenshot target is ready before capture") orelse 0;
options.addOption(u32, "screenshot_delay_seconds", screenshot_delay_seconds);
const shadow_test_scene = b.option(bool, "shadow-test-scene", "Launch the deterministic shadow/cave lighting test scene") orelse false;
options.addOption(bool, "shadow_test_scene", shadow_test_scene);
const shadow_test_variant = b.option([]const u8, "shadow-test-variant", "Shadow test scene variant (dug-cave, bend)") orelse "dug-cave";
options.addOption([]const u8, "shadow_test_variant", shadow_test_variant);
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 fs_module = b.createModule(.{
.root_source_file = b.path("modules/engine-core/src/fs.zig"),
.target = target,
.optimize = optimize,
});
const sync_module = b.createModule(.{
.root_source_file = b.path("modules/engine-core/src/sync.zig"),
.target = target,
.optimize = optimize,
});
const c_module = b.createModule(.{
.root_source_file = b.path("src/c.zig"),
.target = target,
.optimize = optimize,
});
c_module.addIncludePath(b.path("libs/stb"));
c_module.linkSystemLibrary("sdl3", .{});
c_module.linkSystemLibrary("vulkan", .{});
const engine_math = b.createModule(.{ .root_source_file = b.path("modules/engine-math/src/root.zig"), .target = target, .optimize = optimize });
const engine_audio = b.createModule(.{ .root_source_file = b.path("modules/engine-audio/src/root.zig"), .target = target, .optimize = optimize });
const engine_core = b.createModule(.{ .root_source_file = b.path("modules/engine-core/src/root.zig"), .target = target, .optimize = optimize });
const engine_ecs = b.createModule(.{ .root_source_file = b.path("modules/engine-ecs/src/root.zig"), .target = target, .optimize = optimize });
const engine_input = b.createModule(.{ .root_source_file = b.path("modules/engine-input/src/root.zig"), .target = target, .optimize = optimize });
const engine_physics = b.createModule(.{ .root_source_file = b.path("modules/engine-physics/src/root.zig"), .target = target, .optimize = optimize });
const engine_rhi = b.createModule(.{ .root_source_file = b.path("modules/engine-rhi/src/root.zig"), .target = target, .optimize = optimize });
const engine_graphics = b.createModule(.{ .root_source_file = b.path("modules/engine-graphics/src/root.zig"), .target = target, .optimize = optimize });
const engine_assets_impl = b.createModule(.{ .root_source_file = b.path("modules/engine-graphics/src/assets_root.zig"), .target = target, .optimize = optimize });
const engine_camera_impl = b.createModule(.{ .root_source_file = b.path("modules/engine-graphics/src/camera_root.zig"), .target = target, .optimize = optimize });
const engine_clouds_impl = b.createModule(.{ .root_source_file = b.path("modules/engine-graphics/src/clouds_root.zig"), .target = target, .optimize = optimize });
const engine_atmosphere_impl = b.createModule(.{ .root_source_file = b.path("modules/engine-graphics/src/atmosphere_root.zig"), .target = target, .optimize = optimize });
const engine_shadows_impl = b.createModule(.{ .root_source_file = b.path("modules/engine-graphics/src/shadows_root.zig"), .target = target, .optimize = optimize });
const engine_lighting_impl = b.createModule(.{ .root_source_file = b.path("modules/engine-graphics/src/lighting_root.zig"), .target = target, .optimize = optimize });
const engine_assets = b.createModule(.{ .root_source_file = b.path("modules/engine-assets/src/root.zig"), .target = target, .optimize = optimize });
const engine_camera = b.createModule(.{ .root_source_file = b.path("modules/engine-camera/src/root.zig"), .target = target, .optimize = optimize });
const engine_clouds = b.createModule(.{ .root_source_file = b.path("modules/engine-clouds/src/root.zig"), .target = target, .optimize = optimize });
const engine_atmosphere = b.createModule(.{ .root_source_file = b.path("modules/engine-atmosphere/src/root.zig"), .target = target, .optimize = optimize });
const engine_shadows = b.createModule(.{ .root_source_file = b.path("modules/engine-shadows/src/root.zig"), .target = target, .optimize = optimize });
const engine_lighting = b.createModule(.{ .root_source_file = b.path("modules/engine-lighting/src/root.zig"), .target = target, .optimize = optimize });
const engine_ui = b.createModule(.{ .root_source_file = b.path("modules/engine-ui/src/root.zig"), .target = target, .optimize = optimize });
const world_core = b.createModule(.{ .root_source_file = b.path("modules/world-core/src/root.zig"), .target = target, .optimize = optimize });
const worldgen_api = b.createModule(.{ .root_source_file = b.path("modules/worldgen-api/src/root.zig"), .target = target, .optimize = optimize });
const worldgen_common = b.createModule(.{ .root_source_file = b.path("modules/worldgen-common/src/root.zig"), .target = target, .optimize = optimize });
const worldgen_overworld = b.createModule(.{ .root_source_file = b.path("modules/worldgen-overworld/src/root.zig"), .target = target, .optimize = optimize });
const worldgen_overworld_v2 = b.createModule(.{ .root_source_file = b.path("modules/worldgen-overworld-v2/src/root.zig"), .target = target, .optimize = optimize });
const worldgen_flat = b.createModule(.{ .root_source_file = b.path("modules/worldgen-flat/src/root.zig"), .target = target, .optimize = optimize });
const worldgen_test = b.createModule(.{ .root_source_file = b.path("modules/worldgen-test/src/root.zig"), .target = target, .optimize = optimize });
const world_worldgen = b.createModule(.{ .root_source_file = b.path("modules/world-worldgen/src/root.zig"), .target = target, .optimize = optimize });
const world_meshing = b.createModule(.{ .root_source_file = b.path("modules/world-meshing/src/root.zig"), .target = target, .optimize = optimize });
const world_lod = b.createModule(.{ .root_source_file = b.path("modules/world-lod/src/root.zig"), .target = target, .optimize = optimize });
const world_runtime = b.createModule(.{ .root_source_file = b.path("modules/world-runtime/src/root.zig"), .target = target, .optimize = optimize });
const world_persistence = b.createModule(.{ .root_source_file = b.path("modules/world-persistence/src/root.zig"), .target = target, .optimize = optimize });
const game_core = b.createModule(.{ .root_source_file = b.path("modules/game-core/src/root.zig"), .target = target, .optimize = optimize });
const game_ui = b.createModule(.{ .root_source_file = b.path("modules/game-ui/src/root.zig"), .target = target, .optimize = optimize });
addSharedImports(engine_math, zig_math, zig_noise, fs_module, sync_module, c_module, options);
addSharedImports(engine_audio, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_audio.addImport("engine-math", engine_math);
engine_audio.addImport("engine-core", engine_core);
addSharedImports(engine_core, zig_math, zig_noise, fs_module, sync_module, c_module, options);
addSharedImports(engine_ecs, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_ecs.addImport("engine-core", engine_core);
engine_ecs.addImport("engine-math", engine_math);
engine_ecs.addImport("engine-physics", engine_physics);
engine_ecs.addImport("engine-rhi", engine_rhi);
addSharedImports(engine_input, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_input.addImport("engine-core", engine_core);
addSharedImports(engine_physics, zig_math, zig_noise, fs_module, sync_module, c_module, options);
addSharedImports(engine_rhi, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_rhi.addImport("engine-math", engine_math);
engine_rhi.addImport("engine-core", engine_core);
addSharedImports(engine_assets_impl, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_assets_impl.addImport("engine-core", engine_core);
engine_assets_impl.addImport("engine-rhi", engine_rhi);
addSharedImports(engine_assets, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_assets.addImport("engine-assets-impl", engine_assets_impl);
addSharedImports(engine_camera_impl, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_camera_impl.addImport("engine-core", engine_core);
engine_camera_impl.addImport("engine-input", engine_input);
engine_camera_impl.addImport("engine-math", engine_math);
addSharedImports(engine_camera, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_camera.addImport("engine-camera-impl", engine_camera_impl);
addSharedImports(engine_clouds_impl, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_clouds_impl.addImport("engine-math", engine_math);
engine_clouds_impl.addImport("engine-rhi", engine_rhi);
addSharedImports(engine_clouds, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_clouds.addImport("engine-clouds-impl", engine_clouds_impl);
addSharedImports(engine_atmosphere_impl, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_atmosphere_impl.addImport("engine-core", engine_core);
engine_atmosphere_impl.addImport("engine-math", engine_math);
engine_atmosphere_impl.addImport("engine-rhi", engine_rhi);
addSharedImports(engine_atmosphere, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_atmosphere.addImport("engine-atmosphere-impl", engine_atmosphere_impl);
addSharedImports(engine_shadows_impl, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_shadows_impl.addImport("engine-core", engine_core);
engine_shadows_impl.addImport("engine-math", engine_math);
engine_shadows_impl.addImport("engine-rhi", engine_rhi);
addSharedImports(engine_shadows, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_shadows.addImport("engine-shadows-impl", engine_shadows_impl);
addSharedImports(engine_lighting_impl, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_lighting_impl.addImport("engine-core", engine_core);
engine_lighting_impl.addImport("engine-math", engine_math);
engine_lighting_impl.addImport("engine-rhi", engine_rhi);
addSharedImports(engine_lighting, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_lighting.addImport("engine-lighting-impl", engine_lighting_impl);
addSharedImports(engine_graphics, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_graphics.addImport("engine-assets", engine_assets);
engine_graphics.addImport("engine-atmosphere", engine_atmosphere);
engine_graphics.addImport("engine-camera", engine_camera);
engine_graphics.addImport("engine-clouds", engine_clouds);
engine_graphics.addImport("engine-lighting", engine_lighting);
engine_graphics.addImport("engine-math", engine_math);
engine_graphics.addImport("engine-core", engine_core);
engine_graphics.addImport("engine-input", engine_input);
engine_graphics.addImport("engine-rhi", engine_rhi);
engine_graphics.addImport("engine-shadows", engine_shadows);
engine_graphics.addOptions("engine_graphics_options", engine_graphics_options);
addSharedImports(engine_ui, zig_math, zig_noise, fs_module, sync_module, c_module, options);
engine_ui.addImport("engine-math", engine_math);
engine_ui.addImport("engine-core", engine_core);
engine_ui.addImport("engine-rhi", engine_rhi);
engine_ui.addOptions("engine_ui_options", engine_ui_options);
engine_ui.linkSystemLibrary("sdl3", .{});
engine_ui.linkSystemLibrary("vulkan", .{});
if (enable_imgui) {
engine_ui.linkSystemLibrary("cimgui", .{ .use_pkg_config = .force });
engine_ui.link_libcpp = true;
}
addSharedImports(world_core, zig_math, zig_noise, fs_module, sync_module, c_module, options);
world_core.addImport("engine-core", engine_core);
world_core.addImport("engine-math", engine_math);
addSharedImports(worldgen_api, zig_math, zig_noise, fs_module, sync_module, c_module, options);
worldgen_api.addImport("world-core", world_core);
addSharedImports(worldgen_common, zig_math, zig_noise, fs_module, sync_module, c_module, options);
worldgen_common.addImport("world-core", world_core);
const worldgen_overworld_options = b.addOptions();
worldgen_overworld_options.addOption(bool, "chunk_debug_mode", chunk_debug_mode);
worldgen_overworld_options.addOption([]const u8, "chunk_debug_enable", chunk_debug_enable);
addSharedImports(worldgen_overworld, zig_math, zig_noise, fs_module, sync_module, c_module, options);
worldgen_overworld.addImport("engine-core", engine_core);
worldgen_overworld.addImport("engine-rhi", engine_rhi);
worldgen_overworld.addImport("world-core", world_core);
worldgen_overworld.addImport("worldgen-api", worldgen_api);
worldgen_overworld.addImport("worldgen-common", worldgen_common);
worldgen_overworld.addOptions("worldgen_overworld_options", worldgen_overworld_options);
addSharedImports(worldgen_overworld_v2, zig_math, zig_noise, fs_module, sync_module, c_module, options);
worldgen_overworld_v2.addImport("world-core", world_core);
worldgen_overworld_v2.addImport("worldgen-api", worldgen_api);
worldgen_overworld_v2.addImport("worldgen-common", worldgen_common);
addSharedImports(worldgen_flat, zig_math, zig_noise, fs_module, sync_module, c_module, options);
worldgen_flat.addImport("world-core", world_core);
worldgen_flat.addImport("worldgen-api", worldgen_api);
worldgen_flat.addImport("worldgen-common", worldgen_common);
const worldgen_test_options = b.addOptions();
worldgen_test_options.addOption([]const u8, "shadow_test_variant", shadow_test_variant);
addSharedImports(worldgen_test, zig_math, zig_noise, fs_module, sync_module, c_module, options);
worldgen_test.addImport("world-core", world_core);
worldgen_test.addImport("worldgen-api", worldgen_api);
worldgen_test.addImport("worldgen-common", worldgen_common);
worldgen_test.addOptions("worldgen_test_options", worldgen_test_options);
addSharedImports(world_worldgen, zig_math, zig_noise, fs_module, sync_module, c_module, options);
addSharedImports(world_meshing, zig_math, zig_noise, fs_module, sync_module, c_module, options);
world_meshing.addImport("engine-core", engine_core);
world_meshing.addImport("engine-assets", engine_assets);
world_meshing.addImport("engine-graphics", engine_graphics);
world_meshing.addImport("engine-rhi", engine_rhi);
world_meshing.addImport("world-core", world_core);
addSharedImports(world_lod, zig_math, zig_noise, fs_module, sync_module, c_module, options);
world_lod.addImport("engine-core", engine_core);
world_lod.addImport("engine-assets", engine_assets);
world_lod.addImport("engine-graphics", engine_graphics);
world_lod.addImport("engine-math", engine_math);
world_lod.addImport("engine-rhi", engine_rhi);
world_lod.addImport("world-meshing", world_meshing);
world_lod.addImport("world-core", world_core);
world_lod.addOptions("world_lod_options", world_lod_options);
addSharedImports(world_persistence, zig_math, zig_noise, fs_module, sync_module, c_module, options);
world_persistence.addImport("engine-core", engine_core);
world_persistence.addImport("world-core", world_core);
world_worldgen.addImport("engine-core", engine_core);
world_worldgen.addImport("engine-rhi", engine_rhi);
world_worldgen.addImport("world-core", world_core);
world_worldgen.addImport("worldgen-api", worldgen_api);
world_worldgen.addImport("worldgen-common", worldgen_common);
world_worldgen.addImport("worldgen-overworld", worldgen_overworld);
world_worldgen.addImport("worldgen-overworld-v2", worldgen_overworld_v2);
world_worldgen.addImport("worldgen-flat", worldgen_flat);
world_worldgen.addImport("worldgen-test", worldgen_test);
addSharedImports(world_runtime, zig_math, zig_noise, fs_module, sync_module, c_module, options);
world_runtime.addImport("engine-core", engine_core);
world_runtime.addImport("engine-assets", engine_assets);
world_runtime.addImport("engine-lighting", engine_lighting);
world_runtime.addImport("engine-shadows", engine_shadows);
world_runtime.addImport("engine-graphics", engine_graphics);
world_runtime.addImport("engine-math", engine_math);
world_runtime.addImport("engine-physics", engine_physics);
world_runtime.addImport("engine-rhi", engine_rhi);
world_runtime.addImport("engine-ui", engine_ui);
world_runtime.addImport("world-core", world_core);
world_runtime.addImport("world-lod", world_lod);
world_runtime.addImport("world-meshing", world_meshing);
world_runtime.addImport("world-persistence", world_persistence);
world_runtime.addImport("world-worldgen", world_worldgen);
world_runtime.addOptions("world_runtime_options", world_runtime_options);
addSharedImportsNoOptions(game_core, zig_math, zig_noise, fs_module, sync_module, c_module);
addProjectModuleImports(game_core, engine_math, engine_audio, engine_core, engine_ecs, engine_input, engine_physics, engine_rhi, engine_graphics, engine_assets, engine_camera, engine_clouds, engine_atmosphere, engine_shadows, engine_lighting, engine_ui, world_core, world_worldgen, world_meshing, world_lod, world_runtime, world_persistence);
addSharedImportsNoOptions(game_ui, zig_math, zig_noise, fs_module, sync_module, c_module);
addProjectModuleImports(game_ui, engine_math, engine_audio, engine_core, engine_ecs, engine_input, engine_physics, engine_rhi, engine_graphics, engine_assets, engine_camera, engine_clouds, engine_atmosphere, engine_shadows, engine_lighting, engine_ui, world_core, world_worldgen, world_meshing, world_lod, world_runtime, world_persistence);
game_ui.addImport("game-core", game_core);
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.addImport("fs", fs_module);
root_module.addImport("sync", sync_module);
root_module.addImport("c", c_module);
addProjectModuleImports(root_module, engine_math, engine_audio, engine_core, engine_ecs, engine_input, engine_physics, engine_rhi, engine_graphics, engine_assets, engine_camera, engine_clouds, engine_atmosphere, engine_shadows, engine_lighting, engine_ui, world_core, world_worldgen, world_meshing, world_lod, world_runtime, world_persistence);
root_module.addImport("game-core", game_core);
root_module.addImport("game-ui", game_ui);
root_module.addOptions("build_options", options);
root_module.addIncludePath(b.path("libs/stb"));
const exe = b.addExecutable(.{
.name = "zigcraft",
.root_module = root_module,
});
exe.root_module.link_libc = true;
exe.root_module.addCSourceFile(.{
.file = b.path("libs/stb/stb_image_impl.c"),
.flags = &.{"-std=c99"},
});
exe.root_module.addCSourceFile(.{
.file = b.path("libs/stb/stb_truetype_impl.c"),
.flags = &.{"-std=c99"},
});
exe.root_module.linkSystemLibrary("sdl3", .{});
exe.root_module.linkSystemLibrary("vulkan", .{});
if (enable_imgui) addCimgui(b, exe);
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, "imgui", enable_imgui);
benchmark_options.addOption(bool, "smoke_test", false);
benchmark_options.addOption(bool, "chunk_debug_mode", false);
benchmark_options.addOption([]const u8, "chunk_debug_enable", "");
benchmark_options.addOption([]const u8, "auto_world", "");
benchmark_options.addOption([]const u8, "auto_preset", "");
benchmark_options.addOption(u32, "startup_diagnostic_seconds", 0);
benchmark_options.addOption(i32, "monitor_index", monitor_index);
benchmark_options.addOption([]const u8, "monitor_name", monitor_name);
benchmark_options.addOption([]const u8, "window_video_driver", window_video_driver);
benchmark_options.addOption(bool, "window_no_focus", window_no_focus);
benchmark_options.addOption(bool, "skip_present", true);
benchmark_options.addOption([]const u8, "screenshot_path", "");
benchmark_options.addOption(u32, "screenshot_frame", 120);
benchmark_options.addOption(u32, "screenshot_delay_seconds", 0);
benchmark_options.addOption(bool, "shadow_test_scene", false);
benchmark_options.addOption([]const u8, "shadow_test_variant", "dug-cave");
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.addImport("fs", fs_module);
benchmark_root_module.addImport("sync", sync_module);
benchmark_root_module.addImport("c", c_module);
addProjectModuleImports(benchmark_root_module, engine_math, engine_audio, engine_core, engine_ecs, engine_input, engine_physics, engine_rhi, engine_graphics, engine_assets, engine_camera, engine_clouds, engine_atmosphere, engine_shadows, engine_lighting, engine_ui, world_core, world_worldgen, world_meshing, world_lod, world_runtime, world_persistence);
benchmark_root_module.addImport("game-core", game_core);
benchmark_root_module.addImport("game-ui", game_ui);
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.root_module.link_libc = true;
benchmark_exe.root_module.addCSourceFile(.{
.file = b.path("libs/stb/stb_image_impl.c"),
.flags = &.{"-std=c99"},
});
benchmark_exe.root_module.addCSourceFile(.{
.file = b.path("libs/stb/stb_truetype_impl.c"),
.flags = &.{"-std=c99"},
});
benchmark_exe.root_module.linkSystemLibrary("sdl3", .{});
benchmark_exe.root_module.linkSystemLibrary("vulkan", .{});
if (enable_imgui) addCimgui(b, benchmark_exe);
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 worldgen_report_root_module = b.createModule(.{
.root_source_file = b.path("src/worldgen_report_main.zig"),
.target = target,
.optimize = optimize,
});
worldgen_report_root_module.addImport("world-core", world_core);
worldgen_report_root_module.addImport("world-worldgen", world_worldgen);
const worldgen_report_exe = b.addExecutable(.{
.name = "worldgen-report",
.root_module = worldgen_report_root_module,
});
const worldgen_report_run_cmd = b.addRunArtifact(worldgen_report_exe);
const worldgen_report_step = b.step("worldgen-report", "Print deterministic worldgen baseline report");
worldgen_report_step.dependOn(&worldgen_report_run_cmd.step);
const worldgen_climate_snapshot_root_module = b.createModule(.{
.root_source_file = b.path("src/worldgen_climate_snapshot_main.zig"),
.target = target,
.optimize = optimize,
});
worldgen_climate_snapshot_root_module.addImport("fs", fs_module);
worldgen_climate_snapshot_root_module.addImport("world-core", world_core);
worldgen_climate_snapshot_root_module.addImport("world-worldgen", world_worldgen);
const worldgen_climate_snapshot_exe = b.addExecutable(.{
.name = "worldgen-climate-snapshot",
.root_module = worldgen_climate_snapshot_root_module,
});
const worldgen_climate_snapshot_run_cmd = b.addRunArtifact(worldgen_climate_snapshot_exe);
if (b.args) |args| {
worldgen_climate_snapshot_run_cmd.addArgs(args);
}
const worldgen_climate_snapshot_step = b.step("worldgen-climate-snapshot", "Write deterministic worldgen climate snapshot JSON or heatmap");
worldgen_climate_snapshot_step.dependOn(&worldgen_climate_snapshot_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.addImport("fs", fs_module);
test_root_module.addImport("sync", sync_module);
test_root_module.addImport("c", c_module);
addProjectModuleImports(test_root_module, engine_math, engine_audio, engine_core, engine_ecs, engine_input, engine_physics, engine_rhi, engine_graphics, engine_assets, engine_camera, engine_clouds, engine_atmosphere, engine_shadows, engine_lighting, engine_ui, world_core, world_worldgen, world_meshing, world_lod, world_runtime, world_persistence);
test_root_module.addImport("game-core", game_core);
test_root_module.addImport("game-ui", game_ui);
test_root_module.addOptions("build_options", options);
const test_filters: []const []const u8 = if (b.option([]const u8, "test-filter", "Only run unit tests whose name contains this filter")) |filter|
&.{filter}
else if (b.args) |args|
if (args.len >= 2 and std.mem.eql(u8, args[0], "--test-filter")) &.{args[1]} else &.{}
else
&.{};
const exe_tests = b.addTest(.{
.root_module = test_root_module,
.filters = test_filters,
});
exe_tests.root_module.link_libc = true;
exe_tests.root_module.addCSourceFile(.{
.file = b.path("libs/stb/stb_truetype_impl.c"),
.flags = &.{"-std=c99"},
});
exe_tests.root_module.linkSystemLibrary("sdl3", .{});
exe_tests.root_module.linkSystemLibrary("vulkan", .{});
exe_tests.root_module.addIncludePath(b.path("libs/stb"));
if (enable_imgui) addCimgui(b, exe_tests);
const test_step = b.step("test", "Run unit tests");
const run_exe_tests = b.addRunArtifact(exe_tests);
run_exe_tests.setEnvironmentVariable("ZIGCRAFT_LOG_LEVEL", "fatal");
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.addImport("fs", fs_module);
integration_root_module.addImport("sync", sync_module);
integration_root_module.addImport("c", c_module);
addProjectModuleImports(integration_root_module, engine_math, engine_audio, engine_core, engine_ecs, engine_input, engine_physics, engine_rhi, engine_graphics, engine_assets, engine_camera, engine_clouds, engine_atmosphere, engine_shadows, engine_lighting, engine_ui, world_core, world_worldgen, world_meshing, world_lod, world_runtime, world_persistence);
integration_root_module.addImport("game-core", game_core);
integration_root_module.addImport("game-ui", game_ui);
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.root_module.link_libc = true;
exe_integration_tests.root_module.addCSourceFile(.{
.file = b.path("libs/stb/stb_image_impl.c"),
.flags = &.{"-std=c99"},
});
exe_integration_tests.root_module.addCSourceFile(.{
.file = b.path("libs/stb/stb_truetype_impl.c"),
.flags = &.{"-std=c99"},
});
exe_integration_tests.root_module.linkSystemLibrary("sdl3", .{});
exe_integration_tests.root_module.linkSystemLibrary("vulkan", .{});
if (enable_imgui) addCimgui(b, exe_integration_tests);
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.root_module.addImport("fs", fs_module);
robust_demo.root_module.addImport("sync", sync_module);
robust_demo.root_module.addImport("c", c_module);
robust_demo.root_module.addImport("engine-core", engine_core);
robust_demo.root_module.addImport("engine-graphics", engine_graphics);
robust_demo.root_module.link_libc = true;
robust_demo.root_module.linkSystemLibrary("sdl3", .{});
robust_demo.root_module.linkSystemLibrary("vulkan", .{});
robust_demo.root_module.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.root_module.addImport("fs", fs_module);
integration_robustness.root_module.addImport("sync", sync_module);
integration_robustness.root_module.addImport("c", c_module);
integration_robustness.root_module.addImport("engine-core", engine_core);
integration_robustness.root_module.link_libc = true;
integration_robustness.root_module.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_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_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);
}
fn addCimgui(_: *std.Build, compile: *std.Build.Step.Compile) void {
compile.root_module.linkSystemLibrary("cimgui", .{ .use_pkg_config = .force });
compile.root_module.link_libcpp = true;
}
fn addSharedImports(module: *std.Build.Module, zig_math: *std.Build.Module, zig_noise: *std.Build.Module, fs_module: *std.Build.Module, sync_module: *std.Build.Module, c_module: *std.Build.Module, options: *std.Build.Step.Options) void {
addSharedImportsNoOptions(module, zig_math, zig_noise, fs_module, sync_module, c_module);
module.addOptions("build_options", options);
}
fn addSharedImportsNoOptions(module: *std.Build.Module, zig_math: *std.Build.Module, zig_noise: *std.Build.Module, fs_module: *std.Build.Module, sync_module: *std.Build.Module, c_module: *std.Build.Module) void {
module.addImport("zig-math", zig_math);
module.addImport("zig-noise", zig_noise);
module.addImport("fs", fs_module);
module.addImport("sync", sync_module);
module.addImport("c", c_module);
}
fn addProjectModuleImports(
module: *std.Build.Module,
engine_math: *std.Build.Module,
engine_audio: *std.Build.Module,
engine_core: *std.Build.Module,
engine_ecs: *std.Build.Module,
engine_input: *std.Build.Module,
engine_physics: *std.Build.Module,
engine_rhi: *std.Build.Module,
engine_graphics: *std.Build.Module,
engine_assets: *std.Build.Module,
engine_camera: *std.Build.Module,
engine_clouds: *std.Build.Module,
engine_atmosphere: *std.Build.Module,
engine_shadows: *std.Build.Module,
engine_lighting: *std.Build.Module,
engine_ui: *std.Build.Module,
world_core: *std.Build.Module,
world_worldgen: *std.Build.Module,
world_meshing: *std.Build.Module,
world_lod: *std.Build.Module,
world_runtime: *std.Build.Module,
world_persistence: *std.Build.Module,
) void {
module.addImport("engine-math", engine_math);
module.addImport("engine-audio", engine_audio);
module.addImport("engine-core", engine_core);
module.addImport("engine-ecs", engine_ecs);
module.addImport("engine-input", engine_input);
module.addImport("engine-physics", engine_physics);
module.addImport("engine-rhi", engine_rhi);
module.addImport("engine-graphics", engine_graphics);
module.addImport("engine-assets", engine_assets);
module.addImport("engine-camera", engine_camera);
module.addImport("engine-clouds", engine_clouds);
module.addImport("engine-atmosphere", engine_atmosphere);
module.addImport("engine-shadows", engine_shadows);
module.addImport("engine-lighting", engine_lighting);
module.addImport("engine-ui", engine_ui);
module.addImport("world-core", world_core);
module.addImport("world-worldgen", world_worldgen);
module.addImport("world-meshing", world_meshing);
module.addImport("world-lod", world_lod);
module.addImport("world-runtime", world_runtime);
module.addImport("world-persistence", world_persistence);
}