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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const strip = b.option(bool, "strip", "strip debug symbols from the relay") orelse false;
const offline_replay = b.option(bool, "offline-replay", "enable bounded offline corpus replay") orelse false;
const zat = b.dependency("zat", .{
.target = target,
.optimize = optimize,
});
const websocket = b.dependency("websocket", .{
.target = target,
.optimize = optimize,
});
const pg = b.dependency("pg", .{
.target = target,
.optimize = optimize,
});
const zkv = b.dependency("zkv", .{
.target = target,
.optimize = optimize,
});
const zio = b.dependency("zio", .{
.target = target,
.optimize = optimize,
});
// -Dbackend=zio swaps the std.Io implementation under the whole relay.
// Both variants must compile from the same source; see docs/design.md.
const backend = b.option(enum { threaded, zio }, "backend", "std.Io backend (default: threaded)") orelse .threaded;
const backend_opts = b.addOptions();
backend_opts.addOption(bool, "use_zio", backend == .zio);
const imports: []const std.Build.Module.Import = &.{
.{ .name = "zat", .module = zat.module("zat") },
.{ .name = "websocket", .module = websocket.module("websocket") },
.{ .name = "pg", .module = pg.module("pg") },
.{ .name = "zkv", .module = zkv.module("zkv") },
.{ .name = "zio", .module = zio.module("zio") },
.{ .name = "backend_config", .module = backend_opts.createModule() },
};
// embed build info (git SHA + optimize mode) for canary metric
const build_options = b.addOptions();
build_options.addOption([]const u8, "git_sha", git_sha: {
var code: u8 = 0;
const result = b.runAllowFail(&.{ "git", "rev-parse", "--short", "HEAD" }, &code, .ignore);
if (result) |output| {
break :git_sha std.mem.trimEnd(u8, output, "\n \t");
} else |_| {
break :git_sha "unknown";
}
});
build_options.addOption([]const u8, "optimize", @tagName(optimize));
const use_gpa = b.option(bool, "use_gpa", "use GeneralPurposeAllocator for leak detection (slow)") orelse false;
build_options.addOption(bool, "use_gpa", use_gpa);
build_options.addOption(bool, "offline_replay", offline_replay);
build_options.addOption(bool, "profile_stages", b.option(bool, "profile-stages", "measure live frame processing stages") orelse false);
// relay executable
const relay_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
});
relay_mod.addImport("build_options", build_options.createModule());
if (offline_replay) {
relay_mod.addImport("relay_corpus", b.createModule(.{
.root_source_file = b.path("src/internal/testing/relay_corpus.zig"),
.target = target,
.optimize = optimize,
}));
}
relay_mod.link_libc = true;
relay_mod.strip = strip;
const relay = b.addExecutable(.{
.name = "zlay",
.root_module = relay_mod,
});
b.installArtifact(relay);
b.step("relay", "install only the relay executable").dependOn(&b.addInstallArtifact(relay, .{}).step);
const run_relay = b.addRunArtifact(relay);
run_relay.addPassthruArgs();
const run_step = b.step("run", "run the relay");
run_step.dependOn(&run_relay.step);
const proof_mod = b.createModule(.{
.root_source_file = b.path("src/proof_replay.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.link_libc = true,
});
proof_mod.addImport("build_options", build_options.createModule());
const proof = b.addExecutable(.{ .name = "proof-replay", .root_module = proof_mod });
b.step("proof-replay", "install the offline captured-proof verifier").dependOn(&b.addInstallArtifact(proof, .{}).step);
// conformance harness — runs the atmoq relay-conformance corpora through
// the real decode + validation path (see src/conformance_main.zig)
const conformance_mod = b.createModule(.{
.root_source_file = b.path("src/conformance_main.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
});
conformance_mod.addImport("build_options", build_options.createModule());
conformance_mod.link_libc = true;
const conformance = b.addExecutable(.{
.name = "conformance",
.root_module = conformance_mod,
});
b.installArtifact(conformance);
const run_conformance = b.addRunArtifact(conformance);
run_conformance.addPassthruArgs();
const conformance_step = b.step("conformance", "run the relay conformance harness");
conformance_step.dependOn(&run_conformance.step);
const space_mod = b.createModule(.{
.root_source_file = b.path("src/index_space.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.link_libc = true,
});
const space = b.addExecutable(.{ .name = "index-space", .root_module = space_mod });
b.step("index-space", "install the offline index space comparison").dependOn(
&b.addInstallArtifact(space, .{}).step,
);
const index_bench_mod = b.createModule(.{
.root_source_file = b.path("src/index_bench.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.link_libc = true,
.link_libcpp = false,
});
const index_bench = b.addExecutable(.{ .name = "index-bench", .root_module = index_bench_mod });
b.step("index-bench", "install the offline collection index benchmark").dependOn(
&b.addInstallArtifact(index_bench, .{}).step,
);
const corpus_mod = b.createModule(.{
.root_source_file = b.path("src/index_corpus.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.link_libc = true,
.link_libcpp = false,
});
const corpus = b.addExecutable(.{ .name = "index-corpus", .root_module = corpus_mod });
b.step("index-corpus", "install the offline captured-frame index replay").dependOn(
&b.addInstallArtifact(corpus, .{}).step,
);
const strip_load = b.option(bool, "strip-load", "strip debug information from the load harness") orelse false;
const read_cost = b.addExecutable(.{
.name = "index-read-cost",
.root_module = b.createModule(.{
.root_source_file = b.path("src/index_read_cost.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.link_libc = true,
}),
});
b.step("index-read-cost", "install the reader refresh and dispatch microcosm").dependOn(&b.addInstallArtifact(read_cost, .{}).step);
const owner_cost = b.addExecutable(.{
.name = "index-owner-cost",
.root_module = b.createModule(.{
.root_source_file = b.path("src/index_owner_cost.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.link_libc = true,
}),
});
b.step("index-owner-cost", "install the scheduled owner-handoff control").dependOn(&b.addInstallArtifact(owner_cost, .{}).step);
const load_mod = b.createModule(.{
.strip = strip_load,
.root_source_file = b.path("src/index_load.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.link_libc = true,
.link_libcpp = false,
});
const load = b.addExecutable(.{ .name = "index-load", .root_module = load_mod });
b.step("index-load", "install the fixed-arrival-rate collection index load test").dependOn(
&b.addInstallArtifact(load, .{}).step,
);
const recovery_mod = b.createModule(.{
.root_source_file = b.path("src/index_recovery.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.link_libc = true,
.strip = strip_load,
});
const recovery = b.addExecutable(.{ .name = "index-recovery", .root_module = recovery_mod });
b.step("index-recovery", "install the process-crash collection index recovery test").dependOn(
&b.addInstallArtifact(recovery, .{}).step,
);
const runtime_mod = b.createModule(.{
.strip = strip_load,
.root_source_file = b.path("src/index_runtime.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.link_libc = true,
});
const runtime_probe = b.addExecutable(.{ .name = "index-runtime", .root_module = runtime_mod });
b.step("index-runtime", "install the one-executor reader scheduling probe").dependOn(
&b.addInstallArtifact(runtime_probe, .{}).step,
);
// tests
// tests — a single module rooted at src/ so every internal/ import resolves
const test_step = b.step("test", "run unit tests");
const test_mod = b.createModule(.{
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
});
test_mod.addImport("build_options", build_options.createModule());
test_mod.link_libc = true;
const t = b.addTest(.{
.root_module = test_mod,
});
test_step.dependOn(&b.addRunArtifact(t).step);
const index_test_mod = b.createModule(.{
.root_source_file = b.path("src/index_tests.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.link_libc = true,
});
const index_tests = b.addTest(.{ .root_module = index_test_mod });
b.step("test-index", "test collection index ownership, readers, maintenance, backfill and resync").dependOn(&b.addRunArtifact(index_tests).step);
}