summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig90
1 files changed, 63 insertions, 27 deletions
diff --git a/build.zig b/build.zig
index 9bc1d2b6..7d64f995 100644
--- a/build.zig
+++ b/build.zig
@@ -4,15 +4,6 @@ pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
- const exe = b.addExecutable(.{
- .name = "pardes",
- .root_module = b.createModule(.{
- .target = target,
- .optimize = optimize,
- .root_source_file = b.path("main.zig"),
- }),
- });
-
// ghostty-vt and vaxis both depend on uucode, but Zig 0.16 forbids the
// same source file from belonging to two modules, so they can't each have
// their own uucode instance. We build a single uucode module here (with our
@@ -42,30 +33,75 @@ pub fn build(b: *std.Build) void {
});
const vaxis_mod = vaxis_dep.module("vaxis");
- // You'll want to use a lazy dependency here so that ghostty is only
- // downloaded if you actually need it.
- if (b.lazyDependency("ghostty", .{
- // Setting simd to false will force a pure static build that
- // doesn't even require libc, but it has a significant performance
- // penalty. If your embedding app requires libc anyway, you should
- // always keep simd enabled.
+ // Accessing ghostty's modules runs its build(), which (because vaxis is a
+ // shared dependency, deduplicated to the same module) wires ghostty's own
+ // uucode into vaxis. We override both with ours below; order matters, so
+ // ghostty must be touched before the final vaxis uucode override.
+ const ghostty_vt: ?*std.Build.Module = if (b.lazyDependency("ghostty", .{
+ // Setting simd to false will force a pure static build that doesn't
+ // even require libc, but it has a significant performance penalty. If
+ // your embedding app requires libc anyway, you should always keep simd
+ // enabled. We need libc anyway (forkpty), so we keep it on.
// .simd = false,
- })) |dep| {
- // Accessing ghostty's modules runs its build(), which (because vaxis is
- // a shared dependency, deduplicated to the same module) wires ghostty's
- // own uucode into vaxis. We undo that below by overriding both imports
- // with ours — order matters, so this must happen after this point.
- const ghostty_vt = dep.module("ghostty-vt");
- ghostty_vt.addImport("uucode", uucode_mod);
- exe.root_module.addImport("ghostty-vt", ghostty_vt);
- }
+ })) |dep| blk: {
+ const mod = dep.module("ghostty-vt");
+ mod.addImport("uucode", uucode_mod);
+ break :blk mod;
+ } else null;
// Override uucode on vaxis last, so it wins over ghostty's build() above.
vaxis_mod.addImport("uucode", uucode_mod);
- exe.root_module.addImport("vaxis", vaxis_mod);
- const run_exe = b.addRunArtifact(exe);
+ // Wires the shared imports onto a root module. We link libc for `forkpty`
+ // (see pty.zig).
+ const wire = struct {
+ fn apply(
+ mod: *std.Build.Module,
+ vaxis_m: *std.Build.Module,
+ ghostty_m: ?*std.Build.Module,
+ ) void {
+ mod.link_libc = true;
+ mod.addImport("vaxis", vaxis_m);
+ if (ghostty_m) |g| mod.addImport("ghostty-vt", g);
+ }
+ }.apply;
+
+ // The app.
+ const exe_mod = b.createModule(.{
+ .target = target,
+ .optimize = optimize,
+ .root_source_file = b.path("main.zig"),
+ });
+ wire(exe_mod, vaxis_mod, ghostty_vt);
+ const exe = b.addExecutable(.{ .name = "pardes", .root_module = exe_mod });
+ b.installArtifact(exe);
+ const run_exe = b.addRunArtifact(exe);
const run = b.step("run", "descend to the pardes");
run.dependOn(&run_exe.step);
+
+ // Deterministic pipeline tests (pty -> ghostty-vt -> grid + input encode).
+ const test_mod = b.createModule(.{
+ .target = target,
+ .optimize = optimize,
+ .root_source_file = b.path("tests.zig"),
+ });
+ wire(test_mod, vaxis_mod, ghostty_vt);
+ const tests = b.addTest(.{ .root_module = test_mod });
+ const run_tests = b.addRunArtifact(tests);
+ const test_step = b.step("test", "run the pipeline + smoke tests");
+ test_step.dependOn(&run_tests.step);
+
+ // End-to-end smoke: drives the real `pardes` binary under a pty. Only needs
+ // libc (forkpty); the pardes path is passed in as argv[1].
+ const smoke_mod = b.createModule(.{
+ .target = target,
+ .optimize = optimize,
+ .root_source_file = b.path("smoke.zig"),
+ });
+ smoke_mod.link_libc = true;
+ const smoke = b.addExecutable(.{ .name = "smoke", .root_module = smoke_mod });
+ const run_smoke = b.addRunArtifact(smoke);
+ run_smoke.addArtifactArg(exe); // builds pardes first, passes its path
+ test_step.dependOn(&run_smoke.step);
}