-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.zig
More file actions
150 lines (139 loc) · 7.24 KB
/
Copy pathbuild.zig
File metadata and controls
150 lines (139 loc) · 7.24 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
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,
}),
});
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"));
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,
}),
.filters = test_filters,
});
unit_tests.root_module.addOptions("build_options", opts);
unit_tests.root_module.addImport("zigzag", zigzag.module("zigzag"));
const run_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.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" },
}) |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.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);
}