summaryrefslogtreecommitdiff
path: root/src/Addon.zig
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/Addon.zig
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/Addon.zig')
-rw-r--r--src/Addon.zig21
1 files changed, 19 insertions, 2 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);