diff options
| author | Gabriel Schneider <[email protected]> | 2026-07-06 18:00:54 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-01 15:02:07 -0300 |
| commit | 7a83d1548493b043e2e77022c1c87d348377ac7b (patch) | |
| tree | 75bcac77800b13695a953a3398b5bb8a95e017dd /build.zig | |
| parent | de4def3548a6729b0dfd2120495a61beef8c8c2c (diff) | |
| download | pardes-7a83d1548493b043e2e77022c1c87d348377ac7b.tar.gz pardes-7a83d1548493b043e2e77022c1c87d348377ac7b.zip | |
posix portability: linux syscalls -> libc (std.c) in one shared path. All raw std.os.linux.* call sites converted with the errno-convention flip (libc returns -1 + thread-local errno, not -errno): open/close/read/write/rename in tty.zig, gui.zig, look.zig; harness too (snapshot.zig: getcwd/mkdir/chdir/fork+waitpid/getdents64->opendir-readdir, e2e_harness.zig: clock_gettime/write/close), so the parity suite itself is POSIX-portable. Per-OS branches kept only where platforms genuinely diverge: shellCwd in look.zig (linux /proc/<pid>/cwd readlink; darwin libproc proc_pidinfo PROC_PIDVNODEPATHINFO with a hand-declared extern; other POSIX degrades to null), bash path (/usr/bin/bash on linux, /bin/bash elsewhere), TIOCSWINSZ constant (absent from std.c.T on darwin). forkpty/execv/chdir externs were already libc and are portable (fork-safety preserved: absolute-path execv, no malloc between fork and exec, initial spawns before worker threads). build.zig: forward target/optimize to the ghostty dep for native/cross (web keeps its no-target fetch), disable ghostty simd for darwin cross-builds (apple_sdk needs xcrun; scalar fallback = web config), link libutil on the BSDs. Pinned ghostty needs two one-line zig-0.16 darwin fixes, applied in the zig-pkg cache and documented in build.zig. Verified: aarch64-macos + x86_64-macos + x86_64-freebsd cross-compiles green; linux native tty + gui + web green; snapshot suite 18/18 with goldens untouched. Out of scope: gui-on-macos needs Metal shaders (SDL GPU rejects our SPIR-V there).
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -59,6 +59,10 @@ pub fn build(b: *std.Build) void { // static archives the emcc link needs beyond the zig object (grammars, SDL) var wasm_libs: std.ArrayList(std.Build.LazyPath) = .empty; + // forkpty: in libc proper on glibc>=2.34 and darwin; the BSDs keep it in libutil + if (target.result.os.tag == .freebsd or target.result.os.tag == .netbsd or target.result.os.tag == .openbsd) + root_mod.linkSystemLibrary("util", .{}); + const opts = b.addOptions(); opts.addOption(Platform, "platform", platform); opts.addOption(bool, "syntax_highlighting", tree_sitter_grammars != .disabled); @@ -171,7 +175,26 @@ pub fn build(b: *std.Build) void { }).module("vaxis"); var ghostty_vt_for_snap: ?*std.Build.Module = null; - if (b.lazyDependency("ghostty", .{ .simd = target.result.os.tag != .emscripten })) |dep| { + // ghostty's simd libs (simdutf/highway, C++) locate the Apple SDK via + // xcrun on darwin targets, so cross-compiling to macOS from elsewhere + // uses the scalar fallback (the same configuration the web shell ships). + // Native/cross builds hand ghostty the real target (it defaults to the + // host otherwise); the web path keeps its original no-target fetch, whose + // zig object never uses ghostty's artifacts. + // NOTE: darwin targets also need two one-line zig-0.16 fixes in the + // pinned ghostty (applied in the zig-pkg cache; re-apply after a fresh + // fetch, or bump the pin once upstream carries them): + // src/os/mach.zig — std.heap.next_mmap_addr_hint is gone (make the hint + // var module-local) and posix.mmap prot is now a packed struct + // (.{ .READ = true, .WRITE = true }); + // src/terminal/kitty/graphics_image.zig:185 — shm_open's variadic mode + // literal 0 must be @as(std.c.mode_t, 0). + const ghostty_simd = !target.result.os.tag.isDarwin() or b.graph.host.result.os.tag.isDarwin(); + const ghostty_dep = if (is_emscripten) + b.lazyDependency("ghostty", .{ .simd = false }) + else + b.lazyDependency("ghostty", .{ .target = target, .optimize = optimize, .simd = ghostty_simd }); + if (ghostty_dep) |dep| { const ghostty_vt = dep.module("ghostty-vt"); ghostty_vt_for_snap = ghostty_vt; ghostty_vt.addImport("uucode", uucode_mod); @@ -309,6 +332,8 @@ pub fn build(b: *std.Build) void { }), }); 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); |
