-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathbuild.zig
More file actions
262 lines (246 loc) · 13.4 KB
/
Copy pathbuild.zig
File metadata and controls
262 lines (246 loc) · 13.4 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lean_release = optimize == .ReleaseFast or optimize == .ReleaseSmall;
// `--version` string: stamped from `git describe` at build time so every
// binary says which commit built it; `-Dversion=X.Y.Z` overrides (the
// release workflow passes the tag).
const version = b.option([]const u8, "version", "version string for --version") orelse blk: {
var code: u8 = 0;
const raw = b.runAllowFail(
&.{ "git", "-C", ".", "describe", "--tags", "--always", "--dirty" },
&code,
.ignore,
) catch break :blk "0.1.0-dev";
const described = std.mem.trim(u8, raw, " \r\n");
if (described.len == 0) break :blk "0.1.0-dev";
// No tags yet → describe is a bare commit hash (no dot); make it
// read as a version.
break :blk if (std.mem.indexOfScalar(u8, described, '.') != null)
described
else
b.fmt("0.1.0-dev+{s}", .{described});
};
// Baked-in default OTLP telemetry endpoint: the harness phones
// usage/evolution telemetry here unless the user overrides with
// OTEL_EXPORTER_OTLP_ENDPOINT or opts out (--no-telemetry /
// GRAFF_NO_TELEMETRY). Hardcoded as the default so every build — release,
// source-install, and dev — carries it; `-Dtelemetry-endpoint=""` disables
// it at build time. The harness-telemetry worker recomputes the HMAC and
// rejects unsigned rows, so this must match the deployed collector.
const telemetry_endpoint = b.option(
[]const u8,
"telemetry-endpoint",
"default OTLP endpoint baked into builds (pass \"\" to disable; default = the deployed collector)",
) orelse "https://harness-telemetry.rachpradhan.workers.dev";
const opts = b.addOptions();
opts.addOption([]const u8, "version", version);
opts.addOption([]const u8, "telemetry_endpoint", telemetry_endpoint);
const exe = b.addExecutable(.{
.name = "graff",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.strip = lean_release,
// Linux cross-builds (x86_64-linux for in-container evals) must say
// libc explicitly; macOS resolves it implicitly and never notices.
.link_libc = true,
}),
});
exe.root_module.addOptions("build_options", opts);
// zigzag: the TUI framework backing the `graff repl` subcommand (and the
// standalone graff-repl exe below). The repo's first dependency.
const zigzag = b.dependency("zigzag", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("zigzag", zigzag.module("zigzag"));
// Shared by the line-REPL picker and the TUI overlay so they cannot
// drift: a file import from both modules is illegal in Zig 0.17.
const models_rank_mod = b.createModule(.{
.root_source_file = b.path("src/models_rank.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("models_rank", models_rank_mod);
const tui_mod = b.createModule(.{
.root_source_file = b.path("TUI/root.zig"),
.target = target,
.optimize = optimize,
});
tui_mod.addImport("models_rank", models_rank_mod);
exe.root_module.addImport("tui", tui_mod);
const install_graff = b.addInstallArtifact(exe, .{});
b.getInstallStep().dependOn(&install_graff.step);
const graff_step = b.step("graff", "Build and install only the release CLI");
graff_step.dependOn(&install_graff.step);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(&install_graff.step);
const run_step = b.step("run", "Run the harness");
run_step.dependOn(&run_cmd.step);
// `zig build test` — unit tests live in src/main.zig `test "..." {}` blocks.
// `-Dtest-filter="<text>"` (repeatable) narrows the run to the tests whose
// name contains that text. scripts/eval-tier1.sh uses it to prove the named
// goal/loop/todo invariants still run — a test whose module fell out of the
// test root exists in the source but never executes.
const test_filters = b.option(
[]const []const u8,
"test-filter",
"Only run tests whose name contains this text (repeatable)",
) orelse &[_][]const u8{};
const unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true, // workspace_switch reaches std.c.getcwd (#721); same as the exe
}),
.filters = test_filters,
});
unit_tests.root_module.addOptions("build_options", opts);
unit_tests.root_module.addImport("zigzag", zigzag.module("zigzag"));
unit_tests.root_module.addImport("models_rank", models_rank_mod);
unit_tests.root_module.addImport("tui", tui_mod);
// spec/ fixtures live outside src/; importing them here makes @embedFile
// legal and rebuilds the suite when the exported semantics change.
unit_tests.root_module.addAnonymousImport("spec_tool_catalog", .{ .root_source_file = b.path("spec/kernels/tool_catalog.json") });
unit_tests.root_module.addAnonymousImport("spec_transport", .{ .root_source_file = b.path("spec/kernels/transport.json") });
unit_tests.root_module.addAnonymousImport("spec_providers", .{ .root_source_file = b.path("spec/kernels/providers.json") });
unit_tests.root_module.addAnonymousImport("spec_goal_loop", .{ .root_source_file = b.path("spec/kernels/goal_loop.json") });
unit_tests.root_module.addAnonymousImport("spec_path_confine", .{ .root_source_file = b.path("spec/kernels/path_confine.json") });
unit_tests.root_module.addAnonymousImport("spec_shape", .{ .root_source_file = b.path("spec/kernels/shape.json") });
unit_tests.root_module.addAnonymousImport("spec_score", .{ .root_source_file = b.path("spec/kernels/score.json") });
unit_tests.root_module.addAnonymousImport("spec_bash_policy", .{ .root_source_file = b.path("spec/kernels/bash_policy.json") });
unit_tests.root_module.addAnonymousImport("spec_structured_output", .{ .root_source_file = b.path("spec/kernels/structured_output.json") });
unit_tests.root_module.addAnonymousImport("spec_prompt_cache", .{ .root_source_file = b.path("spec/kernels/prompt_cache.json") });
unit_tests.root_module.addAnonymousImport("spec_prompt_prefix", .{ .root_source_file = b.path("spec/kernels/prompt_prefix.json") });
unit_tests.root_module.addAnonymousImport("spec_prompt_stable", .{ .root_source_file = b.path("spec/kernels/prompt_stable.json") });
const run_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit and subprocess integration tests");
test_step.dependOn(&run_tests.step);
const acp_preauth_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-preauth.py" });
acp_preauth_test.addArtifactArg(exe);
test_step.dependOn(&acp_preauth_test.step);
// Learning kit: the adapter/suite files `graff learn init` materializes
// into a workspace so zero-configuration learning needs no repo checkout.
// Embedded by name (src/learn_assets.zig `@embedFile`s these imports).
for ([_]struct { import: []const u8, path: []const u8 }{
.{ .import = "learn_kit_mutator", .path = "examples/learn_graff_mutator.py" },
.{ .import = "learn_kit_evaluator", .path = "examples/learn_graff_evaluator.py" },
.{ .import = "learn_kit_case", .path = "examples/learn_graff_case.py" },
.{ .import = "learn_kit_behavior", .path = "examples/learn_behavior_metrics.py" },
.{ .import = "learn_kit_suites", .path = "examples/learn_graff_suites.py" },
.{ .import = "learn_kit_generate", .path = "examples/learn_generate_suites.py" },
.{ .import = "learn_kit_scorer", .path = "scripts/score_run.py" },
}) |asset| {
exe.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
unit_tests.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
}
// Bundled skills: SKILL.md playbooks compiled into every binary (embedded
// by name in src/skill_docs.zig), so a fresh install already knows how to
// author more skills and how to change this workspace's MCP servers.
for ([_]struct { import: []const u8, path: []const u8 }{
.{ .import = "skill_doc_creator", .path = "assets/skills/skill-creator.md" },
.{ .import = "skill_doc_mcp_config", .path = "assets/skills/mcp-config.md" },
.{ .import = "skill_doc_mcp", .path = "assets/skills/mcp.md" },
.{ .import = "skill_doc_jspace", .path = "assets/skills/jspace.md" },
.{ .import = "skill_doc_workspace", .path = "assets/skills/workspace.md" },
}) |asset| {
exe.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
unit_tests.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
}
// --- spike (branch: spike/zigzag-repl): zigzag-based REPL ---
// Also reachable as the `graff repl` subcommand of the main binary (see
// src/main.zig). This standalone exe + `repl-test` step are kept for
// isolated builds / unit tests. `zig build repl`, `zig build repl-test`.
const repl_exe = b.addExecutable(.{
.name = "graff-repl",
.root_module = b.createModule(.{
.root_source_file = b.path("src/repl.zig"),
.target = target,
.optimize = optimize,
.strip = lean_release,
}),
});
repl_exe.root_module.addOptions("build_options", opts);
repl_exe.root_module.addImport("zigzag", zigzag.module("zigzag"));
b.installArtifact(repl_exe);
const repl_run = b.addRunArtifact(repl_exe);
repl_run.step.dependOn(b.getInstallStep());
const repl_step = b.step("repl", "Run the zigzag REPL spike");
repl_step.dependOn(&repl_run.step);
const repl_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/repl.zig"),
.target = target,
.optimize = optimize,
}),
});
repl_tests.root_module.addImport("zigzag", zigzag.module("zigzag"));
const repl_test_step = b.step("repl-test", "Run zigzag REPL unit tests");
repl_test_step.dependOn(&b.addRunArtifact(repl_tests).step);
const tui_exe = b.addExecutable(.{
.name = "graff-tui",
.root_module = b.createModule(.{
.root_source_file = b.path("TUI/root.zig"),
.target = target,
.optimize = optimize,
.strip = lean_release,
.link_libc = true,
}),
});
tui_exe.root_module.addImport("models_rank", models_rank_mod);
b.installArtifact(tui_exe);
const tui_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("TUI/root.zig"),
.target = target,
.optimize = optimize,
// The dump/bench helpers read GRAFF_TUI_DUMP / GRAFF_TUI_BENCH
// through std.c.getenv. Without libc those tests do not compile
// on Linux, so the painter battery never ran here.
.link_libc = true,
}),
// Same -Dtest-filter as `zig build test`: the layout benchmark needs to
// be runnable on its own, ReleaseFast, without the rest of the suite.
.filters = test_filters,
});
tui_tests.root_module.addImport("models_rank", models_rank_mod);
tui_tests.root_module.addAnonymousImport("spec_terminal_modes", .{ .root_source_file = b.path("spec/kernels/terminal_modes.json") });
const tui_test_step = b.step("tui-test", "Run fullscreen TUI unit tests");
tui_test_step.dependOn(&b.addRunArtifact(tui_tests).step);
// In-process ACP (fx-shaped embed). Off the default install so the
// tagged CLI cut does not grow a .so / .wasm. `zig build libgraff`
// and `zig build -Dwasm-surface=core`.
const libgraff = b.addLibrary(.{
.linkage = .dynamic,
.name = "graff",
.root_module = b.createModule(.{
.root_source_file = b.path("src/libgraff.zig"),
.target = target,
.optimize = optimize,
.strip = lean_release,
}),
});
const libgraff_step = b.step("libgraff", "Build the in-process ACP shared library");
libgraff_step.dependOn(&b.addInstallArtifact(libgraff, .{}).step);
_ = b.option([]const u8, "wasm-surface", "wasm surface: core (use `zig build wasm-core`)");
// Pinned ReleaseSmall regardless of the global optimize: the wasm surface
// ships in @codegraff/sdk for JS hosts, so size is the axis that matters
// (vercel-labs/fx pins it the same way). -Doptimize still overrides.
const wasm = b.addExecutable(.{
.name = "graff-core",
.root_module = b.createModule(.{
.root_source_file = b.path("src/wasm_core_main.zig"),
.target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
}),
.optimize = if (optimize == .Debug) .ReleaseSmall else optimize,
.strip = true,
}),
});
wasm.entry = .disabled;
wasm.rdynamic = true;
const wasm_step = b.step("wasm-core", "Build graff-core.wasm (in-process ACP)");
wasm_step.dependOn(&b.addInstallArtifact(wasm, .{}).step);
}