summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 13:39:00 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:24:59 -0300
commit31706a1d1c13c26c69f67f107b72179019cbd255 (patch)
tree9cb7ee1e529155d4a80c9409fd1104130588647e /src
parent0f81de017ca7b52e951bb70f6f5f3e8c88b425e6 (diff)
downloadpardes-31706a1d1c13c26c69f67f107b72179019cbd255.tar.gz
pardes-31706a1d1c13c26c69f67f107b72179019cbd255.zip
kinds #26, one static pardes: `zig build static -Dplatform=tui -Dtarget=x86_64-linux-musl` (musl's, as glibc links only dynamically; never the default, and -Dstatic gone) links the terminal binary statically with both addons compiled in, image.zig as a module and pdf.c with MuPDF, its export renamed by a -D, which Addon.zig registers at start as if loaded (/addons says builtin, Addon reload refuses one, no library is scanned), and execveat and close_range go by their syscalls, which musl has no wrappers for; macOS's way to image and PDF panes too, say a comment, building.typ, shared-libs.md and the changelog
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
-rw-r--r--src/Addon.zig21
-rw-r--r--src/CHANGELOG.md4
-rw-r--r--src/daemon.zig4
-rw-r--r--src/upgrade.zig10
4 files changed, 31 insertions, 8 deletions
diff --git a/src/Addon.zig b/src/Addon.zig
index c6dca34b..5219f2b1 100644
--- a/src/Addon.zig
+++ b/src/Addon.zig
@@ -174,9 +174,25 @@ var found_words: [Kind.max_kinds][64]LoadedWord = undefined;
var found_text: [Kind.max_kinds][2][4096]u8 = undefined;
var nfound: usize = 0;
-/// Every library of the two directories, in name order each, the user's
-/// first. A library that crashed at its last load is listed, not loaded.
+/// A static pardes's addons (`zig build static`), compiled in: the image
+/// addon's module and the PDF's C, its `pardes_addon` renamed. A static
+/// binary cannot dlopen, and macOS's loader has no memfd: this is how
+/// either has image and PDF panes.
+const compiled_in: []const *const Kind.Ops = if (@import("builtin_addons").on) &.{ &@import("image_addon").pardes_addon, &pardes_addon_pdf } else &.{};
+extern const pardes_addon_pdf: Kind.Ops;
+
+/// The addons compiled in, as if loaded (`builtin` their path); else every
+/// library of the two directories, in name order each, the user's first. A
+/// library that crashed at its last load is listed, not loaded.
pub fn scan() []const Loaded {
+ for (compiled_in) |ops| {
+ found[nfound] = loadedOf(ops, "builtin", @splat(0), &found_words[nfound]);
+ if (ops.init) |init| if (init(&Kind.api) != Kind.c.PA_OK) {
+ found[nfound].why = "refused: its init failed";
+ };
+ nfound += 1;
+ }
+ if (compiled_in.len > 0) return found[0..nfound];
var data_buf: [4096]u8 = undefined;
const data = dataDir(&data_buf);
const crashed = crashedPath(data);
@@ -491,6 +507,7 @@ pub fn run(p: *Pardes, id: usize, arg: ?[]const u8) void {
}
const k = p.kinds.byName(rest) orelse return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon {t}: no addon brought kind {s}", .{ op, rest }) catch takes);
const e = &p.kinds.kinds[k];
+ if (op == .reload and std.mem.eql(u8, e.path.slice(), "builtin")) return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon reload: {s} is built into this pardes", .{rest}) catch takes);
if (op == .reload) return p.emit(.{ .addon = .{ .op = .reload, .pane = @intCast(id), .arg = .from(e.path.slice()) } });
const n = openPanes(p, rest);
if (n > 0) return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon unload: {d} {s} pane{s} open", .{ n, rest, if (n == 1) " is" else "s are" }) catch takes);
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index fb47ac8e..c465032d 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -2,6 +2,10 @@
## Unreleased
+- `zig build static -Dplatform=tui -Dtarget=x86_64-linux-musl`: one
+ statically linked `pardes` with the image and PDF addons compiled in
+ (`/addons` lists them `builtin`; `Addon reload` refuses them). It
+ replaces `-Dstatic`, which glibc refused (it links only dynamically).
- Addons in Zig: `src/kinds/addon.zig` (over the same header, nothing of
the core) makes a kind's `pa_ops` from a struct of its functions, with
the pane's arena as an Allocator, typed keys, a window to `put` text in,
diff --git a/src/daemon.zig b/src/daemon.zig
index bc9e9773..6c0a0adf 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -247,7 +247,9 @@ fn spawn(listener: c_int, lock: c_int) bool {
const l = libc.fcntl(listener, libc.F.DUPFD, @as(c_int, 10));
const k = libc.fcntl(lock, libc.F.DUPFD, @as(c_int, 10));
if (l < 0 or k < 0 or libc.dup2(l, 3) < 0 or libc.dup2(k, 4) < 0) libc._exit(127);
- if (close_range(5, std.math.maxInt(c_uint), 0) != 0) {
+ // Linux's by its syscall: musl (a static pardes) has no close_range.
+ const shut = if (comptime builtin.os.tag == .linux) std.os.linux.close_range(5, std.math.maxInt(i32), .{ .UNSHARE = false, .CLOEXEC = false }) == 0 else close_range(5, std.math.maxInt(c_uint), 0) == 0;
+ if (!shut) {
var fd: c_int = 5;
while (fd < 1024) : (fd += 1) _ = libc.close(fd);
}
diff --git a/src/upgrade.zig b/src/upgrade.zig
index 7819f216..97d3be4f 100644
--- a/src/upgrade.zig
+++ b/src/upgrade.zig
@@ -322,13 +322,13 @@ pub fn exec(gpa: std.mem.Allocator, path: ?[:0]const u8, old: c_int, rec: *const
for (given, argv[2..]) |a, *slot| slot.* = a.ptr;
rec.closeOnExec(false);
const envp: [*:null]const ?[*:0]const u8 = @ptrCast(libc.environ);
- const r = if (path) |p|
- libc.execve(p, argv.ptr, envp)
+ // execveat by its syscall: musl (a static pardes) has no wrapper.
+ const e = if (path) |p|
+ libc.errno(libc.execve(p, argv.ptr, envp))
else if (comptime builtin.os.tag == .linux)
- libc.execveat(old, "", argv.ptr, envp, .{ .SYMLINK_NOFOLLOW = false, .EMPTY_PATH = true })
+ std.os.linux.errno(std.os.linux.execveat(old, "", argv.ptr, envp, .{ .SYMLINK_NOFOLLOW = false, .EMPTY_PATH = true }))
else
- -1;
- const e = libc.errno(r);
+ libc.errno(@as(c_int, -1));
rec.closeOnExec(true);
return switch (e) {
.NOENT => "it is not there",