-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.zig
More file actions
1789 lines (1602 loc) · 71.7 KB
/
build.zig
File metadata and controls
1789 lines (1602 loc) · 71.7 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");
// Ananke Build System
// Supports multiple targets including native binaries and WASM
pub fn build(b: *std.Build) void {
// Target options with WASM support
const target = b.standardTargetOptions(.{
.default_target = .{
.cpu_arch = null,
.os_tag = null,
.abi = null,
},
});
// Optimization options
const optimize = b.standardOptimizeOption(.{});
// Build options for mechanical sympathy optimizations
// Note: LTO is disabled for tree-sitter parser libraries to prevent symbol stripping
const cpu_native = b.option(bool, "cpu-native", "Enable native CPU features (-march=native)") orelse false;
// v0.2.0: Apply strip_symbols to executables (requires updating exe configuration)
// const strip_symbols = b.option(bool, "strip", "Strip debug symbols from release builds") orelse (optimize == .ReleaseSmall);
// Build option to enable WASM-specific features
const wasm_build = b.option(bool, "wasm", "Build for WebAssembly target") orelse false;
// Build option to enable Claude API integration
// const enable_claude = b.option(bool, "claude", "Enable Claude API integration") orelse true;
// It's also possible to define more custom flags to toggle optional features
// of this build script using `b.option()`. All defined flags (including
// target and optimize options) will be listed when running `zig build --help`
// in this directory.
// Helper function to generate C compiler flags based on optimization level
// Enables aggressive optimizations for release builds with LTO and CPU-specific features
const getCFlags = struct {
fn get(opt: std.builtin.OptimizeMode, lto: bool, native: bool) []const []const u8 {
return switch (opt) {
.Debug => &.{ "-std=c11", "-O0", "-g", "-fno-sanitize=undefined" },
.ReleaseSafe => if (lto)
&.{ "-std=c11", "-O2", "-flto", "-fno-omit-frame-pointer", "-fno-sanitize=undefined" }
else
&.{ "-std=c11", "-O2", "-fno-omit-frame-pointer", "-fno-sanitize=undefined" },
.ReleaseFast => if (lto and native)
&.{ "-std=c11", "-O3", "-flto", "-march=native", "-mtune=native", "-fno-sanitize=undefined" }
else if (lto)
&.{ "-std=c11", "-O3", "-flto", "-fno-sanitize=undefined" }
else if (native)
&.{ "-std=c11", "-O3", "-march=native", "-mtune=native", "-fno-sanitize=undefined" }
else
&.{ "-std=c11", "-O3", "-fno-sanitize=undefined" },
.ReleaseSmall => if (lto)
&.{ "-std=c11", "-Os", "-flto", "-fno-sanitize=undefined" }
else
&.{ "-std=c11", "-Os", "-fno-sanitize=undefined" },
};
}
}.get;
// Tree-sitter support via direct C FFI
// Note: Requires tree-sitter libraries to be installed via:
// macOS: brew install tree-sitter
// Linux: apt-get install libtree-sitter-dev or similar
//
// The tree-sitter C library provides the core API for parsing and AST traversal.
// or /usr/local on Linux. For portability across systems, you may need to adjust
// these paths or use pkg-config to detect the correct location.
// Tree-sitter module for direct C FFI bindings
// CRITICAL: This module must be configured with C include paths and system library linkage
// so that @cImport in c_api.zig can find tree_sitter/api.h
const tree_sitter_mod = b.addModule("tree_sitter", .{
.root_source_file = b.path("src/clew/tree_sitter.zig"),
.target = target,
.link_libc = true,
});
// Configure tree-sitter system library and include paths
// This ensures tree_sitter/api.h can be found by @cImport in c_api.zig
tree_sitter_mod.linkSystemLibrary("tree-sitter", .{});
// On Linux, explicitly add /usr/local/include for tree-sitter headers
// This is where our source-built tree-sitter installs headers
if (target.result.os.tag == .linux) {
tree_sitter_mod.addSystemIncludePath(.{ .cwd_relative = "/usr/local/include" });
}
// Tree-sitter language parsers as static libraries
// IMPORTANT: Disable LTO for parser libraries to prevent symbol stripping
// TypeScript parser
const ts_parser_lib = b.addLibrary(.{
.name = "tree-sitter-typescript",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
ts_parser_lib.addIncludePath(b.path("vendor/tree-sitter-typescript/typescript/src"));
// The common scanner needs to find tree_sitter/parser.h from the tsx source dir
ts_parser_lib.addIncludePath(b.path("vendor/tree-sitter-typescript/tsx/src"));
ts_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-typescript/typescript/src"),
.files = &.{ "parser.c", "scanner.c" },
.flags = getCFlags(optimize, false, cpu_native), // Disable LTO for parsers
});
// Python parser
const py_parser_lib = b.addLibrary(.{
.name = "tree-sitter-python",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
py_parser_lib.addIncludePath(b.path("vendor/tree-sitter-python/src"));
py_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-python/src"),
.files = &.{ "parser.c", "scanner.c" },
.flags = getCFlags(optimize, false, cpu_native), // Disable LTO for parsers
});
// JavaScript parser
const js_parser_lib = b.addLibrary(.{
.name = "tree-sitter-javascript",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
js_parser_lib.addIncludePath(b.path("vendor/tree-sitter-javascript/src"));
js_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-javascript/src"),
.files = &.{ "parser.c", "scanner.c" },
.flags = getCFlags(optimize, false, cpu_native), // Disable LTO for parsers
});
// Rust parser
const rust_parser_lib = b.addLibrary(.{
.name = "tree-sitter-rust",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
rust_parser_lib.addIncludePath(b.path("vendor/tree-sitter-rust/src"));
rust_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-rust/src"),
.files = &.{ "parser.c", "scanner.c" },
.flags = getCFlags(optimize, false, cpu_native), // Disable LTO for parsers
});
// Go parser
const go_parser_lib = b.addLibrary(.{
.name = "tree-sitter-go",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
go_parser_lib.addIncludePath(b.path("vendor/tree-sitter-go/src"));
go_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-go/src"),
.files = &.{"parser.c"},
.flags = getCFlags(optimize, false, cpu_native), // Disable LTO for parsers
});
// Zig parser
const zig_parser_lib = b.addLibrary(.{
.name = "tree-sitter-zig",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
zig_parser_lib.addIncludePath(b.path("vendor/tree-sitter-zig/src"));
zig_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-zig/src"),
.files = &.{"parser.c"},
.flags = getCFlags(optimize, false, cpu_native), // Disable LTO for parsers
});
// C parser
const c_parser_lib = b.addLibrary(.{
.name = "tree-sitter-c",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
c_parser_lib.addIncludePath(b.path("vendor/tree-sitter-c/src"));
c_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-c/src"),
.files = &.{"parser.c"},
.flags = getCFlags(optimize, false, cpu_native), // Disable LTO for parsers
});
// C++ parser
const cpp_parser_lib = b.addLibrary(.{
.name = "tree-sitter-cpp",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
cpp_parser_lib.addIncludePath(b.path("vendor/tree-sitter-cpp/src"));
cpp_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-cpp/src"),
.files = &.{ "parser.c", "scanner.c" },
.flags = getCFlags(optimize, false, cpu_native), // Disable LTO for parsers
});
// Java parser
const java_parser_lib = b.addLibrary(.{
.name = "tree-sitter-java",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
java_parser_lib.addIncludePath(b.path("vendor/tree-sitter-java/src"));
java_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-java/src"),
.files = &.{"parser.c"},
.flags = getCFlags(optimize, false, cpu_native), // Disable LTO for parsers
});
// Kotlin parser
const kotlin_parser_lib = b.addLibrary(.{
.name = "tree-sitter-kotlin",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
kotlin_parser_lib.addIncludePath(b.path("vendor/tree-sitter-kotlin/src"));
kotlin_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-kotlin/src"),
.files = &.{ "parser.c", "scanner.c" },
.flags = getCFlags(optimize, false, cpu_native),
});
// C# parser
const csharp_parser_lib = b.addLibrary(.{
.name = "tree-sitter-c-sharp",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
csharp_parser_lib.addIncludePath(b.path("vendor/tree-sitter-c-sharp/src"));
csharp_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-c-sharp/src"),
.files = &.{ "parser.c", "scanner.c" },
.flags = getCFlags(optimize, false, cpu_native),
});
// Ruby parser
const ruby_parser_lib = b.addLibrary(.{
.name = "tree-sitter-ruby",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
ruby_parser_lib.addIncludePath(b.path("vendor/tree-sitter-ruby/src"));
ruby_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-ruby/src"),
.files = &.{ "parser.c", "scanner.c" },
.flags = getCFlags(optimize, false, cpu_native),
});
// PHP parser (nested php/src/ structure)
const php_parser_lib = b.addLibrary(.{
.name = "tree-sitter-php",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
php_parser_lib.addIncludePath(b.path("vendor/tree-sitter-php/php/src"));
php_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-php/php/src"),
.files = &.{ "parser.c", "scanner.c" },
.flags = getCFlags(optimize, false, cpu_native),
});
// Swift parser
const swift_parser_lib = b.addLibrary(.{
.name = "tree-sitter-swift",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
swift_parser_lib.addIncludePath(b.path("vendor/tree-sitter-swift/src"));
swift_parser_lib.addCSourceFiles(.{
.root = b.path("vendor/tree-sitter-swift/src"),
.files = &.{ "parser.c", "scanner.c" },
.flags = getCFlags(optimize, false, cpu_native),
});
// All tree-sitter parser libraries as a tuple for DRY linkage
const parser_libs = .{
ts_parser_lib, py_parser_lib, js_parser_lib,
rust_parser_lib, go_parser_lib, zig_parser_lib,
c_parser_lib, cpp_parser_lib, java_parser_lib,
kotlin_parser_lib, csharp_parser_lib, ruby_parser_lib,
php_parser_lib, swift_parser_lib,
};
// Install all tree-sitter parser libraries so they can be used by examples and other dependents
inline for (parser_libs) |pl| b.installArtifact(pl);
// Core Ananke modules
// Note: We need to create modules first, then add imports after
// API modules (http and claude)
const http_mod = b.addModule("http", .{
.root_source_file = b.path("src/api/http.zig"),
.target = target,
});
const claude_mod = b.addModule("claude", .{
.root_source_file = b.path("src/api/claude.zig"),
.target = target,
});
claude_mod.addImport("http", http_mod);
// Main Ananke module (declared first so we can reference it)
const ananke_mod = b.addModule("ananke", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
});
// Clew: Constraint extraction engine
const clew_mod = b.addModule("clew", .{
.root_source_file = b.path("src/clew/clew.zig"),
.target = target,
.link_libc = true,
});
clew_mod.addImport("ananke", ananke_mod);
clew_mod.addImport("http", http_mod);
clew_mod.addImport("claude", claude_mod);
clew_mod.addImport("tree_sitter", tree_sitter_mod);
// Braid: Constraint compilation engine
const braid_mod = b.addModule("braid", .{
.root_source_file = b.path("src/braid/braid.zig"),
.target = target,
});
braid_mod.addImport("ananke", ananke_mod);
braid_mod.addImport("http", http_mod);
braid_mod.addImport("claude", claude_mod);
// Ariadne: Optional DSL compiler
const ariadne_mod = b.addModule("ariadne", .{
.root_source_file = b.path("src/ariadne/ariadne.zig"),
.target = target,
});
ariadne_mod.addImport("ananke", ananke_mod);
// Now add imports to ananke_mod
ananke_mod.addImport("clew", clew_mod);
ananke_mod.addImport("braid", braid_mod);
ananke_mod.addImport("ariadne", ariadne_mod);
ananke_mod.addImport("http", http_mod);
ananke_mod.addImport("claude", claude_mod);
// CLI modules (dependent on ananke)
const cli_args_mod = b.addModule("cli_args", .{
.root_source_file = b.path("src/cli/args.zig"),
.target = target,
});
const cli_output_mod = b.addModule("cli_output", .{
.root_source_file = b.path("src/cli/output.zig"),
.target = target,
});
cli_output_mod.addImport("ananke", ananke_mod);
const security_mod = b.addModule("security", .{
.root_source_file = b.path("src/security/secure_string.zig"),
.target = target,
});
const path_validator_mod = b.addModule("path_validator", .{
.root_source_file = b.path("src/cli/path_validator.zig"),
.target = target,
});
const sanitizer_mod = b.addModule("sanitizer", .{
.root_source_file = b.path("src/braid/sanitizer.zig"),
.target = target,
});
const cli_config_mod = b.addModule("cli_config", .{
.root_source_file = b.path("src/cli/config.zig"),
.target = target,
});
cli_config_mod.addImport("security", security_mod);
const cli_error_mod = b.addModule("cli_error", .{
.root_source_file = b.path("src/cli/error.zig"),
.target = target,
});
cli_error_mod.addImport("cli_output", cli_output_mod);
const cli_error_help_mod = b.addModule("cli_error_help", .{
.root_source_file = b.path("src/cli/error_help.zig"),
.target = target,
});
cli_error_help_mod.addImport("cli_output", cli_output_mod);
cli_error_help_mod.addImport("cli_error", cli_error_mod);
// CLI command modules
const cli_extract_mod = b.addModule("cli_extract", .{
.root_source_file = b.path("src/cli/commands/extract.zig"),
.target = target,
});
cli_extract_mod.addImport("ananke", ananke_mod);
cli_extract_mod.addImport("cli_args", cli_args_mod);
cli_extract_mod.addImport("cli_output", cli_output_mod);
cli_extract_mod.addImport("cli_config", cli_config_mod);
cli_extract_mod.addImport("cli_error", cli_error_mod);
cli_extract_mod.addImport("cli_error_help", cli_error_help_mod);
cli_extract_mod.addImport("path_validator", path_validator_mod);
const cli_compile_mod = b.addModule("cli_compile", .{
.root_source_file = b.path("src/cli/commands/compile.zig"),
.target = target,
});
cli_compile_mod.addImport("ananke", ananke_mod);
cli_compile_mod.addImport("cli_args", cli_args_mod);
cli_compile_mod.addImport("cli_output", cli_output_mod);
cli_compile_mod.addImport("cli_config", cli_config_mod);
cli_compile_mod.addImport("cli_error", cli_error_mod);
cli_compile_mod.addImport("cli_error_help", cli_error_help_mod);
cli_compile_mod.addImport("path_validator", path_validator_mod);
const cli_generate_mod = b.addModule("cli_generate", .{
.root_source_file = b.path("src/cli/commands/generate.zig"),
.target = target,
});
cli_generate_mod.addImport("ananke", ananke_mod);
cli_generate_mod.addImport("cli_args", cli_args_mod);
cli_generate_mod.addImport("cli_output", cli_output_mod);
cli_generate_mod.addImport("cli_config", cli_config_mod);
cli_generate_mod.addImport("cli_error", cli_error_mod);
const cli_export_spec_mod = b.addModule("cli_export_spec", .{
.root_source_file = b.path("src/cli/commands/export_spec.zig"),
.target = target,
});
cli_export_spec_mod.addImport("ananke", ananke_mod);
cli_export_spec_mod.addImport("cli_args", cli_args_mod);
cli_export_spec_mod.addImport("cli_output", cli_output_mod);
cli_export_spec_mod.addImport("cli_config", cli_config_mod);
cli_export_spec_mod.addImport("cli_error", cli_error_mod);
cli_export_spec_mod.addImport("path_validator", path_validator_mod);
const cli_validate_mod = b.addModule("cli_validate", .{
.root_source_file = b.path("src/cli/commands/validate.zig"),
.target = target,
});
cli_validate_mod.addImport("ananke", ananke_mod);
cli_validate_mod.addImport("cli_args", cli_args_mod);
cli_validate_mod.addImport("cli_output", cli_output_mod);
cli_validate_mod.addImport("cli_config", cli_config_mod);
cli_validate_mod.addImport("cli_error", cli_error_mod);
cli_validate_mod.addImport("cli_error_help", cli_error_help_mod);
cli_validate_mod.addImport("path_validator", path_validator_mod);
const cli_init_mod = b.addModule("cli_init", .{
.root_source_file = b.path("src/cli/commands/init.zig"),
.target = target,
});
cli_init_mod.addImport("cli_args", cli_args_mod);
cli_init_mod.addImport("cli_config", cli_config_mod);
cli_init_mod.addImport("cli_error", cli_error_mod);
const cli_version_mod = b.addModule("cli_version", .{
.root_source_file = b.path("src/cli/commands/version.zig"),
.target = target,
});
cli_version_mod.addImport("cli_args", cli_args_mod);
cli_version_mod.addImport("cli_config", cli_config_mod);
cli_version_mod.addImport("cli_output", cli_output_mod);
const cli_help_mod = b.addModule("cli_help", .{
.root_source_file = b.path("src/cli/commands/help.zig"),
.target = target,
});
cli_help_mod.addImport("cli_args", cli_args_mod);
cli_help_mod.addImport("cli_config", cli_config_mod);
cli_help_mod.addImport("cli_output", cli_output_mod);
cli_help_mod.addImport("cli/commands/extract", cli_extract_mod);
cli_help_mod.addImport("cli/commands/compile", cli_compile_mod);
cli_help_mod.addImport("cli/commands/generate", cli_generate_mod);
cli_help_mod.addImport("cli/commands/export_spec", cli_export_spec_mod);
cli_help_mod.addImport("cli/commands/validate", cli_validate_mod);
cli_help_mod.addImport("cli/commands/init", cli_init_mod);
cli_help_mod.addImport("cli/commands/version", cli_version_mod);
// Build static library for FFI integration with Rust Maze
const lib = b.addLibrary(.{
.name = "ananke",
.linkage = .static,
.root_module = b.createModule(.{
.root_source_file = b.path("src/ffi/zig_ffi.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "clew", .module = clew_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
lib.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| lib.linkLibrary(pl);
b.installArtifact(lib);
// Build dynamic/shared library for FFI integration with Node.js (VSCode extension)
const shared_lib = b.addLibrary(.{
.name = "ananke_shared",
.linkage = .dynamic,
.root_module = b.createModule(.{
.root_source_file = b.path("src/ffi/zig_ffi.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "clew", .module = clew_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
shared_lib.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| shared_lib.linkLibrary(pl);
b.installArtifact(shared_lib);
// Build step for VSCode extension shared library
const vscode_lib_step = b.step("vscode-lib", "Build shared library for VSCode extension FFI");
vscode_lib_step.dependOn(&shared_lib.step);
// Here we define an executable. An executable needs to have a root module
// which needs to expose a `main` function. While we could add a main function
// to the module defined above, it's sometimes preferable to split business
// logic and the CLI into two separate modules.
//
// If your goal is to create a Zig library for others to use, consider if
// it might benefit from also exposing a CLI tool. A parser library for a
// data serialization format could also bundle a CLI syntax checker, for example.
//
// If instead your goal is to create an executable, consider if users might
// be interested in also being able to embed the core functionality of your
// program in their own executable in order to avoid the overhead involved in
// subprocessing your CLI tool.
//
// If neither case applies to you, feel free to delete the declaration you
// don't need and to put everything under a single module.
const exe = b.addExecutable(.{
.name = "ananke",
.root_module = b.createModule(.{
// b.createModule defines a new module just like b.addModule but,
// unlike b.addModule, it does not expose the module to consumers of
// this package, which is why in this case we don't have to give it a name.
.root_source_file = b.path("src/main.zig"),
// Target and optimization levels must be explicitly wired in when
// defining an executable or library (in the root module), and you
// can also hardcode a specific target for an executable or library
// definition if desireable (e.g. firmware for embedded devices).
.target = target,
.optimize = optimize,
.link_libc = true,
// List of modules available for import in source files part of the
// root module.
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "clew", .module = clew_mod },
.{ .name = "braid", .module = braid_mod },
.{ .name = "ariadne", .module = ariadne_mod },
.{ .name = "cli/args", .module = cli_args_mod },
.{ .name = "cli/output", .module = cli_output_mod },
.{ .name = "cli/config", .module = cli_config_mod },
.{ .name = "cli/error", .module = cli_error_mod },
.{ .name = "cli/error_help", .module = cli_error_help_mod },
.{ .name = "cli/commands/extract", .module = cli_extract_mod },
.{ .name = "cli/commands/compile", .module = cli_compile_mod },
.{ .name = "cli/commands/generate", .module = cli_generate_mod },
.{ .name = "cli/commands/export_spec", .module = cli_export_spec_mod },
.{ .name = "cli/commands/validate", .module = cli_validate_mod },
.{ .name = "cli/commands/init", .module = cli_init_mod },
.{ .name = "cli/commands/version", .module = cli_version_mod },
.{ .name = "cli/commands/help", .module = cli_help_mod },
},
}),
});
// Link tree-sitter libraries
exe.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| exe.linkLibrary(pl);
// This declares intent for the executable to be installed into the
// install prefix when running `zig build` (i.e. when executing the default
// step). By default the install prefix is `zig-out/` but can be overridden
// by passing `--prefix` or `-p`.
b.installArtifact(exe);
// Example: Claude integration demo
const claude_example = b.addExecutable(.{
.name = "claude_integration",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/claude_integration.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "http", .module = http_mod },
.{ .name = "claude", .module = claude_mod },
},
}),
});
b.installArtifact(claude_example);
// Run step for Claude integration example
const run_claude_example_step = b.step("run-example", "Run the Claude integration example");
const run_claude_example_cmd = b.addRunArtifact(claude_example);
run_claude_example_step.dependOn(&run_claude_example_cmd.step);
run_claude_example_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_claude_example_cmd.addArgs(args);
}
// This creates a top level step. Top level steps have a name and can be
// invoked by name when running `zig build` (e.g. `zig build run`).
// This will evaluate the `run` step rather than the default step.
// For a top level step to actually do something, it must depend on other
// steps (e.g. a Run step, as we will see in a moment).
const run_step = b.step("run", "Run the app");
// This creates a RunArtifact step in the build graph. A RunArtifact step
// invokes an executable compiled by Zig. Steps will only be executed by the
// runner if invoked directly by the user (in the case of top level steps)
// or if another step depends on it, so it's up to you to define when and
// how this Run step will be executed. In our case we want to run it when
// the user runs `zig build run`, so we create a dependency link.
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
// By making the run step depend on the default step, it will be run from the
// installation directory rather than directly from within the cache directory.
run_cmd.step.dependOn(b.getInstallStep());
// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| {
run_cmd.addArgs(args);
}
// WASM library build (if requested)
// TODO: Implement WASM build when needed
_ = wasm_build;
// Creates an executable that will run `test` blocks from the provided module.
const mod_tests = b.addTest(.{
.root_module = ananke_mod,
});
// A run step that will run the test executable.
const run_mod_tests = b.addRunArtifact(mod_tests);
// Creates an executable that will run `test` blocks from the executable's
// root module. Note that test executables only test one module at a time,
// hence why we have to create two separate ones.
const exe_tests = b.addTest(.{
.root_module = exe.root_module,
});
// A run step that will run the second test executable.
const run_exe_tests = b.addRunArtifact(exe_tests);
// Creates test executable for Clew Claude integration tests
const clew_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/clew/claude_integration_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "clew", .module = clew_mod },
.{ .name = "claude", .module = claude_mod },
},
}),
});
clew_tests.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| clew_tests.linkLibrary(pl);
const run_clew_tests = b.addRunArtifact(clew_tests);
// Cache tests
const cache_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/clew/cache_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "clew", .module = clew_mod },
},
}),
});
cache_tests.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| cache_tests.linkLibrary(pl);
const run_cache_tests = b.addRunArtifact(cache_tests);
// Pattern extraction tests
const pattern_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/clew/pattern_extraction_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "clew", .module = clew_mod },
},
}),
});
pattern_tests.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| pattern_tests.linkLibrary(pl);
const run_pattern_tests = b.addRunArtifact(pattern_tests);
// Tree-sitter FFI tests
const tree_sitter_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/clew/tree_sitter_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "tree_sitter", .module = tree_sitter_mod },
},
}),
});
tree_sitter_tests.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| tree_sitter_tests.linkLibrary(pl);
const run_tree_sitter_tests = b.addRunArtifact(tree_sitter_tests);
// Hybrid extractor integration tests
const hybrid_extractor_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/clew/hybrid_extractor_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "clew", .module = clew_mod },
.{ .name = "tree_sitter", .module = tree_sitter_mod },
},
}),
});
hybrid_extractor_tests.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| hybrid_extractor_tests.linkLibrary(pl);
const run_hybrid_extractor_tests = b.addRunArtifact(hybrid_extractor_tests);
// Tree-sitter traversal integration tests
const traversal_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/clew/tree_sitter_traversal_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "tree_sitter", .module = tree_sitter_mod },
},
}),
});
traversal_tests.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| traversal_tests.linkLibrary(pl);
const run_traversal_tests = b.addRunArtifact(traversal_tests);
// Phase 3: Rust/Go/Zig extraction tests
const rust_go_zig_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/clew/rust_go_zig_extraction_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "clew", .module = clew_mod },
},
}),
});
rust_go_zig_tests.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| rust_go_zig_tests.linkLibrary(pl);
const run_rust_go_zig_tests = b.addRunArtifact(rust_go_zig_tests);
// Graph algorithm tests for Braid constraint compilation
const graph_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/braid/graph_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
const run_graph_tests = b.addRunArtifact(graph_tests);
// JSON Schema generation tests for Braid
const json_schema_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/braid/json_schema_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
const run_json_schema_tests = b.addRunArtifact(json_schema_tests);
// Grammar generation tests for Braid
const grammar_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/braid/grammar_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
const run_grammar_tests = b.addRunArtifact(grammar_tests);
// Regex pattern extraction tests for Braid
const regex_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/braid/regex_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
const run_regex_tests = b.addRunArtifact(regex_tests);
// Constraint operations tests for Braid
const constraint_ops_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/braid/constraint_ops_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
const run_constraint_ops_tests = b.addRunArtifact(constraint_ops_tests);
// Token mask generation tests for Braid
const token_mask_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/braid/token_mask_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
const run_token_mask_tests = b.addRunArtifact(token_mask_tests);
// Incremental compilation tests for Braid
const incremental_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/braid/incremental_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
const run_incremental_tests = b.addRunArtifact(incremental_tests);
// Integration tests for Extract -> Compile pipeline
const integration_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/integration/pipeline_tests.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "clew", .module = clew_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
integration_tests.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| integration_tests.linkLibrary(pl);
const run_integration_tests = b.addRunArtifact(integration_tests);
// E2E integration tests for full Zig -> Rust -> Modal pipeline
const e2e_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/integration/e2e_pipeline_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "clew", .module = clew_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
e2e_tests.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| e2e_tests.linkLibrary(pl);
const run_e2e_tests = b.addRunArtifact(e2e_tests);
// New comprehensive E2E test suite with fixtures
const new_e2e_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/e2e/e2e_test.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "ananke", .module = ananke_mod },
.{ .name = "clew", .module = clew_mod },
.{ .name = "braid", .module = braid_mod },
},
}),
});
new_e2e_tests.linkSystemLibrary("tree-sitter");
inline for (parser_libs) |pl| new_e2e_tests.linkLibrary(pl);
const run_new_e2e_tests = b.addRunArtifact(new_e2e_tests);
// Phase 2 E2E tests: Full pipeline integration
const phase2_full_pipeline_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/e2e/phase2/full_pipeline_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{