-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
1192 lines (1134 loc) · 52 KB
/
Copy pathbuild.zig
File metadata and controls
1192 lines (1134 loc) · 52 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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const std = @import("std");
const builtin = @import("builtin");
fn addCoreOptions(
b: *std.Build,
target: std.Build.ResolvedTarget,
test_mode: bool,
corpus_scan_spv_path: []const u8,
lattice_query_spv_path: []const u8,
) *std.Build.Step.Options {
const arch = target.result.cpu.arch;
const features = target.result.cpu.features;
const is_x86_64 = arch == .x86_64;
var core_options = b.addOptions();
core_options.addOption([]const u8, "ghost_version", "V32");
core_options.addOption([]const u8, "project_root", b.pathFromRoot("."));
core_options.addOption([]const u8, "platform_subdir", b.fmt(
"platforms/{s}/{s}",
.{ @tagName(target.result.os.tag), @tagName(arch) },
));
core_options.addOption(bool, "test_mode", test_mode);
core_options.addOption(bool, "use_avx2", is_x86_64 and std.Target.x86.featureSetHas(features, .avx2));
core_options.addOption(bool, "use_neon", arch == .aarch64 or arch == .arm);
core_options.addOption([]const u8, "corpus_scan_spv_path", corpus_scan_spv_path);
core_options.addOption([]const u8, "lattice_query_spv_path", lattice_query_spv_path);
const generated_shader_dir = b.pathFromRoot(".zig-cache/ghost_shaders");
core_options.addOption([]const u8, "gemma_rune_embed_spv_path", b.pathJoin(&.{ generated_shader_dir, "rune_embed.spv" }));
core_options.addOption([]const u8, "gemma_matmul_q4k_spv_path", b.pathJoin(&.{ generated_shader_dir, "matmul_q4k.spv" }));
core_options.addOption([]const u8, "gemma_matmul_q8_0_spv_path", b.pathJoin(&.{ generated_shader_dir, "matmul_q8_0.spv" }));
core_options.addOption([]const u8, "gemma_rms_norm_spv_path", b.pathJoin(&.{ generated_shader_dir, "rms_norm.spv" }));
core_options.addOption([]const u8, "gemma_swiglu_spv_path", b.pathJoin(&.{ generated_shader_dir, "swiglu.spv" }));
core_options.addOption([]const u8, "gemma_attention_spv_path", b.pathJoin(&.{ generated_shader_dir, "ghost_attention.spv" }));
core_options.addOption([]const u8, "gemma_rune_project_spv_path", b.pathJoin(&.{ generated_shader_dir, "rune_project.spv" }));
return core_options;
}
pub fn build(b: *std.Build) void {
// Linux/x86_64 is the primary Ghost target. The default build specializes
// for the local CPU; pass -Dtarget/-Dcpu to produce portable artifacts.
const target = b.standardTargetOptions(.{
.default_target = .{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .gnu,
.cpu_model = .native,
},
});
const optimize = b.standardOptimizeOption(.{});
const dev_native_backend = b.option(
bool,
"dev-native-backend",
"Opt into Zig native codegen for scalar Debug checks; full Ghost VSA builds need LLVM on Zig 0.14.1",
) orelse false;
const release_lto = b.option(
bool,
"release-lto",
"Enable LTO for ReleaseFast builds when LLVM is active",
) orelse true;
const strip_release = b.option(
bool,
"strip-release",
"Strip ReleaseFast artifacts",
) orelse (optimize == .ReleaseFast);
const omit_release_frame_pointer = b.option(
bool,
"omit-release-frame-pointer",
"Omit frame pointers for ReleaseFast artifacts",
) orelse (optimize == .ReleaseFast);
const use_llvm: ?bool = if (dev_native_backend) false else null;
const use_lto = optimize == .ReleaseFast and release_lto and use_llvm != false;
const release_strip: ?bool = if (strip_release) true else null;
const release_omit_frame_pointer: ?bool = if (omit_release_frame_pointer) true else null;
const test_filter = b.option([]const u8, "test-filter", "Run only tests whose name contains this text");
const test_filters: []const []const u8 = if (test_filter) |filter| &.{filter} else &.{};
const generated_shader_dir = b.pathFromRoot(".zig-cache/ghost_shaders");
const corpus_scan_spv_path = b.pathJoin(&.{ generated_shader_dir, "corpus_scan.spv" });
const mkdir_generated_shaders = b.addSystemCommand(&.{ "mkdir", "-p", generated_shader_dir });
const compile_corpus_scan_shader = b.addSystemCommand(&.{
"glslc",
b.pathFromRoot("src/shaders/corpus_scan.comp"),
"-o",
corpus_scan_spv_path,
});
compile_corpus_scan_shader.step.dependOn(&mkdir_generated_shaders.step);
const phase2_search_spv_path = b.pathJoin(&.{ generated_shader_dir, "phase2_search.spv" });
const compile_phase2_search_shader = b.addSystemCommand(&.{
"glslc",
b.pathFromRoot("src/gpu/search.comp"),
"-o",
phase2_search_spv_path,
});
compile_phase2_search_shader.step.dependOn(&mkdir_generated_shaders.step);
compile_corpus_scan_shader.step.dependOn(&compile_phase2_search_shader.step);
const gemma_shader_names = [_][]const u8{
"rune_embed",
"matmul_q4k",
"matmul_q8_0",
"rms_norm",
"swiglu",
"ghost_attention",
"rune_project",
};
for (gemma_shader_names) |name| {
const compile_gemma_shader = b.addSystemCommand(&.{
"glslc",
b.pathFromRoot(b.fmt("src/shaders/{s}.comp", .{name})),
"-o",
b.pathJoin(&.{ generated_shader_dir, b.fmt("{s}.spv", .{name}) }),
});
compile_gemma_shader.step.dependOn(&mkdir_generated_shaders.step);
compile_corpus_scan_shader.step.dependOn(&compile_gemma_shader.step);
}
const native_gip_parser_check = b.addSystemCommand(&.{
b.graph.zig_exe,
"test",
b.pathFromRoot("src/compiler/gip_parser.zig"),
"-fno-llvm",
"-fno-emit-bin",
"--cache-dir",
b.pathFromRoot(".zig-cache"),
});
const native_gip_parser_step = b.step(
"check-native-gip-parser",
"Compile-check the scalar GIP parser with Zig native codegen and no emitted binary",
);
native_gip_parser_step.dependOn(&native_gip_parser_check.step);
const core_options = addCoreOptions(b, target, false, corpus_scan_spv_path, phase2_search_spv_path);
// ── 1. External Dependencies (Vulkan headers only) ──
// NOTE: We do NOT link against vulkan-1.dll at build time.
// The DLL is loaded dynamically at runtime via LoadLibraryA.
// If the DLL is missing (no GPU driver), the engine falls back to CPU mode.
const vulkan_sdk = b.graph.env_map.get("VULKAN_SDK");
// ── 2. Sovereign Core Module ──
const ghost_core = b.createModule(.{
.root_source_file = b.path("src/ghost.zig"),
});
ghost_core.addOptions("build_options", core_options);
if (target.result.os.tag == .windows) {
if (vulkan_sdk) |sdk| {
ghost_core.addIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "Include" }) });
}
} else if (target.result.os.tag == .linux) {
ghost_core.addSystemIncludePath(.{ .cwd_relative = "/usr/include" });
ghost_core.addSystemIncludePath(.{ .cwd_relative = "/usr/include/x86_64-linux-gnu" });
}
const domain_inference_module = b.createModule(.{
.root_source_file = b.path("src/domain/inference.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
});
const anchor_discovery_module = b.createModule(.{
.root_source_file = b.path("src/analysis/anchors.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
});
anchor_discovery_module.addImport("domain_inference", domain_inference_module);
const semantic_tensor_module = b.createModule(.{
.root_source_file = b.path("src/semantics/tensor.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
});
semantic_tensor_module.addImport("domain_inference", domain_inference_module);
const z3_bridge_module = b.createModule(.{
.root_source_file = b.path("src/verification/z3_bridge.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
});
if (target.result.os.tag == .linux) {
z3_bridge_module.addSystemIncludePath(.{ .cwd_relative = "/usr/include" });
z3_bridge_module.addSystemIncludePath(.{ .cwd_relative = "/usr/include/x86_64-linux-gnu" });
z3_bridge_module.addLibraryPath(.{ .cwd_relative = "/usr/lib/x86_64-linux-gnu" });
}
const proof_session_module = b.createModule(.{
.root_source_file = b.path("src/core/proof_session.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
});
ghost_core.addImport("proof_session", proof_session_module);
ghost_core.addImport("z3_bridge", z3_bridge_module);
z3_bridge_module.addImport("anchor_discovery", anchor_discovery_module);
z3_bridge_module.addImport("semantic_tensor", semantic_tensor_module);
z3_bridge_module.addImport("proof_session", proof_session_module);
// Helper: add Vulkan include path to any module that imports ghost_core
// (needed because @cImport in vulkan_loader.zig resolves headers at the root_module level)
const addVulkanIncludes = struct {
fn add(mod: *std.Build.Module, os: std.Target.Os, sdk_opt: ?[]const u8, builder: *std.Build) void {
if (os.tag == .windows) {
if (sdk_opt) |sdk| {
mod.addIncludePath(.{ .cwd_relative = builder.pathJoin(&.{ sdk, "Include" }) });
}
} else if (os.tag == .linux) {
mod.addSystemIncludePath(.{ .cwd_relative = "/usr/include" });
mod.addSystemIncludePath(.{ .cwd_relative = "/usr/include/x86_64-linux-gnu" });
mod.addLibraryPath(.{ .cwd_relative = "/usr/lib/x86_64-linux-gnu" });
}
}
}.add;
const addGhostExecutable = struct {
fn add(
builder: *std.Build,
exe_name: []const u8,
root: []const u8,
exe_target: std.Build.ResolvedTarget,
exe_optimize: std.builtin.OptimizeMode,
core_module: *std.Build.Module,
options: *std.Build.Step.Options,
os: std.Target.Os,
sdk_opt: ?[]const u8,
exe_use_llvm: ?bool,
exe_use_lto: bool,
exe_strip: ?bool,
exe_omit_frame_pointer: ?bool,
add_vulkan_includes: *const fn (*std.Build.Module, std.Target.Os, ?[]const u8, *std.Build) void,
shader_step: *std.Build.Step.Run,
) *std.Build.Step.Compile {
const exe = builder.addExecutable(.{
.name = exe_name,
.use_llvm = exe_use_llvm,
.root_module = builder.createModule(.{
.root_source_file = builder.path(root),
.target = exe_target,
.optimize = exe_optimize,
.code_model = .small,
.strip = exe_strip,
.omit_frame_pointer = exe_omit_frame_pointer,
}),
});
exe.want_lto = exe_use_lto;
exe.root_module.addImport("ghost_core", core_module);
exe.root_module.addOptions("build_options", options);
exe.root_module.linkSystemLibrary("c", .{});
if (os.tag == .linux) {
exe.root_module.linkSystemLibrary("dl", .{});
}
add_vulkan_includes(exe.root_module, os, sdk_opt, builder);
if (std.mem.eql(u8, exe_name, "ghost_sovereign") and os.tag == .windows) {
exe.root_module.linkSystemLibrary("ws2_32", .{});
}
exe.step.dependOn(&shader_step.step);
return exe;
}
}.add;
const phase2_hypervector_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/vsa/hypervector.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
phase2_hypervector_tests.want_lto = use_lto;
const run_phase2_hypervector_tests = b.addRunArtifact(phase2_hypervector_tests);
const phase2_vulkan_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/gpu/vulkan_init.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
phase2_vulkan_tests.want_lto = use_lto;
phase2_vulkan_tests.step.dependOn(&compile_phase2_search_shader.step);
phase2_vulkan_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
phase2_vulkan_tests.root_module.linkSystemLibrary("dl", .{});
}
addVulkanIncludes(phase2_vulkan_tests.root_module, target.result.os, vulkan_sdk, b);
const run_phase2_vulkan_tests = b.addRunArtifact(phase2_vulkan_tests);
const phase2_oracle_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/oracle/compiler_loop.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
phase2_oracle_tests.want_lto = use_lto;
const run_phase2_oracle_tests = b.addRunArtifact(phase2_oracle_tests);
const swe_harness_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/test_swe_harness.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
swe_harness_tests.want_lto = use_lto;
const run_swe_harness_tests = b.addRunArtifact(swe_harness_tests);
const phase3_ipc_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/ipc/protocol.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
phase3_ipc_tests.want_lto = use_lto;
const run_phase3_ipc_tests = b.addRunArtifact(phase3_ipc_tests);
const phase3_wingman_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/zenith/wingman.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
phase3_wingman_tests.want_lto = use_lto;
const run_phase3_wingman_tests = b.addRunArtifact(phase3_wingman_tests);
const zenith_bridge_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/zenith/bridge.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
zenith_bridge_tests.want_lto = use_lto;
const run_zenith_bridge_tests = b.addRunArtifact(zenith_bridge_tests);
const lattice_view_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/ui/lattice_view.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
lattice_view_tests.root_module.addImport("ghost_core", ghost_core);
lattice_view_tests.want_lto = use_lto;
const run_lattice_view_tests = b.addRunArtifact(lattice_view_tests);
const phase4_auto_fix_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/oracle/auto_fix.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
phase4_auto_fix_tests.want_lto = use_lto;
const run_phase4_auto_fix_tests = b.addRunArtifact(phase4_auto_fix_tests);
const phase4_curiosity_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/ghost/curiosity.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
phase4_curiosity_tests.want_lto = use_lto;
const run_phase4_curiosity_tests = b.addRunArtifact(phase4_curiosity_tests);
const phase5_hive_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/net/hive.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
phase5_hive_tests.want_lto = use_lto;
const run_phase5_hive_tests = b.addRunArtifact(phase5_hive_tests);
const phase6_recursive_boot_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/ghost/recursive_boot.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
phase6_recursive_boot_tests.want_lto = use_lto;
const run_phase6_recursive_boot_tests = b.addRunArtifact(phase6_recursive_boot_tests);
const phase2_step = b.step("test-phase2-core", "Run Phase 2 VSA, Vulkan stage-gate, and Reality Oracle tests");
phase2_step.dependOn(&run_phase2_hypervector_tests.step);
phase2_step.dependOn(&run_phase2_vulkan_tests.step);
phase2_step.dependOn(&run_phase2_oracle_tests.step);
const swe_harness_step = b.step("test-swe-harness", "Run native SWE provisioning harness tests");
swe_harness_step.dependOn(&run_swe_harness_tests.step);
const phase3_step = b.step("test-phase3-integration", "Run Phase 3 IPC and Wingman integration tests");
phase3_step.dependOn(&run_phase3_ipc_tests.step);
phase3_step.dependOn(&run_phase3_wingman_tests.step);
phase3_step.dependOn(&run_zenith_bridge_tests.step);
phase3_step.dependOn(&run_lattice_view_tests.step);
const phase456_step = b.step("test-phase456", "Run explicit Phase 4/5/6 oracle, curiosity, hive, and recursive boot tests");
phase456_step.dependOn(&run_phase4_auto_fix_tests.step);
phase456_step.dependOn(&run_phase4_curiosity_tests.step);
phase456_step.dependOn(&run_phase5_hive_tests.step);
phase456_step.dependOn(&run_phase6_recursive_boot_tests.step);
// ── 3. Shader SPIR-V ──
const shader_names = [_][]const u8{
"resonance_query",
"genesis_etch",
"thermal_prune",
"recursive_lookahead",
"lattice_etch",
"candidate_score",
"neighborhood_score",
"contradiction_filter",
"semantic_hash",
"rune_search",
};
for (shader_names) |name| {
const spv_path = b.pathJoin(&.{ "src", "shaders", b.fmt("{s}.spv", .{name}) });
_ = b.path(spv_path);
}
// Helper: configure an executable with ghost_core (no Vulkan link-time dependency)
const ExeConfig = struct {
name: []const u8,
root: []const u8,
};
const monolith = addGhostExecutable(
b,
"ghost_sovereign",
"src/main.zig",
target,
optimize,
ghost_core,
core_options,
target.result.os,
vulkan_sdk,
use_llvm,
use_lto,
release_strip,
release_omit_frame_pointer,
addVulkanIncludes,
compile_corpus_scan_shader,
);
monolith.root_module.addImport("domain_inference", domain_inference_module);
monolith.root_module.addImport("anchor_discovery", anchor_discovery_module);
monolith.root_module.addImport("semantic_tensor", semantic_tensor_module);
monolith.root_module.addImport("z3_bridge", z3_bridge_module);
monolith.root_module.linkSystemLibrary("z3", .{});
b.installArtifact(monolith);
const exes = [_]ExeConfig{
.{ .name = "ohl_trainer", .root = "src/trainer.zig" },
.{ .name = "probe_inference", .root = "src/probe_inference.zig" },
.{ .name = "sigil_core", .root = "src/sigil_core.zig" },
.{ .name = "ghost_code_intel", .root = "src/code_intel_cli.zig" },
.{ .name = "ghost_corpus_ingest", .root = "src/corpus_ingest_cli.zig" },
.{ .name = "ghost_invent", .root = "src/invent_cli.zig" },
.{ .name = "ghost_medic_ingest", .root = "src/medic_ingest_cli.zig" },
.{ .name = "ghost_medic_solve", .root = "src/medic_solve_cli.zig" },
.{ .name = "ghost_patch_candidates", .root = "src/patch_candidates_cli.zig" },
.{ .name = "ghost_panic_dump", .root = "src/panic_dump_cli.zig" },
.{ .name = "ghost_task_intent", .root = "src/task_intent_cli.zig" },
.{ .name = "ghost_task_operator", .root = "src/task_operator_cli.zig" },
.{ .name = "ghost_intent_grounding", .root = "src/intent_grounding_cli.zig" },
.{ .name = "ghost_knowledge_pack", .root = "src/knowledge_packs.zig" },
.{ .name = "ghost_gip", .root = "src/gip_cli.zig" },
.{ .name = "ghost_gemma", .root = "src/gemma_cli.zig" },
.{ .name = "ghost_swe_harness", .root = "src/swe_harness_cli.zig" },
.{ .name = "sigil", .root = "src/ui/sigil.zig" },
.{ .name = "lattice_view", .root = "src/ui/lattice_view.zig" },
.{ .name = "ghostd", .root = "src/daemon.zig" },
.{ .name = "ghost_project_autopsy", .root = "src/project_autopsy_cli.zig" },
.{ .name = "ghost_forge", .root = "src/forge_cli.zig" },
.{ .name = "ghost_semantic_test", .root = "src/semantic_test_cli.zig" },
};
for (exes) |cfg| {
const exe = addGhostExecutable(
b,
cfg.name,
cfg.root,
target,
optimize,
ghost_core,
core_options,
target.result.os,
vulkan_sdk,
use_llvm,
use_lto,
release_strip,
release_omit_frame_pointer,
addVulkanIncludes,
compile_corpus_scan_shader,
);
if (std.mem.eql(u8, cfg.name, "ghostd") or std.mem.eql(u8, cfg.name, "ghost_gip") or std.mem.eql(u8, cfg.name, "ghost_invent") or std.mem.eql(u8, cfg.name, "ghost_gemma")) {
exe.root_module.addImport("domain_inference", domain_inference_module);
exe.root_module.addImport("anchor_discovery", anchor_discovery_module);
exe.root_module.addImport("semantic_tensor", semantic_tensor_module);
exe.root_module.addImport("z3_bridge", z3_bridge_module);
exe.root_module.linkSystemLibrary("z3", .{});
}
const install_exe = b.addInstallArtifact(exe, .{});
b.getInstallStep().dependOn(&install_exe.step);
if (std.mem.eql(u8, cfg.name, "ghost_gemma")) {
const gemma_weights_cli_step = b.step("ghost-gemma-weights", "Build the explicit Ghost Gemma GGUF weight inventory CLI");
gemma_weights_cli_step.dependOn(&install_exe.step);
}
}
const zenith_bridge_lib = b.addLibrary(.{
.name = "zenith_wingman_bridge",
.linkage = .dynamic,
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/zenith/bridge.zig"),
.target = target,
.optimize = .ReleaseFast,
.code_model = .small,
.strip = true,
.omit_frame_pointer = true,
}),
});
zenith_bridge_lib.want_lto = use_llvm != false;
b.installArtifact(zenith_bridge_lib);
// ── 8. Run Step ──
const run_cmd = b.addRunArtifact(monolith);
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const bench_exe = addGhostExecutable(
b,
"ghost_bench_serious_workflows",
"src/bench_serious_workflows.zig",
target,
optimize,
ghost_core,
core_options,
target.result.os,
vulkan_sdk,
use_llvm,
use_lto,
release_strip,
release_omit_frame_pointer,
addVulkanIncludes,
compile_corpus_scan_shader,
);
const compute_bench_exe = addGhostExecutable(
b,
"ghost_bench_compute_dominance",
"src/bench_compute_dominance.zig",
target,
optimize,
ghost_core,
core_options,
target.result.os,
vulkan_sdk,
use_llvm,
use_lto,
release_strip,
release_omit_frame_pointer,
addVulkanIncludes,
compile_corpus_scan_shader,
);
const run_compute_bench = b.addRunArtifact(compute_bench_exe);
run_compute_bench.step.dependOn(b.getInstallStep());
const compute_bench_step = b.step("bench-compute-dominance", "Run local compute dominance benchmark scenarios");
compute_bench_step.dependOn(&run_compute_bench.step);
const run_bench = b.addRunArtifact(bench_exe);
run_bench.step.dependOn(b.getInstallStep());
const bench_step = b.step("bench-serious-workflows", "Run the serious workflow benchmark suite");
bench_step.dependOn(&run_compute_bench.step);
bench_step.dependOn(&run_bench.step);
const hygiene_cmd = b.addSystemCommand(&.{
"git",
"status",
"--short",
"--untracked-files=all",
});
hygiene_cmd.has_side_effects = true;
const hygiene_step = b.step("repo-hygiene", "Print repository status after ignoring generated Ghost state");
hygiene_step.dependOn(&hygiene_cmd.step);
const artifact_autopsy_smoke_cmd = b.addSystemCommand(&.{
"bash",
"tools/smoke_artifact_autopsy.sh",
});
artifact_autopsy_smoke_cmd.setCwd(b.path("."));
artifact_autopsy_smoke_cmd.has_side_effects = true;
artifact_autopsy_smoke_cmd.step.dependOn(b.getInstallStep());
const artifact_autopsy_smoke_step = b.step("smoke-artifact-autopsy", "Run artifact autopsy smoke fixtures");
artifact_autopsy_smoke_step.dependOn(&artifact_autopsy_smoke_cmd.step);
const gemma_weights_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/gemma/weights.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
gemma_weights_tests.want_lto = use_lto;
gemma_weights_tests.root_module.addOptions("build_options", core_options);
gemma_weights_tests.root_module.linkSystemLibrary("c", .{});
const run_gemma_weights_tests = b.addRunArtifact(gemma_weights_tests);
const gemma_weights_step = b.step("test-gemma-weights", "Run GGUF parser and Gemma weight inventory tests");
gemma_weights_step.dependOn(&run_gemma_weights_tests.step);
const gemma_inference_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/gemma_native_tests.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
gemma_inference_tests.want_lto = use_lto;
gemma_inference_tests.root_module.addOptions("build_options", core_options);
gemma_inference_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
gemma_inference_tests.root_module.linkSystemLibrary("dl", .{});
gemma_inference_tests.root_module.linkSystemLibrary("vulkan", .{});
}
addVulkanIncludes(gemma_inference_tests.root_module, target.result.os, vulkan_sdk, b);
const run_gemma_inference_tests = b.addRunArtifact(gemma_inference_tests);
const gemma_agent_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/gemma_native_tests.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
gemma_agent_tests.want_lto = use_lto;
gemma_agent_tests.root_module.addOptions("build_options", core_options);
gemma_agent_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
gemma_agent_tests.root_module.linkSystemLibrary("dl", .{});
gemma_agent_tests.root_module.linkSystemLibrary("vulkan", .{});
}
addVulkanIncludes(gemma_agent_tests.root_module, target.result.os, vulkan_sdk, b);
const run_gemma_agent_tests = b.addRunArtifact(gemma_agent_tests);
// Add the agents test back to the native step
const gemma_native_step = b.step("test-gemma-native", "Run Ghost-native Gemma rune, attention, inference, and agent-router tests");
gemma_native_step.dependOn(&run_gemma_inference_tests.step);
gemma_native_step.dependOn(&run_gemma_agent_tests.step);
const text_generation_lab_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/text_generation_lab.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
text_generation_lab_tests.want_lto = use_lto;
text_generation_lab_tests.step.dependOn(&compile_corpus_scan_shader.step);
const text_generation_lab_options = addCoreOptions(b, target, true, corpus_scan_spv_path, phase2_search_spv_path);
text_generation_lab_tests.root_module.addOptions("build_options", text_generation_lab_options);
text_generation_lab_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
text_generation_lab_tests.root_module.linkSystemLibrary("dl", .{});
text_generation_lab_tests.root_module.linkSystemLibrary("vulkan", .{});
}
addVulkanIncludes(text_generation_lab_tests.root_module, target.result.os, vulkan_sdk, b);
const run_text_generation_lab_tests = b.addRunArtifact(text_generation_lab_tests);
const text_generation_lab_smoke_step = b.step("smoke-text-generation-lab", "Run experimental text generation lab tests and fixture corpus smoke");
text_generation_lab_smoke_step.dependOn(&run_text_generation_lab_tests.step);
// ── 9. Unit & Integration Tests ──
const main_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/tests/test_routing.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
main_tests.want_lto = use_lto;
main_tests.step.dependOn(&compile_corpus_scan_shader.step);
const test_core_options = addCoreOptions(b, target, true, corpus_scan_spv_path, phase2_search_spv_path);
swe_harness_tests.root_module.addOptions("build_options", test_core_options);
swe_harness_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
swe_harness_tests.root_module.linkSystemLibrary("dl", .{});
swe_harness_tests.root_module.linkSystemLibrary("vulkan", .{});
}
addVulkanIncludes(swe_harness_tests.root_module, target.result.os, vulkan_sdk, b);
const ghost_core_test = b.createModule(.{
.root_source_file = b.path("src/ghost.zig"),
});
ghost_core_test.addImport("proof_session", proof_session_module);
ghost_core_test.addOptions("build_options", test_core_options);
if (target.result.os.tag == .windows) {
if (vulkan_sdk) |sdk| {
ghost_core_test.addIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "Include" }) });
}
} else if (target.result.os.tag == .linux) {
ghost_core_test.addSystemIncludePath(.{ .cwd_relative = "/usr/include" });
ghost_core_test.addSystemIncludePath(.{ .cwd_relative = "/usr/include/x86_64-linux-gnu" });
}
main_tests.root_module.addOptions("build_options", test_core_options);
main_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
main_tests.root_module.linkSystemLibrary("dl", .{});
main_tests.root_module.linkSystemLibrary("vulkan", .{});
}
addVulkanIncludes(main_tests.root_module, target.result.os, vulkan_sdk, b);
const run_main_tests = b.addRunArtifact(main_tests);
const test_smoke_step = b.step("test-smoke", "Run src/test_smoke.zig tests");
test_smoke_step.dependOn(&run_main_tests.step);
const test_step = b.step("test", "Run all tests");
test_step.dependOn(phase2_step);
test_step.dependOn(phase3_step);
test_step.dependOn(phase456_step);
test_step.dependOn(swe_harness_step);
test_step.dependOn(gemma_native_step);
run_text_generation_lab_tests.step.dependOn(&run_main_tests.step);
const lifecycle_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/test_verifier_lifecycle.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
lifecycle_tests.want_lto = use_lto;
lifecycle_tests.step.dependOn(&compile_corpus_scan_shader.step);
lifecycle_tests.root_module.addOptions("build_options", test_core_options);
lifecycle_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
lifecycle_tests.root_module.linkSystemLibrary("dl", .{});
lifecycle_tests.root_module.linkSystemLibrary("vulkan", .{});
}
addVulkanIncludes(lifecycle_tests.root_module, target.result.os, vulkan_sdk, b);
const run_lifecycle_tests = b.addRunArtifact(lifecycle_tests);
run_lifecycle_tests.step.dependOn(&run_text_generation_lab_tests.step);
const test_lifecycle_step = b.step("test-lifecycle", "Run src/test_verifier_lifecycle.zig tests");
test_lifecycle_step.dependOn(&run_lifecycle_tests.step);
const gip_cli_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/gip_cli.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
gip_cli_tests.want_lto = use_lto;
gip_cli_tests.step.dependOn(&compile_corpus_scan_shader.step);
gip_cli_tests.root_module.addImport("ghost_core", ghost_core_test);
gip_cli_tests.root_module.addOptions("build_options", test_core_options);
gip_cli_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
gip_cli_tests.root_module.linkSystemLibrary("dl", .{});
gip_cli_tests.root_module.linkSystemLibrary("vulkan", .{});
}
addVulkanIncludes(gip_cli_tests.root_module, target.result.os, vulkan_sdk, b);
const run_gip_cli_tests = b.addRunArtifact(gip_cli_tests);
run_gip_cli_tests.step.dependOn(&run_lifecycle_tests.step);
const test_gip_cli_step = b.step("test-gip-cli", "Run src/gip_cli.zig tests");
test_gip_cli_step.dependOn(&run_gip_cli_tests.step);
const knowledge_pack_cli_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/knowledge_packs.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
knowledge_pack_cli_tests.want_lto = use_lto;
knowledge_pack_cli_tests.step.dependOn(&compile_corpus_scan_shader.step);
knowledge_pack_cli_tests.root_module.addOptions("build_options", test_core_options);
knowledge_pack_cli_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
knowledge_pack_cli_tests.root_module.linkSystemLibrary("dl", .{});
knowledge_pack_cli_tests.root_module.linkSystemLibrary("vulkan", .{});
}
addVulkanIncludes(knowledge_pack_cli_tests.root_module, target.result.os, vulkan_sdk, b);
const run_knowledge_pack_cli_tests = b.addRunArtifact(knowledge_pack_cli_tests);
run_knowledge_pack_cli_tests.step.dependOn(&run_gip_cli_tests.step);
const test_knowledge_packs_step = b.step("test-knowledge-packs", "Run src/knowledge_packs.zig tests");
test_knowledge_packs_step.dependOn(&run_knowledge_pack_cli_tests.step);
const project_autopsy_cli_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/project_autopsy_cli.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
project_autopsy_cli_tests.want_lto = use_lto;
project_autopsy_cli_tests.step.dependOn(&compile_corpus_scan_shader.step);
project_autopsy_cli_tests.root_module.addImport("ghost_core", ghost_core_test);
project_autopsy_cli_tests.root_module.addOptions("build_options", test_core_options);
project_autopsy_cli_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
project_autopsy_cli_tests.root_module.linkSystemLibrary("dl", .{});
project_autopsy_cli_tests.root_module.linkSystemLibrary("vulkan", .{});
}
addVulkanIncludes(project_autopsy_cli_tests.root_module, target.result.os, vulkan_sdk, b);
const run_project_autopsy_cli_tests = b.addRunArtifact(project_autopsy_cli_tests);
run_project_autopsy_cli_tests.step.dependOn(&run_knowledge_pack_cli_tests.step);
const test_project_autopsy_step = b.step("test-project-autopsy-cli", "Run src/project_autopsy_cli.zig tests");
test_project_autopsy_step.dependOn(&run_project_autopsy_cli_tests.step);
const compute_dominance_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/bench_compute_dominance.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
compute_dominance_tests.want_lto = use_lto;
compute_dominance_tests.step.dependOn(&compile_corpus_scan_shader.step);
compute_dominance_tests.root_module.addImport("ghost_core", ghost_core_test);
compute_dominance_tests.root_module.addOptions("build_options", test_core_options);
compute_dominance_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
compute_dominance_tests.root_module.linkSystemLibrary("dl", .{});
compute_dominance_tests.root_module.linkSystemLibrary("vulkan", .{});
}
addVulkanIncludes(compute_dominance_tests.root_module, target.result.os, vulkan_sdk, b);
const run_compute_dominance_tests = b.addRunArtifact(compute_dominance_tests);
run_compute_dominance_tests.step.dependOn(&run_project_autopsy_cli_tests.step);
const test_compute_dominance_step = b.step("test-compute-dominance", "Run src/bench_compute_dominance.zig tests");
test_compute_dominance_step.dependOn(&run_compute_dominance_tests.step);
const crucible_tests = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/tests/the_crucible.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.filters = test_filters,
});
crucible_tests.want_lto = use_lto;
crucible_tests.step.dependOn(&compile_corpus_scan_shader.step);
crucible_tests.root_module.addImport("ghost_core", ghost_core_test);
crucible_tests.root_module.addOptions("build_options", test_core_options);
crucible_tests.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
crucible_tests.root_module.linkSystemLibrary("dl", .{});
crucible_tests.root_module.linkSystemLibrary("vulkan", .{});
}
addVulkanIncludes(crucible_tests.root_module, target.result.os, vulkan_sdk, b);
const run_crucible_tests = b.addRunArtifact(crucible_tests);
const test_crucible_step = b.step("test-crucible", "Run the adversarial Technical Axiom Matrix crucible");
test_crucible_step.dependOn(&run_crucible_tests.step);
// test_step.dependOn(&run_compute_dominance_tests.step);
test_step.dependOn(&run_crucible_tests.step);
// ── 10. Parity Test ──
const parity_test = b.addTest(.{
.use_llvm = use_llvm,
.root_module = b.createModule(.{
.root_source_file = b.path("src/test_parity.zig"),
.target = target,
.optimize = optimize,
.code_model = .small,
.strip = release_strip,
.omit_frame_pointer = release_omit_frame_pointer,
}),
.test_runner = .{
.path = b.path("src/parity_test_runner.zig"),
.mode = .simple,
},
});
parity_test.want_lto = use_lto;
parity_test.step.dependOn(&compile_corpus_scan_shader.step);
parity_test.root_module.addImport("ghost_core", ghost_core);
parity_test.root_module.addOptions("build_options", core_options);
parity_test.root_module.linkSystemLibrary("c", .{});
if (target.result.os.tag == .linux) {
parity_test.root_module.addLibraryPath(.{ .cwd_relative = "/lib/x86_64-linux-gnu" });
parity_test.root_module.addLibraryPath(.{ .cwd_relative = "/usr/lib/x86_64-linux-gnu" });