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
|
const std = @import("std");
const builtin = @import("builtin");
const Platform = @import("../build.zig").Platform;
const PerfBuild = @import("../build.zig").PerfBuild;
const TreeSitterGrammars = @import("../build.zig").TreeSitterGrammars;
const core = @import("core.zig");
const testMatch = @import("tests.zig").testMatch;
/// A program of this build's, from `root`, with libc and `imports`: the
/// harnesses, benches and runners below and in tests.zig.
pub fn program(b: *std.Build, name: []const u8, root: []const u8, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, imports: []const std.Build.Module.Import) *std.Build.Step.Compile {
return b.addExecutable(.{ .name = name, .root_module = b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path(root), .link_libc = true, .imports = imports }) });
}
/// What unit-test runs of what these make.
pub const Tools = struct {
perf_gate_step: *std.Build.Step,
/// The perf program's build identity, which its own tests read too.
perf_options: *std.Build.Step.Options,
lib_test_step: *std.Build.Step,
};
/// The harnesses, the helix comparisons, the benches and the perf gate, the
/// syntax snapshots and their tests, the library's package test and history.
pub fn add(b: *std.Build, c: struct {
c_optimize: std.lang.Optimize,
core_module: *std.Build.Module,
enable_jpx: bool,
exe: *std.Build.Step.Compile,
ghostty_optimize: std.lang.Optimize,
ghostty_simd: bool,
ghostty_vt_for_tests: ?*std.Build.Module,
image_addon: *std.Build.Step.Compile,
/// core-test's core: the syntax module's tests run on it.
lean: core.Core,
no_pdf: ?*std.Build.Step,
optimize: std.lang.Optimize,
parts: core.Parts,
pdf_addon: ?*std.Build.Step.Compile,
platform: Platform,
prebuilt_shaders: bool,
shell_cfg: core.ShellConfig,
target: std.Build.ResolvedTarget,
test_filters: []const []const u8,
tracy: ?[]const u8,
tree_sitter_grammars: TreeSitterGrammars,
unit_profile: *std.Build.Step.Compile,
}) Tools {
const image_harness = program(b, "pardes-image-harness", "test/image_harness.zig", c.target, c.optimize, &.{});
if (c.ghostty_vt_for_tests) |vt| image_harness.root_module.addImport("ghostty-vt", vt);
switch (c.target.result.os.tag) {
.freebsd, .netbsd, .openbsd => image_harness.root_module.linkSystemLibrary("util", .{}),
else => {},
}
const run_image_harness = b.addRunArtifact(image_harness);
run_image_harness.addArtifactArg(c.exe);
run_image_harness.addArtifactArg(c.image_addon);
run_image_harness.addArg(if (c.platform == .gui) "gui" else "tui");
run_image_harness.has_side_effects = true;
b.step("image-harness", "exercise native Kitty/SDL image rendering end to end").dependOn(&run_image_harness.step);
// Kitty graphics through a terminal pane, end to end: a client in
// the pane's bash (and kitten icat, chafa when installed), a kitty
// terminal outside (tui) or the GPU capture (gui). test/kitty.zig
// is the same protocol at the core.
const kitty_client = program(b, "pardes-kitty-client", "test/kitty_client.zig", c.target, c.optimize, &.{});
const kitty_harness = program(b, "pardes-kitty-harness", "test/kitty_harness.zig", c.target, c.optimize, &.{});
if (c.ghostty_vt_for_tests) |vt| kitty_harness.root_module.addImport("ghostty-vt", vt);
switch (c.target.result.os.tag) {
.freebsd, .netbsd, .openbsd => kitty_harness.root_module.linkSystemLibrary("util", .{}),
else => {},
}
const run_kitty_harness = b.addRunArtifact(kitty_harness);
run_kitty_harness.addArtifactArg(c.exe);
run_kitty_harness.addArtifactArg(kitty_client);
run_kitty_harness.addArg(if (c.platform == .gui) "gui" else "tui");
run_kitty_harness.has_side_effects = true;
b.step("kitty-harness", "kitty graphics through a terminal pane end to end (a client inside, a kitty terminal or the GPU capture outside)").dependOn(&run_kitty_harness.step);
const pdf_harness_step = b.step("pdf-harness", "exercise continuous PDF rendering, search, and sections navigation end to end");
if (c.no_pdf) |s| pdf_harness_step.dependOn(s) else {
const run_pdf_harness = b.addRunArtifact(image_harness);
run_pdf_harness.addArtifactArg(c.exe);
run_pdf_harness.addArtifactArg(c.image_addon);
run_pdf_harness.addArg(if (c.platform == .gui) "gui" else "tui");
run_pdf_harness.addArg("pdf");
run_pdf_harness.addArtifactArg(c.pdf_addon.?);
run_pdf_harness.has_side_effects = true;
pdf_harness_step.dependOn(&run_pdf_harness.step);
}
const hxdiff = program(b, "pardes-hxdiff", "test/hxdiff.zig", c.target, c.optimize, &.{.{ .name = "pardes", .module = c.core_module }});
const run_hxdiff = b.addRunArtifact(hxdiff);
run_hxdiff.has_side_effects = true;
// Bare, it runs the checked-in suite (test/hxdiff.zig); `-- --parity`
// runs each case in a file pane and a pty pane and compares the two.
run_hxdiff.addPassthruArgs();
run_hxdiff.setCwd(b.path("."));
// the new line's indent per file type, against the reference helix
// with its grammars (test/hxcases/hx_indent.py): before the suite,
// whose count stays the last line
const run_hxindent = b.addRunArtifact(hxdiff);
run_hxindent.has_side_effects = true;
run_hxindent.addArgs(&.{ "--strict", "test/hxcases/indent.jsonl", "test/hxcases/indent-goldens.jsonl" });
run_hxindent.setCwd(b.path("."));
run_hxdiff.step.dependOn(&run_hxindent.step);
const hxdiff_step = b.step("hxdiff", "compare Helix results (-- --strict cases reference [waivers]; cases alone emits; --parity: a pty pane against a file pane)");
hxdiff_step.dependOn(&run_hxdiff.step);
// The same cases on the library (src/lib_editor.zig): test/hxlib.zig
// types them into an editor value and prints its results, which
// hxdiff holds against helix's goldens, or with `-- --parity`
// against the file pane, so the library cannot drift from either.
const hxlib = program(b, "pardes-hxlib", "test/hxlib.zig", c.target, c.optimize, &.{});
hxlib.root_module.addImport("pardes-editor", core.editorModule(b, null, c.target, c.optimize, c.shell_cfg, .{ .themes = c.parts.themes, .ts = c.parts.ts, .uucode = c.parts.uucode, .mvzr = c.parts.mvzr, .vaxis = c.parts.vaxis }));
const run_hxlib = b.addRunArtifact(hxlib);
run_hxlib.addArgs(&.{ "test/hxcases/cases.jsonl", "test/hxcases/parity.jsonl" });
run_hxlib.setCwd(b.path("."));
run_hxlib.has_side_effects = true;
const run_hxdiff_lib = b.addRunArtifact(hxdiff);
run_hxdiff_lib.has_side_effects = true;
run_hxdiff_lib.addPrefixedFileArg("--actual=", run_hxlib.captureStdOut(.{}));
run_hxdiff_lib.addPassthruArgs();
run_hxdiff_lib.setCwd(b.path("."));
b.step("hxlib", "hxdiff's cases on the library, against helix's goldens (-- --parity: against the file pane)").dependOn(&run_hxdiff_lib.step);
const helix_harness = b.option([]const u8, "helix-harness", "path to the reference hx-harness executable") orelse
b.graph.environ_map.get("HX_HARNESS") orelse "hx-harness";
const reference = b.addSystemCommand(&.{helix_harness});
reference.addFileArg(b.path("test/hxcases/cases.jsonl"));
reference.has_side_effects = true;
const reference_results = reference.captureStdOut(.{});
const live_diff = b.addRunArtifact(hxdiff);
live_diff.addArg("--strict");
live_diff.addFileArg(b.path("test/hxcases/cases.jsonl"));
live_diff.addFileArg(reference_results);
live_diff.addFileArg(b.path("test/hxcases/waivers.jsonl"));
live_diff.has_side_effects = true;
b.step("hxdiff-live", "compare the editor against a freshly run Helix reference").dependOn(&live_diff.step);
const update_reference = b.addUpdateSourceFiles();
update_reference.addCopyFileToSource(reference_results, "test/hxcases/goldens.jsonl");
update_reference.step.dependOn(&live_diff.step);
b.step("hxdiff-update", "replace checked-in Helix goldens after the live comparison passes").dependOn(&update_reference.step);
// every helix-golf example, one case per step of its walkthrough
const run_hxgolf = b.addRunArtifact(hxdiff);
run_hxgolf.has_side_effects = true;
run_hxgolf.addArgs(&.{ "--strict", "test/hxcases/golf.jsonl", "test/hxcases/golf-goldens.jsonl", "test/hxcases/golf-waivers.jsonl" });
run_hxgolf.setCwd(b.path("."));
b.step("hxgolf", "compare the helix-golf examples against their Helix results").dependOn(&run_hxgolf.step);
const lspbench = program(b, "pardes-lspbench", "test/lspbench.zig", c.target, .fast, &.{.{ .name = "pardes", .module = c.core_module }});
const run_lspbench = b.addRunArtifact(lspbench);
run_lspbench.addPassthruArgs();
run_lspbench.setCwd(b.path("."));
run_lspbench.has_side_effects = true;
const lspbench_step = b.step("lspbench", "language-backend latency + feature matrix (-- [--json] [--check] [repo-root]), or one query (-- probe <kind> <file> <line>:<col> [arg] [--reps N])");
lspbench_step.dependOn(&run_lspbench.step);
const rollback_bench = program(b, "pardes-rollback-bench", "test/rollback_bench.zig", c.target, c.optimize, &.{.{ .name = "pardes", .module = c.core_module }});
const run_rollback_bench = b.addRunArtifact(rollback_bench);
run_rollback_bench.has_side_effects = true;
b.step("rollback-bench", "a replica's rollback copy (walked state, pinned blobs, walk time) for a typical and a big session, and a fork of the big one (-Doptimize=ReleaseFast)").dependOn(&run_rollback_bench.step);
const locations_bench_step = b.step("locations-bench", "measure cold/warm result formatting (-Doptimize=ReleaseFast; CSV on stderr)");
if (c.optimize != .fast) {
locations_bench_step.dependOn(&b.addFail("locations-bench requires -Doptimize=ReleaseFast").step);
} else {
const locations_bench_module = b.createModule(.{
.target = c.target,
.optimize = .fast,
.root_source_file = b.path("test/locations_bench.zig"),
.link_libc = true,
});
locations_bench_module.addImport("pardes", c.core_module);
const locations_bench = b.addTest(.{ .root_module = locations_bench_module, .filters = &.{"locations benchmark cold and warm formatting"} });
const run_locations_bench = b.addRunArtifact(locations_bench);
run_locations_bench.has_side_effects = true;
locations_bench_step.dependOn(&run_locations_bench.step);
}
const perf_optimize: std.lang.Optimize = .fast;
const perf_options = b.addOptions();
const perf_target = std.Target.Query.fromTarget(&c.target.result);
perf_options.addOption(PerfBuild, "identity", .{
.compiler = builtin.zig_version_string,
.target = perf_target.zigTriple(b.allocator) catch @panic("out of memory"),
.cpu = perf_target.serializeCpuAlloc(b.allocator) catch @panic("out of memory"),
.driver_optimize = @tagName(perf_optimize),
.core_optimize = @tagName(c.optimize),
.c_optimize = @tagName(c.c_optimize),
.terminal_optimize = @tagName(c.ghostty_optimize),
.platform = @tagName(c.platform),
.grammars = @tagName(c.tree_sitter_grammars),
.mupdf = c.pdf_addon != null,
.jpx = c.enable_jpx,
.tracy = c.tracy != null,
.terminal_simd = c.ghostty_simd,
.prebuilt_shaders = c.platform == .gui and c.prebuilt_shaders,
});
perf_options.addOptionPath("image_addon", c.image_addon.getEmittedBin());
perf_options.addOption(bool, "has_pdf_addon", c.pdf_addon != null);
if (c.pdf_addon) |l| perf_options.addOptionPath("pdf_addon", l.getEmittedBin());
const perf = program(b, "pardes-perf", "test/perf.zig", c.target, perf_optimize, &.{.{ .name = "pardes", .module = c.core_module }});
// --live drives the real binary through a pty (test/e2e_harness.zig).
if (c.ghostty_vt_for_tests) |vt| perf.root_module.addImport("ghostty-vt", vt);
perf.root_module.addOptions("perf_options", perf_options);
const run_perf = b.addRunArtifact(perf);
run_perf.has_side_effects = true;
run_perf.addPassthruArgs();
run_perf.setCwd(b.path("."));
const perf_step = b.step("perf", "gesture latency or bounded terminal stress (-- [--json] [--reps N] [--base old.json] [--terminal-mib N])");
perf_step.dependOn(&run_perf.step);
// The gate: the 50k-line file's gestures against the baseline this
// build shape recorded, each within 3x of its best. Record one with
// `zig build perf -Dplatform=P [-Doptimize=O] -- --only medium
// --reps 10 --json > test/perf-baseline-P-O.json` (a build that is
// known good). ponytail: the numbers are this machine's; another
// machine records its own.
const perf_gate = b.addRunArtifact(perf);
perf_gate.has_side_effects = true;
perf_gate.setCwd(b.path("."));
perf_gate.addArgs(&.{ "--only", "medium", "--reps", "10", "--base", b.fmt("test/perf-baseline-{t}-{t}.json", .{ c.platform, c.optimize }), "--max-ratio", "3" });
const perf_gate_step = b.step("perf-gate", "fail when a gesture on the 50k-line file takes over 3x its recorded baseline (test/perf-baseline-<platform>-<optimize>.json)");
perf_gate_step.dependOn(&perf_gate.step);
const fs_bench = program(b, "pardes-fs-bench", "test/fs_bench.zig", c.target, .fast, &.{.{ .name = "pardes", .module = c.core_module }});
const run_fs_bench = b.addRunArtifact(fs_bench);
run_fs_bench.has_side_effects = true;
run_fs_bench.addPassthruArgs();
run_fs_bench.setCwd(b.path("."));
const fs_bench_step = b.step("fs-bench", "9P filesystem request cost and allocation count (-- [--json] [--reps N])");
fs_bench_step.dependOn(&run_fs_bench.step);
// The syntax module's own tests and snapshots, on the core without
// a terminal: its tests reach the editor's modes (modal.zig).
var syntax_cfg = c.lean;
syntax_cfg.root = "src/syntax.zig";
const syntax_module = core.module(b, c.parts, syntax_cfg);
const syntax_runner = program(b, "pardes-syntax", "test/syntax.zig", c.target, c.optimize, &.{.{ .name = "syntax", .module = syntax_module }});
const run_syntax = b.addRunArtifact(syntax_runner);
run_syntax.addPassthruArgs();
run_syntax.has_side_effects = true;
b.step("syntax", "emit deterministic syntax snapshots (-- --bench: highlighting latency and allocations)").dependOn(&run_syntax.step);
const syntax_test = b.addTest(.{
.root_module = syntax_module,
.filters = if (c.test_filters.len == 0) &.{"syntax "} else c.test_filters,
});
const run_syntax_test = b.addRunArtifact(syntax_test);
run_syntax_test.has_side_effects = true;
const syntax_test_step = b.step("syntax-test", "test syntax correctness without building the editor");
syntax_test_step.dependOn(&run_syntax_test.step);
if (testMatch(b, c.unit_profile, c.test_filters, syntax_test_step)) |check| check.addArtifactArg(syntax_test);
// The library as a package that depends on pardes is given it
// (`library`): test/lib's own `zig build test`, over the packages
// this checkout has fetched.
const lib_test = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "test", "--pkg-dir", "../../zig-pkg" });
lib_test.setCwd(b.path("test/lib"));
lib_test.has_side_effects = true;
const lib_test_step = b.step("lib-test", "build and test the library from a package that depends on pardes (test/lib)");
lib_test_step.dependOn(&lib_test.step);
const history = b.addExecutable(.{
.name = "pardes-history",
.root_module = b.createModule(.{
.target = c.target,
.optimize = c.optimize,
.root_source_file = b.path("test/history.zig"),
}),
});
const run_history = b.addRunArtifact(history);
run_history.addPassthruArgs();
run_history.has_side_effects = true;
b.step("history", "compare command output and test/build runtime across jj revisions").dependOn(&run_history.step);
return .{ .perf_gate_step = perf_gate_step, .perf_options = perf_options, .lib_test_step = lib_test_step };
}
/// The PDF benches: the core over the pdf addon, a pane of it.
pub fn pdfBenches(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, core_module: *std.Build.Module, lib: *std.Build.Step.Compile, pointer_step: *std.Build.Step, scroll_step: *std.Build.Step) void {
const config = b.addOptions();
config.addOption(bool, "release_fast_core", optimize == .fast);
config.addOption([]const u8, "core_optimize", @tagName(optimize));
config.addOptionPath("pdf_addon", lib.getEmittedBin());
for ([_]struct { step: *std.Build.Step, exe: []const u8, file: []const u8, optimize: std.lang.Optimize }{
.{ .step = pointer_step, .exe = "pardes-pdf-pointer-bench", .file = "test/pdf_pointer_bench.zig", .optimize = .fast },
.{ .step = scroll_step, .exe = "pardes-pdf-scroll-bench", .file = "test/pdf_scroll_bench.zig", .optimize = optimize },
}) |bench| {
const exe = b.addExecutable(.{ .name = bench.exe, .root_module = b.createModule(.{ .target = target, .optimize = bench.optimize, .root_source_file = b.path(bench.file), .link_libc = true }) });
exe.root_module.addImport("pardes", core_module);
exe.root_module.addOptions("pdf_bench_config", config);
const run = b.addRunArtifact(exe);
run.addPassthruArgs();
run.setCwd(b.path("."));
bench.step.dependOn(&run.step);
}
}
|