summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-07-28 13:21:42 -0300
committerGabriel Schneider <[email protected]>2026-08-01 15:02:07 -0300
commit0b5ad7a30ba9e7c6eedcb426be294bd94219310f (patch)
tree1a991acfb2a14f25ece19e13e65915dbbb48c7fc /build.zig
parent95202b9b22751c86f100aae9ff1c64e535dcbd70 (diff)
downloadpardes-0b5ad7a30ba9e7c6eedcb426be294bd94219310f.tar.gz
pardes-0b5ad7a30ba9e7c6eedcb426be294bd94219310f.zip
build.zig runners and testing improvements
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig65
1 files changed, 18 insertions, 47 deletions
diff --git a/build.zig b/build.zig
index a4d530f1..6073bbcc 100644
--- a/build.zig
+++ b/build.zig
@@ -1,4 +1,5 @@
const std = @import("std");
+const snap_build = @import("build/snap.zig");
pub const Platform = enum { tty, gui, web };
pub const TreeSitterGrammars = enum { disabled, zig, minimal, full };
@@ -24,6 +25,13 @@ pub fn build(b: *std.Build) void {
const is_emscripten = target.result.os.tag == .emscripten;
// wasm: size is the budget
const optimize = if (is_emscripten) .ReleaseSmall else requested_optimize;
+ // The vendored C is never what we are debugging, and at -O0 it dominates
+ // the app: 90% of a Debug startup is tree-sitter's query analyser
+ // (perf: ts_query__perform_analysis + ts_lookahead_iterator__next), and
+ // stb_image decodes at a crawl. Building the C optimized whatever the Zig
+ // mode takes a Debug boot from ~710ms to ~210ms — the same treatment
+ // ghostty's simdutf/highway already get here. Zig code keeps its mode.
+ const c_optimize: std.builtin.OptimizeMode = if (optimize == .Debug) .ReleaseFast else optimize;
const default_grammars: TreeSitterGrammars = if (is_emscripten) .zig else .full;
const tree_sitter_grammars = b.option(TreeSitterGrammars, "tree-sitter", "tree-sitter grammar set: disabled, zig, minimal (c/c++/zig), full") orelse default_grammars;
const tracy = b.option([]const u8, "tracy", "enable Tracy profiling; supply the path to a Tracy source checkout");
@@ -52,33 +60,7 @@ pub fn build(b: *std.Build) void {
const inspect_sources = b.addInstallFileWithDir(embedded_sources, .{ .custom = "web" }, "embedded_sources.zig");
b.step("embed-web-sources", "generate zig-out/web/embedded_sources.zig from tracked .zig files").dependOn(&inspect_sources.step);
- // Browser regression suite: make an isolated web build from the real TTY
- // dump captured after running `git ls-files '*.zig'`, with the Zig-only
- // tree-sitter tier. The dependency-free CDP harness then drives
- // its .snap script through real Chromium touch events. This recursive build
- // selects `web`, not `web-snap`, so it bottoms out after one level.
- const build_web_snap = b.addSystemCommand(&.{
- b.graph.zig_exe,
- "build",
- "web",
- "-Dplatform=web",
- "-Dtarget=wasm32-emscripten",
- "-Dtree-sitter=zig",
- "-Ddump=test/web-snapshots/source-list.dump.zon",
- "-p",
- "zig-out/web-snap-test",
- });
- build_web_snap.setCwd(b.path("."));
- const run_web_snap = b.addSystemCommand(&.{
- "node",
- "test/web_snapshot.mjs",
- "zig-out/web-snap-test/web",
- "test/web-snapshots/source-list.snap",
- });
- run_web_snap.setCwd(b.path("."));
- run_web_snap.step.dependOn(&build_web_snap.step);
- if (b.args) |args| run_web_snap.addArgs(args);
- b.step("web-snap", "run browser touch/LOOK snapshots (-- --update regenerates goldens)").dependOn(&run_web_snap.step);
+ snap_build.addWeb(b);
const emscripten_sysroot = if (is_emscripten) detectEmscriptenSysroot(b) else null;
if (platform == .web and !is_emscripten) return failBuild(b, web_step, "-Dplatform=web requires -Dtarget=wasm32-emscripten");
@@ -173,7 +155,7 @@ pub fn build(b: *std.Build) void {
// and each grammar's highlights.scm slurped at build time into the
// ts_queries options module (codegen consumed by comptime in syntax.zig).
if (tree_sitter_grammars != .disabled) {
- const tree_sitter_mod = b.dependency("tree_sitter", .{ .target = target, .optimize = optimize }).module("tree_sitter");
+ const tree_sitter_mod = b.dependency("tree_sitter", .{ .target = target, .optimize = c_optimize }).module("tree_sitter");
// the C runtime rides the module as a static lib; give it the wasm
// libc and hand its archive to the emcc link
if (is_emscripten) {
@@ -237,7 +219,7 @@ pub fn build(b: *std.Build) void {
const lib = b.addLibrary(.{
.name = "tree-sitter-" ++ g.name,
- .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true }),
+ .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }),
.linkage = .static,
});
if (libc_file) |f| lib.setLibCFile(f);
@@ -263,7 +245,7 @@ pub fn build(b: *std.Build) void {
}
// zstbi (C stb_image): image pane decode. zigimg crashes the 0.16 compiler.
- const zstbi_dep = b.dependency("zstbi", .{ .target = target, .optimize = optimize });
+ const zstbi_dep = b.dependency("zstbi", .{ .target = target, .optimize = c_optimize });
root_mod.addImport("zstbi", zstbi_dep.module("root"));
hx_core_mod.addImport("zstbi", zstbi_dep.module("root"));
@@ -484,24 +466,13 @@ pub fn build(b: *std.Build) void {
// snapshot parity suite: scripted input traces in a pty, captured grids
// diffed against the goldens in snapshots/ — the frozen record of parity
- // with the prototype this program replaced. `-- --update` regenerates.
- const snap = b.addExecutable(.{
- .name = "pardes-snap",
- .root_module = b.createModule(.{
- .target = target,
- .optimize = optimize,
- .root_source_file = b.path("test/snapshot.zig"),
- .link_libc = true,
- }),
+ // with the prototype this program replaced. See build/snap.zig.
+ snap_build.addTty(b, .{
+ .exe = exe,
+ .target = target,
+ .optimize = optimize,
+ .ghostty_vt = ghostty_vt_for_snap,
});
- if (ghostty_vt_for_snap) |vt| snap.root_module.addImport("ghostty-vt", vt);
- if (target.result.os.tag == .freebsd or target.result.os.tag == .netbsd or target.result.os.tag == .openbsd)
- snap.root_module.linkSystemLibrary("util", .{});
- b.installArtifact(snap);
- const run_snap = b.addRunArtifact(snap);
- run_snap.addArtifactArg(exe);
- if (b.args) |args| run_snap.addArgs(args);
- b.step("snap", "run the snapshot parity suite (-- --update regenerates goldens)").dependOn(&run_snap.step);
// helix differential harness: drive the sans-IO core headlessly over
// JSON-Lines cases, one contract result line per case on stdout —