summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 12:32:23 -0300
committerGabriel Schneider <[email protected]>2026-10-29 13:11:16 -0300
commit6b89fed454fd56a3af4b576646538b45d3315146 (patch)
treef4be48c98368bc8c85c461af97528743afc98f59 /build.zig
parent34551a64366b3257ac577c5b68288f955c9eea80 (diff)
downloadpardes-6b89fed454fd56a3af4b576646538b45d3315146.tar.gz
pardes-6b89fed454fd56a3af4b576646538b45d3315146.zip
FreeBSD: the tty pardes builds for it and runs there, terminals, 9P and the daemon included
Cross-compiled with -Dtarget=x86_64-freebsd.15.0 (15 ships libutil.so.10; Zig's default 14.0 links .so.9) and run on the FreeBSD 15.1 box: - 9p_io serves there: fstatat, not Linux's statx. madvise is Linux's. - WINCH reaches the sigwait thread through a handler that does nothing: FreeBSD drops a signal ignored by default as it is sent. - A dead terminal answers a write with ENXIO, which std does not expect: a Debug build traced it to stderr, that same terminal, and recursed until the stack ran out (a session whose ssh dropped hung). No tracing there. - waitid's FreeBSD numbers and 64-bit id: a command pane's exit is seen. - No /proc: a shell's directory and program by sysctl, ttyTaken by the foreground group, the foreground job's name by its program. - File watching by FreeBSD 15's inotify. - ghostty's kitty loader: off Linux a stat comes before a t=f open (a FIFO hung it); FreeBSD's shm_open refuses O_NONBLOCK. - vaxis's test terminal has no read off Linux: no input thread for it. - test-install: the test-build programs installed into <prefix>/test, to run where the build cannot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig28
1 files changed, 23 insertions, 5 deletions
diff --git a/build.zig b/build.zig
index 034d7284..b365d265 100644
--- a/build.zig
+++ b/build.zig
@@ -1929,6 +1929,19 @@ pub fn build(b: *std.Build) void {
}
}
}
+
+ // The test-build programs installed rather than run, for a machine the
+ // build cannot run them on (`-Dtarget=x86_64-freebsd.15.0`): each into
+ // <prefix>/test, named for its root file.
+ const test_install = b.step("test-install", "install the test-build programs into <prefix>/test, to run elsewhere");
+ for (test_build.dependencies.items) |dep| {
+ const t = dep.cast(std.Build.Step.Compile) orelse continue;
+ const name = switch (t.root_module.root_source_file orelse continue) {
+ .src_path => |p| std.fs.path.stem(p.sub_path),
+ else => t.name,
+ };
+ test_install.dependOn(&b.addInstallArtifact(t, .{ .dest_dir = .{ .override = .{ .custom = "test" } }, .dest_sub_path = name }).step);
+ }
}
fn testMatch(b: *std.Build, profiler: *std.Build.Step.Compile, filters: []const []const u8, step: *std.Build.Step) ?*std.Build.Step.Run {
@@ -1964,7 +1977,8 @@ fn installHome(b: *std.Build, artifact: *std.Build.Step.Compile, home_bin: ?[]co
/// file: ghostty opens first and checks after, and the open of a FIFO
/// waits for a writer (pardes hung) while a device's open may do
/// something. On Linux an O_PATH probe looks, which opens nothing, and
-/// the same inode is reopened through /proc/self/fd.
+/// the same inode is reopened through /proc/self/fd; elsewhere a stat by
+/// path looks first.
/// - shared memory is opened non-blocking and must be a regular file, so
/// a FIFO in /dev/shm (or a symlink there to one) neither hangs nor maps.
/// - an image may be no larger than a screen's storage
@@ -1990,14 +2004,15 @@ fn patchGhosttyKitty(b: *std.Build, io: std.Io, dep: *std.Build.Dependency, vt:
.{
" const fd = std.c.shm_open(pathz, @as(c_int, @bitCast(std.c.O{ .ACCMODE = .RDONLY })), @as(u16, 0));",
\\ // pardes (build.zig): a FIFO there must not hang the open, and
- \\ // on Linux nothing but a regular file is opened at all.
+ \\ // on Linux nothing but a regular file is opened at all. FreeBSD's
+ \\ // names are no files, and its shm_open refuses O_NONBLOCK.
\\ if (comptime builtin.target.os.tag == .linux) if (path.len > 0 and path[0] == '/') {
\\ var dev: [std.Io.Dir.max_path_bytes]u8 = undefined;
\\ const full = std.fmt.bufPrint(&dev, "/dev/shm{s}", .{path}) catch return error.InvalidData;
\\ const shm_stat = std.Io.Dir.cwd().statFile(io, full, .{}) catch return error.InvalidData;
\\ if (shm_stat.kind != .file) return error.InvalidData;
\\ };
- \\ const fd = std.c.shm_open(pathz, @as(c_int, @bitCast(std.c.O{ .ACCMODE = .RDONLY, .NONBLOCK = true })), @as(u16, 0));
+ \\ const fd = std.c.shm_open(pathz, @as(c_int, @bitCast(std.c.O{ .ACCMODE = .RDONLY, .NONBLOCK = builtin.target.os.tag != .freebsd })), @as(u16, 0));
},
.{
" if (stat.size <= 0) return error.InvalidData;",
@@ -2011,9 +2026,12 @@ fn patchGhosttyKitty(b: *std.Build, io: std.Io, dep: *std.Build.Dependency, vt:
const helper =
\\
\\/// pardes (build.zig): `path`, opened for reading only once it is known
- \\/// to be a regular file. Elsewhere than Linux, ghostty's open as it was.
+ \\/// to be a regular file. Elsewhere than Linux, a stat by path first.
\\fn pardesOpenRegular(io: std.Io, path: []const u8) !std.Io.File {
- \\ if (comptime builtin.target.os.tag != .linux) return std.Io.Dir.cwd().openFile(io, path, .{});
+ \\ if (comptime builtin.target.os.tag != .linux) {
+ \\ if ((try std.Io.Dir.cwd().statFile(io, path, .{})).kind != .file) return error.NotRegularFile;
+ \\ return std.Io.Dir.cwd().openFile(io, path, .{});
+ \\ }
\\ const probe = try std.Io.Dir.cwd().openFile(io, path, .{ .path_only = true });
\\ defer probe.close(io);
\\ const stat = try probe.stat(io);