-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.zig
More file actions
444 lines (398 loc) · 17.5 KB
/
Copy pathbuild.zig
File metadata and controls
444 lines (398 loc) · 17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
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
const std = @import("std");
/// Run a test binary in terminal mode (avoiding Zig 0.16 server-mode IPC
/// which hangs with this project's test suite).
fn addRunTestTerminal(b: *std.Build, exe: *std.Build.Step.Compile) *std.Build.Step.Run {
const step_name = if (exe.kind == .@"test" and std.mem.eql(u8, exe.name, "test"))
b.fmt("run {s}", .{@tagName(exe.kind)})
else
b.fmt("run {s} {s}", .{ @tagName(exe.kind), exe.name });
const run_step = std.Build.Step.Run.create(b, step_name);
run_step.producer = exe;
if (exe.exec_cmd_args) |exec_cmd_args| {
for (exec_cmd_args) |cmd_arg| {
if (cmd_arg) |arg| {
run_step.addArg(arg);
} else {
run_step.addArtifactArg(exe);
}
}
} else {
run_step.addArtifactArg(exe);
}
run_step.stdio = .inherit;
if (b.args) |args| {
run_step.addArgs(args);
}
return run_step;
}
pub fn build(b: *std.Build) void {
if (b.option(bool, "incremental", "Enable incremental compilation (faster rebuilds)")) |inc| {
b.graph.incremental = inc;
}
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const version_override = b.option([]const u8, "version", "Orca version metadata");
const version = blk: {
if (version_override) |v| break :blk v;
const io = b.graph.io;
const version_file = std.Io.Dir.cwd().readFileAlloc(io, "VERSION", b.allocator, std.Io.Limit.limited(32)) catch break :blk "1.1.0";
const trimmed = std.mem.trim(u8, version_file, " \n\r\t");
const result = b.allocator.dupe(u8, trimmed) catch break :blk "1.1.0";
b.allocator.free(version_file);
break :blk result;
};
const commit = b.option([]const u8, "commit", "Source commit metadata") orelse "unknown";
const build_date = b.option([]const u8, "build-date", "UTC build date metadata") orelse "unknown";
const build_options = b.addOptions();
build_options.addOption([]const u8, "version", version);
build_options.addOption([]const u8, "commit", commit);
build_options.addOption([]const u8, "build_date", build_date);
const build_options_mod = build_options.createModule();
const core_schema_documents = b.addOptions();
core_schema_documents.addOption([]const u8, "policy_v1", @embedFile("schemas/policy-v1.json"));
core_schema_documents.addOption([]const u8, "event_v1", @embedFile("schemas/event-v1.json"));
core_schema_documents.addOption([]const u8, "mcp_manifest_v1", @embedFile("schemas/mcp-manifest-v1.json"));
const core_schema_documents_mod = core_schema_documents.createModule();
_ = &core_schema_documents_mod;
const orca_core_engine_mod = b.createModule(.{
.root_source_file = b.path("src/core_engine.zig"),
.target = target,
.optimize = optimize,
});
const orca_core_mod = b.addModule("orca_core", .{
.root_source_file = b.path("packages/core/src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "core_engine", .module = orca_core_engine_mod },
},
});
const orca_mod = b.addModule("orca", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca_core", .module = orca_core_mod },
.{ .name = "build_options", .module = build_options_mod },
},
});
orca_mod.addImport("build_options", build_options_mod);
const orca_cli_mod = b.addModule("orca_cli", .{
.root_source_file = b.path("packages/cli/src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
.{ .name = "orca_core", .module = orca_core_mod },
.{ .name = "build_options", .module = build_options_mod },
},
});
const exe = b.addExecutable(.{
.name = "orca",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
.{ .name = "build_options", .module = build_options_mod },
},
}),
});
exe.root_module.link_libc = true;
b.installArtifact(exe);
const install_orca = b.addInstallArtifact(exe, .{});
const install_orca_step = b.step("install-orca", "Install Orca CLI only");
install_orca_step.dependOn(&install_orca.step);
const run_step = b.step("run", "Run the Orca CLI");
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
run_step.dependOn(&run_cmd.step);
const lib_tests = b.addTest(.{
.root_module = orca_mod,
});
const run_lib_tests = addRunTestTerminal(b, lib_tests);
const exe_tests = b.addTest(.{
.root_module = exe.root_module,
});
const run_exe_tests = addRunTestTerminal(b, exe_tests);
const core_package_tests = b.addTest(.{
.root_module = orca_core_mod,
});
const run_core_package_tests = addRunTestTerminal(b, core_package_tests);
// Independent run steps for focused test targets (do not inherit lib test dependency).
const run_core_package_tests_only = addRunTestTerminal(b, core_package_tests);
const core_contract_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("packages/core/tests/contract.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca_core", .module = orca_core_mod },
},
}),
});
const run_core_contract_tests = addRunTestTerminal(b, core_contract_tests);
const run_core_contract_tests_only = addRunTestTerminal(b, core_contract_tests);
const cli_package_tests = b.addTest(.{
.root_module = orca_cli_mod,
});
const run_cli_package_tests = addRunTestTerminal(b, cli_package_tests);
const cli_contract_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("packages/cli/tests/contract.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca_cli", .module = orca_cli_mod },
},
}),
});
const run_cli_contract_tests = addRunTestTerminal(b, cli_contract_tests);
const phase2d_daemon_hook_matrix_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase2d_daemon_hook_matrix.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
},
}),
});
const run_phase2d_daemon_hook_matrix_tests = addRunTestTerminal(b, phase2d_daemon_hook_matrix_tests);
const phase2e_hook_dispatch_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase2e_hook_dispatch.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
},
}),
});
const run_phase2e_hook_dispatch_tests = addRunTestTerminal(b, phase2e_hook_dispatch_tests);
const phase2f_hook_validation_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase2f_hook_validation.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
},
}),
});
const run_phase2f_hook_validation_tests = addRunTestTerminal(b, phase2f_hook_validation_tests);
const phase2510_gui_audit_feed_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase2510_gui_audit_feed.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
},
}),
});
const run_phase2510_gui_audit_feed_tests = addRunTestTerminal(b, phase2510_gui_audit_feed_tests);
const phase25_hardening_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase25_cli_hardening.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
},
}),
});
const run_phase25_hardening_tests = addRunTestTerminal(b, phase25_hardening_tests);
const phase42_customer_acquisition_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase42_drone_customer_acquisition.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_phase42_customer_acquisition_tests = addRunTestTerminal(b, phase42_customer_acquisition_tests);
const phase36_codex_plugin_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase36_codex_plugin.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_phase36_codex_plugin_tests = addRunTestTerminal(b, phase36_codex_plugin_tests);
const phase37_claude_plugin_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase37_claude_plugin.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_phase37_claude_plugin_tests = addRunTestTerminal(b, phase37_claude_plugin_tests);
const phase38_plugin_security_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase38_plugin_security_and_compatibility.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
},
}),
});
const run_phase38_plugin_security_tests = addRunTestTerminal(b, phase38_plugin_security_tests);
const phase39_openclaw_plugin_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase39_openclaw_plugin.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_phase39_openclaw_plugin_tests = addRunTestTerminal(b, phase39_openclaw_plugin_tests);
const phase43_hermes_plugin_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase43_hermes_plugin.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_phase43_hermes_plugin_tests = addRunTestTerminal(b, phase43_hermes_plugin_tests);
const phase44_version_drift_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase44_version_drift.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_phase44_version_drift_tests = addRunTestTerminal(b, phase44_version_drift_tests);
const phase44_setup_opencode_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase44_setup_opencode_detection.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
},
}),
});
const run_phase44_setup_opencode_tests = addRunTestTerminal(b, phase44_setup_opencode_tests);
const phase44_install_workspace_paths_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase44_install_workspace_paths.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
},
}),
});
const run_phase44_install_workspace_paths_tests = addRunTestTerminal(b, phase44_install_workspace_paths_tests);
const phase45_start_onboarding_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/phase45_start_onboarding.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
},
}),
});
const run_phase45_start_onboarding_tests = addRunTestTerminal(b, phase45_start_onboarding_tests);
const setup_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/setup.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
.{ .name = "orca_core", .module = orca_core_mod },
},
}),
});
const run_setup_tests = addRunTestTerminal(b, setup_tests);
const check_step = b.step("check", "Compile Orca CLI only (fastest compile gate)");
check_step.dependOn(&exe.step);
const compile_test_lib_step = b.step("compile-test-lib", "Compile orca lib unit tests without running");
compile_test_lib_step.dependOn(&lib_tests.step);
const compile_test_fast_step = b.step("compile-test-fast", "Compile test-fast artifacts without running");
compile_test_fast_step.dependOn(&lib_tests.step);
compile_test_fast_step.dependOn(&core_package_tests.step);
compile_test_fast_step.dependOn(&core_contract_tests.step);
const test_lib_step = b.step("test-lib", "Run orca lib inline tests only");
test_lib_step.dependOn(&run_lib_tests.step);
const test_core_step = b.step("test-core", "Run orca_core package tests only");
test_core_step.dependOn(&run_core_package_tests_only.step);
const test_core_contract_step = b.step("test-core-contract", "Run packages/core contract tests only");
test_core_contract_step.dependOn(&run_core_contract_tests_only.step);
// Serialize runs so local `zig build test-fast` does not launch three heavy test
// binaries at once (parallel runs have hung with no output on some hosts).
run_core_package_tests.step.dependOn(&run_lib_tests.step);
run_core_contract_tests.step.dependOn(&run_core_package_tests.step);
const test_fast_step = b.step("test-fast", "Run fast unit tests (orca lib + orca_core)");
test_fast_step.dependOn(&run_core_contract_tests.step);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_tests.step);
test_step.dependOn(&run_exe_tests.step);
test_step.dependOn(&run_core_package_tests.step);
test_step.dependOn(&run_core_contract_tests.step);
test_step.dependOn(&run_cli_package_tests.step);
test_step.dependOn(&run_cli_contract_tests.step);
test_step.dependOn(&run_phase25_hardening_tests.step);
test_step.dependOn(&run_phase2d_daemon_hook_matrix_tests.step);
test_step.dependOn(&run_phase2e_hook_dispatch_tests.step);
test_step.dependOn(&run_phase2f_hook_validation_tests.step);
test_step.dependOn(&run_phase2510_gui_audit_feed_tests.step);
test_step.dependOn(&run_phase42_customer_acquisition_tests.step);
test_step.dependOn(&run_phase36_codex_plugin_tests.step);
test_step.dependOn(&run_phase37_claude_plugin_tests.step);
test_step.dependOn(&run_phase38_plugin_security_tests.step);
test_step.dependOn(&run_phase39_openclaw_plugin_tests.step);
test_step.dependOn(&run_phase43_hermes_plugin_tests.step);
test_step.dependOn(&run_phase44_version_drift_tests.step);
test_step.dependOn(&run_phase44_setup_opencode_tests.step);
test_step.dependOn(&run_phase44_install_workspace_paths_tests.step);
test_step.dependOn(&run_phase45_start_onboarding_tests.step);
test_step.dependOn(&run_setup_tests.step);
const fuzz_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/fuzz/security_mutation.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = orca_mod },
},
}),
});
const run_fuzz_tests = addRunTestTerminal(b, fuzz_tests);
const fuzz_step = b.step("fuzz", "Run deterministic security mutation tests");
fuzz_step.dependOn(&run_fuzz_tests.step);
test_step.dependOn(&run_fuzz_tests.step);
const windows_target = b.resolveTargetQuery(.{
.cpu_arch = .x86_64,
.os_tag = .windows,
});
const windows_mod = b.addModule("orca-windows-check", .{
.root_source_file = b.path("src/root.zig"),
.target = windows_target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca_core", .module = orca_core_mod },
.{ .name = "build_options", .module = build_options_mod },
},
});
const windows_exe = b.addExecutable(.{
.name = "orca-windows-check",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = windows_target,
.optimize = optimize,
.imports = &.{
.{ .name = "orca", .module = windows_mod },
.{ .name = "build_options", .module = build_options_mod },
},
}),
});
const check_windows_step = b.step("check-windows", "Compile Orca for Windows without running it");
check_windows_step.dependOn(&windows_exe.step);
}