summaryrefslogtreecommitdiff
path: root/build/tools.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 13:26:02 -0300
committerGabriel Schneider <[email protected]>2026-11-17 13:26:17 -0300
commite5c57a863004914136c4e6b0fa13ed805b3b383d (patch)
tree4c3895acfcf310a82432546f9ed02c666a7daefa /build/tools.zig
parent9aa2ac1a21bd96260538f2657ff37b63562380ff (diff)
downloadpardes-e5c57a863004914136c4e6b0fa13ed805b3b383d.tar.gz
pardes-e5c57a863004914136c4e6b0fa13ed805b3b383d.zip
build: build() cut into build/*.zig, as pure moves
build.zig 2,406 -> 658 lines; the pieces moved verbatim into a file per thing, each a function called where its code stood, so every step, module and option is made in the same order as before: build/docs.zig (the typst renders, builtins-json, command-line.txt), build/addons.zig (the GPU addons, the pdf addon and its benches, the image addon), build/patches.zig (vaxis, zstbi, ghostty's kitty loader, mvzr), build/gui.zig (the window's shells and its renderer and atlas tests), build/macos.zig (the app, dmg, e2e, its unit-test), build/tools.zig (harnesses, hx*, benches, perf, the syntax snapshots, lib-test, history), build/tests.zig (unit-test and its roots), build/library.zig (what a dependent package gets), build/core.zig (the options module, themes, grammars, uucode, the editor module, wireCore); mupdf.zig is build/mupdf.zig. A fragment takes what it uses as explicit parameters, or as one struct of exactly those (cloud9's and build/process.zig's pattern). Platform, PerfBuild and TreeSitterGrammars stay in build.zig: Options names an enum or struct by @typeName, so where they are declared is in every options file. Gate: zig build --print-configuration, -l and -h byte-identical to the base over bare (-Dhome-install=false), tui, gui, macos, tui and gui ReleaseFast, -Dpdf=false (tui, gui), -Dtree-sitter=minimal, musl, -Dtracy, and test/lib's -l and --print-configuration. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'build/tools.zig')
-rw-r--r--build/tools.zig399
1 files changed, 399 insertions, 0 deletions
diff --git a/build/tools.zig b/build/tools.zig
new file mode 100644
index 00000000..0819401c
--- /dev/null
+++ b/build/tools.zig
@@ -0,0 +1,399 @@
+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;
+
+/// What unit-test runs of what these make.
+pub const Tools = struct {
+ perf_gate_step: *std.Build.Step,
+ perf_tests: *std.Build.Step.Compile,
+ fs_bench_test: *std.Build.Step.Compile,
+ 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_heap_mod: *std.Build.Module,
+ 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,
+ mvzr_mod: *std.Build.Module,
+ no_pdf: ?*std.Build.Step,
+ optimize: std.lang.Optimize,
+ opts: *std.Build.Step.Options,
+ pdf_addon: ?*std.Build.Step.Compile,
+ platform: Platform,
+ prebuilt_shaders: bool,
+ shell_cfg: core.ShellConfig,
+ target: std.Build.ResolvedTarget,
+ term_mod: *std.Build.Module,
+ test_filters: []const []const u8,
+ themes_mod: *std.Build.Module,
+ tracy: ?[]const u8,
+ tree_sitter_grammars: TreeSitterGrammars,
+ ts_libs: std.ArrayList(*std.Build.Step.Compile),
+ ts_mod: ?*std.Build.Module,
+ ts_queries_opts: ?*std.Build.Step.Options,
+ unit_profile: *std.Build.Step.Compile,
+ uucode_mod: *std.Build.Module,
+ vaxis_mod: *std.Build.Module,
+}) Tools {
+ const image_harness = b.addExecutable(.{
+ .name = "pardes-image-harness",
+ .root_module = b.createModule(.{
+ .target = c.target,
+ .optimize = c.optimize,
+ .root_source_file = b.path("test/image_harness.zig"),
+ .link_libc = true,
+ }),
+ });
+ 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 = b.addExecutable(.{
+ .name = "pardes-kitty-client",
+ .root_module = b.createModule(.{
+ .target = c.target,
+ .optimize = c.optimize,
+ .root_source_file = b.path("test/kitty_client.zig"),
+ .link_libc = true,
+ }),
+ });
+ const kitty_harness = b.addExecutable(.{
+ .name = "pardes-kitty-harness",
+ .root_module = b.createModule(.{
+ .target = c.target,
+ .optimize = c.optimize,
+ .root_source_file = b.path("test/kitty_harness.zig"),
+ .link_libc = true,
+ }),
+ });
+ 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 = b.addExecutable(.{
+ .name = "pardes-hxdiff",
+ .root_module = b.createModule(.{
+ .target = c.target,
+ .optimize = c.optimize,
+ .root_source_file = b.path("test/hxdiff.zig"),
+ .link_libc = true,
+ }),
+ });
+ hxdiff.root_module.addImport("pardes", 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 = b.addExecutable(.{
+ .name = "pardes-hxlib",
+ .root_module = b.createModule(.{
+ .target = c.target,
+ .optimize = c.optimize,
+ .root_source_file = b.path("test/hxlib.zig"),
+ .link_libc = true,
+ }),
+ });
+ hxlib.root_module.addImport("pardes-editor", core.editorModule(b, null, c.target, c.optimize, c.shell_cfg, .{
+ .themes = c.themes_mod,
+ .tree_sitter = c.ts_mod,
+ .ts_libs = c.ts_libs.items,
+ .ts_queries = c.ts_queries_opts,
+ .uucode = c.uucode_mod,
+ .mvzr = c.mvzr_mod,
+ .vaxis = c.vaxis_mod,
+ }));
+ 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 = b.addExecutable(.{
+ .name = "pardes-lspbench",
+ .root_module = b.createModule(.{
+ .target = c.target,
+ .optimize = .fast,
+ .root_source_file = b.path("test/lspbench.zig"),
+ .link_libc = true,
+ }),
+ });
+ lspbench.root_module.addImport("pardes", 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 = b.addExecutable(.{
+ .name = "pardes-rollback-bench",
+ .root_module = b.createModule(.{ .target = c.target, .optimize = c.optimize, .root_source_file = b.path("test/rollback_bench.zig"), .link_libc = true }),
+ });
+ rollback_bench.root_module.addImport("pardes", 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 replicas = b.addExecutable(.{
+ .name = "pardes-replicas",
+ .root_module = b.createModule(.{ .target = c.target, .optimize = c.optimize, .root_source_file = b.path("test/replicas.zig"), .link_libc = true }),
+ });
+ replicas.root_module.addImport("pardes", c.core_module);
+ replicas.root_module.addImport("term", c.term_mod);
+ const run_replicas = b.addRunArtifact(replicas);
+ run_replicas.addPassthruArgs();
+ run_replicas.has_side_effects = true;
+ b.step("replicas", "one authority and several replicas in process, each client typing over a delayed link: digests at quiescence, rollback rate and costs per RTT (-- [--seeds N] [--steps M] [--clients C] [--rtt 30,80,207])").dependOn(&run_replicas.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 = b.addExecutable(.{
+ .name = "pardes-perf",
+ .root_module = b.createModule(.{
+ .target = c.target,
+ .optimize = perf_optimize,
+ .root_source_file = b.path("test/perf.zig"),
+ .link_libc = true,
+ }),
+ });
+ perf.root_module.addImport("pardes", 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 perf_tests = b.addTest(.{
+ .root_module = b.createModule(.{
+ .target = c.target,
+ .optimize = c.optimize,
+ .root_source_file = b.path("test/perf.zig"),
+ .link_libc = true,
+ }),
+ .filters = c.test_filters,
+ });
+ perf_tests.root_module.addOptions("perf_options", perf_options);
+
+ const fs_bench = b.addExecutable(.{
+ .name = "pardes-fs-bench",
+ .root_module = b.createModule(.{
+ .target = c.target,
+ .optimize = .fast,
+ .root_source_file = b.path("test/fs_bench.zig"),
+ .link_libc = true,
+ }),
+ });
+ fs_bench.root_module.addImport("pardes", 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);
+ const fs_bench_test = b.addTest(.{
+ .root_module = b.createModule(.{
+ .target = c.target,
+ .optimize = c.optimize,
+ .root_source_file = b.path("test/fs_bench.zig"),
+ }),
+ .filters = c.test_filters,
+ });
+
+ const syntax_module = b.createModule(.{
+ .target = c.target,
+ .optimize = c.optimize,
+ .root_source_file = b.path("src/syntax.zig"),
+ .link_libc = true,
+ });
+ syntax_module.addOptions("pardes_config", c.opts);
+ core.wireCore(syntax_module, .{ .tree_sitter = c.ts_mod, .ts_libs = c.ts_libs.items, .ts_queries = c.ts_queries_opts, .c_heap = c.c_heap_mod });
+ const syntax_runner = b.addExecutable(.{
+ .name = "pardes-syntax",
+ .root_module = b.createModule(.{
+ .target = c.target,
+ .optimize = c.optimize,
+ .root_source_file = b.path("test/syntax.zig"),
+ .link_libc = true,
+ }),
+ });
+ syntax_runner.root_module.addImport("syntax", 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_tests = perf_tests, .fs_bench_test = fs_bench_test, .lib_test_step = lib_test_step };
+}