summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 13:21:54 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:24:59 -0300
commitb7fdfb18ffd199d49a254c1c799bc3415ad45ec2 (patch)
tree9e52b7a09c2e939f6efd4765c3e8d97464437a21
parentc37a700474e8b84cc3c7db8bf550b7c5f18b1871 (diff)
downloadpardes-b7fdfb18ffd199d49a254c1c799bc3415ad45ec2.tar.gz
pardes-b7fdfb18ffd199d49a254c1c799bc3415ad45ec2.zip
kinds #24, the addons as build steps: `zig build image` and `zig build pdf` each build their library and install it in <prefix>/lib/pardes/addons (and ~/.local/lib/pardes/addons with the home install), `zig build addons` both, the default install the binaries alone and -Dmupdf gone, MuPDF compiled only for the pdf step and the tests that depend on its artifact as before (fetched at the first configure, which Zig runs alike for every step); install.typ, building.typ, reference.typ, shared-libs.md, the README and the changelog say so
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--README.md2
-rw-r--r--build.zig125
-rw-r--r--docs/shared-libs.md12
-rw-r--r--docs/typ/building.typ10
-rw-r--r--docs/typ/install.typ10
-rw-r--r--docs/typ/reference.typ7
-rw-r--r--src/CHANGELOG.md3
-rw-r--r--test/session.zig4
8 files changed, 91 insertions, 82 deletions
diff --git a/README.md b/README.md
index 81511c11..3152de6a 100644
--- a/README.md
+++ b/README.md
@@ -24,4 +24,4 @@ builds them into one PDF.
Contributors: [building](docs/typ/building.typ).
pardes is under the ISC license ([LICENSE](LICENSE)); the libraries it builds keep
-their own (MuPDF, on by default, is AGPL; `-Dmupdf=false` leaves it out).
+their own (MuPDF, in the PDF addon `zig build pdf` installs, is AGPL).
diff --git a/build.zig b/build.zig
index f275475a..603857e7 100644
--- a/build.zig
+++ b/build.zig
@@ -93,7 +93,6 @@ pub fn build(b: *std.Build) void {
&.{f}
else
&.{};
- const enable_mupdf = b.option(bool, "mupdf", "build the pdf addon, PDF panes over MuPDF (AGPL/commercial; default on; -Dmupdf=false leaves it out)") orelse true;
const enable_jpx = b.option(bool, "jpx", "JPEG 2000 in PDFs, for scanned documents (default on; -Djpx=false drops openjpeg)") orelse true;
const embed_sources = b.option(bool, "embed-sources", "serve the editor's own sources under /src of its 9P tree (default off)") orelse false;
const test_build = b.step("test-build", "compile unit-test programs without running them");
@@ -157,12 +156,6 @@ pub fn build(b: *std.Build) void {
const mupdf_check = b.step("mupdf-check", "the pdf addon's check: MuPDF compiles, links, renders and searches docs/design.pdf, and its script runs");
const pdf_pointer_bench_step = b.step("pdf-pointer-bench", "time PDF hover and selection gestures and prove their pixels (-Doptimize=ReleaseFast -- [--label L] [--reps N] [--path FILE] [--cell WxH])");
const pdf_scroll_bench_step = b.step("pdf-scroll-bench", "benchmark fast continuous-strip PDF scrolling in ReleaseFast (-Doptimize=ReleaseFast -- [--json] [--reps N] [--warmup N] [--path FILE])");
- if (!enable_mupdf)
- mupdf_check.dependOn(&b.addFail("mupdf-check is unavailable with -Dmupdf=false").step);
- if (!enable_mupdf)
- pdf_scroll_bench_step.dependOn(&b.addFail("pdf-scroll-bench is unavailable with -Dmupdf=false").step);
- if (!enable_mupdf)
- pdf_pointer_bench_step.dependOn(&b.addFail("pdf-pointer-bench is unavailable with -Dmupdf=false").step);
const shaders_step = b.step("shaders", "refresh the committed shaders/prebuilt/*.spv (glslc)");
const update_shaders = b.addUpdateSourceFiles();
@@ -471,54 +464,54 @@ pub fn build(b: *std.Build) void {
const zlib = freetype_dep.builder.dependency("zlib", .{ .target = target, .optimize = c_optimize }).artifact("z");
// The PDF addon (addons/pdf/pdf.c over MuPDF and pdf_bridge.c), built
- // and installed as the image addon is. MuPDF is compiled against the
+ // and installed as the image addon is: compiled only for a step that
+ // needs it (`pdf`, the tests), though fetched at the first configure,
+ // which Zig runs alike for every step. MuPDF is compiled against the
// build's FreeType and zlib and links them into the library, which holds
// its own copy of each beside a window's FreeType (docs/shared-libs.md);
// so all three are position-independent, and the library exports its
// `pardes_addon` alone.
var pdf_addon: ?*std.Build.Step.Compile = null;
- if (enable_mupdf) {
- if (b.lazyDependency("mupdf", .{})) |mupdf_dep| {
- freetype.root_module.pic = true;
- zlib.root_module.pic = true;
- const mupdf = mupdf_build.add(b, io, mupdf_dep, .{
- .target = target,
- .optimize = c_optimize,
- .jpx = enable_jpx,
- .freetype = freetype,
- .zlib = zlib,
- .pic = true,
- });
- const lib = b.addLibrary(.{ .name = "pdf", .linkage = .dynamic, .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }) });
- mupdf.linkTo(lib.root_module);
- lib.root_module.addIncludePath(b.path("src/kinds"));
- lib.root_module.addIncludePath(b.path("addons/pdf"));
- lib.root_module.addCSourceFile(.{ .file = b.path("addons/pdf/pdf.c"), .flags = &.{ "-std=gnu11", "-Wall", "-Wextra", "-Werror" } });
- lib.root_module.addCSourceFile(.{ .file = b.path("addons/pdf/pdf_bridge.c"), .flags = &.{"-std=gnu11"} });
- lib.setVersionScript(b.addWriteFiles().add("pdf.map", "{ global: pardes_addon; local: *; };\n"));
- pdf_addon = lib;
- mupdf_check.dependOn(mupdf_build.addProbe(b, mupdf, .{
- .target = target,
- .pdf = b.path("docs/design.pdf"),
- }));
+ if (b.lazyDependency("mupdf", .{})) |mupdf_dep| {
+ freetype.root_module.pic = true;
+ zlib.root_module.pic = true;
+ const mupdf = mupdf_build.add(b, io, mupdf_dep, .{
+ .target = target,
+ .optimize = c_optimize,
+ .jpx = enable_jpx,
+ .freetype = freetype,
+ .zlib = zlib,
+ .pic = true,
+ });
+ const lib = b.addLibrary(.{ .name = "pdf", .linkage = .dynamic, .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }) });
+ mupdf.linkTo(lib.root_module);
+ lib.root_module.addIncludePath(b.path("src/kinds"));
+ lib.root_module.addIncludePath(b.path("addons/pdf"));
+ lib.root_module.addCSourceFile(.{ .file = b.path("addons/pdf/pdf.c"), .flags = &.{ "-std=gnu11", "-Wall", "-Wextra", "-Werror" } });
+ lib.root_module.addCSourceFile(.{ .file = b.path("addons/pdf/pdf_bridge.c"), .flags = &.{"-std=gnu11"} });
+ lib.setVersionScript(b.addWriteFiles().add("pdf.map", "{ global: pardes_addon; local: *; };\n"));
+ pdf_addon = lib;
+ mupdf_check.dependOn(mupdf_build.addProbe(b, mupdf, .{
+ .target = target,
+ .pdf = b.path("docs/design.pdf"),
+ }));
- // The PDF benches: the core over the addon, a pane of it.
- const config = b.addOptions();
- config.addOption(bool, "release_fast_core", optimize == .fast);
- config.addOption([]const u8, "core_optimize", @tagName(optimize));
- config.addOptionPath("pdf_addon", lib.getEmittedBin());
- for ([_]struct { step: *std.Build.Step, exe: []const u8, file: []const u8, optimize: std.lang.Optimize }{
- .{ .step = pdf_pointer_bench_step, .exe = "pardes-pdf-pointer-bench", .file = "test/pdf_pointer_bench.zig", .optimize = .fast },
- .{ .step = pdf_scroll_bench_step, .exe = "pardes-pdf-scroll-bench", .file = "test/pdf_scroll_bench.zig", .optimize = optimize },
- }) |bench| {
- const exe = b.addExecutable(.{ .name = bench.exe, .root_module = b.createModule(.{ .target = target, .optimize = bench.optimize, .root_source_file = b.path(bench.file), .link_libc = true }) });
- exe.root_module.addImport("pardes", core_module);
- exe.root_module.addOptions("pdf_bench_config", config);
- const run = b.addRunArtifact(exe);
- run.addPassthruArgs();
- run.setCwd(b.path("."));
- bench.step.dependOn(&run.step);
- }
+ // The PDF benches: the core over the addon, a pane of it.
+ const config = b.addOptions();
+ config.addOption(bool, "release_fast_core", optimize == .fast);
+ config.addOption([]const u8, "core_optimize", @tagName(optimize));
+ config.addOptionPath("pdf_addon", lib.getEmittedBin());
+ for ([_]struct { step: *std.Build.Step, exe: []const u8, file: []const u8, optimize: std.lang.Optimize }{
+ .{ .step = pdf_pointer_bench_step, .exe = "pardes-pdf-pointer-bench", .file = "test/pdf_pointer_bench.zig", .optimize = .fast },
+ .{ .step = pdf_scroll_bench_step, .exe = "pardes-pdf-scroll-bench", .file = "test/pdf_scroll_bench.zig", .optimize = optimize },
+ }) |bench| {
+ const exe = b.addExecutable(.{ .name = bench.exe, .root_module = b.createModule(.{ .target = target, .optimize = bench.optimize, .root_source_file = b.path(bench.file), .link_libc = true }) });
+ exe.root_module.addImport("pardes", core_module);
+ exe.root_module.addOptions("pdf_bench_config", config);
+ const run = b.addRunArtifact(exe);
+ run.addPassthruArgs();
+ run.setCwd(b.path("."));
+ bench.step.dependOn(&run.step);
}
}
@@ -1123,17 +1116,23 @@ pub fn build(b: *std.Build) void {
.root_module = root_mod,
});
installHome(b, exe, home_bin);
- if (target.result.os.tag == .linux and !static) {
- for ([_]?*std.Build.Step.Compile{ image_addon, pdf_addon }, [_][]const u8{ "image.so", "pdf.so" }) |lib, name| if (lib) |l| {
- b.getInstallStep().dependOn(&b.addInstallFileWithDir(l.getEmittedBin(), .lib, b.fmt("pardes/addons/{s}", .{name})).step);
- if (home_bin) |dir| {
- const copy = b.addSystemCommand(&.{ "install", "-Dm755" });
- copy.addFileArg(l.getEmittedBin());
- copy.addArg(b.pathJoin(&.{ dir, "..", "lib", "pardes", "addons", name }));
- copy.has_side_effects = true;
- b.getInstallStep().dependOn(&copy.step);
- }
- };
+ // The addons, a step each: the default install is the binaries
+ // alone, and `zig build image pdf` (or `addons`) puts the libraries
+ // where the start scan finds them, <prefix>/lib/pardes/addons (and
+ // ~/.local/lib/pardes/addons with the home install).
+ const addons_step = b.step("addons", "install the image and pdf addons");
+ for ([_]?*std.Build.Step.Compile{ image_addon, pdf_addon }, [_][]const u8{ "image", "pdf" }) |lib, name| {
+ const step = b.step(name, b.fmt("install the {s} addon, <prefix>/lib/pardes/addons/{s}.so", .{ name, name }));
+ addons_step.dependOn(step);
+ const l = lib orelse continue;
+ step.dependOn(&b.addInstallFileWithDir(l.getEmittedBin(), .lib, b.fmt("pardes/addons/{s}.so", .{name})).step);
+ if (home_bin) |dir| {
+ const copy = b.addSystemCommand(&.{ "install", "-Dm755" });
+ copy.addFileArg(l.getEmittedBin());
+ copy.addArg(b.pathJoin(&.{ dir, "..", "lib", "pardes", "addons", b.fmt("{s}.so", .{name}) }));
+ copy.has_side_effects = true;
+ step.dependOn(&copy.step);
+ }
}
if (gui_mod) |gm| {
var gui_name: []const u8 = "pardes-gui";
@@ -1237,8 +1236,6 @@ pub fn build(b: *std.Build) void {
run_pdf_harness.addArtifactArg(pdf_addon.?);
run_pdf_harness.has_side_effects = true;
pdf_harness_step.dependOn(&run_pdf_harness.step);
- } else {
- pdf_harness_step.dependOn(&b.addFail("pdf-harness is unavailable with -Dmupdf=false").step);
}
const hxdiff = b.addExecutable(.{
@@ -1358,8 +1355,8 @@ pub fn build(b: *std.Build) void {
.terminal_optimize = @tagName(ghostty_optimize),
.platform = @tagName(platform),
.grammars = @tagName(tree_sitter_grammars),
- .mupdf = enable_mupdf,
- .jpx = enable_mupdf and enable_jpx,
+ .mupdf = pdf_addon != null,
+ .jpx = enable_jpx,
.tracy = tracy != null,
.terminal_simd = ghostty_simd,
.prebuilt_shaders = platform == .gui and prebuilt_shaders,
diff --git a/docs/shared-libs.md b/docs/shared-libs.md
index 52457bf1..e730efbd 100644
--- a/docs/shared-libs.md
+++ b/docs/shared-libs.md
@@ -21,6 +21,14 @@ a second FreeType (tools/shared_libs_check.zig). It counts static functions
too, and several functions per family, because a release build inlines some
of them.
+## The addons are build steps (2026-11-06)
+
+The default install is the binaries alone: `zig build image`, `zig build
+pdf` (or `zig build addons`, both) builds and installs each library in
+`<prefix>/lib/pardes/addons` (and `~/.local/lib/pardes/addons` with the
+home install). MuPDF is compiled only for a step that needs it (`pdf`, the
+tests); `-Dmupdf` is gone.
+
## PDF panes became an addon (2026-11-06)
`lib/pardes/addons/pdf.so` (addons/pdf/pdf.c and pdf_bridge.c) holds MuPDF,
@@ -107,8 +115,8 @@ Text section: tty 61,369,343 → 61,294,855 bytes (**−74,488**); gui
- **Two JPEG decoders: MuPDF's libjpeg and wuffs.** MuPDF's `DCTDecode` filter
(`filter-dct.c`) is written against libjpeg's streaming source-manager API.
Moving PDFs onto wuffs means a new DCT filter for fitz. Moving image panes
- onto libjpeg instead would leave a `-Dmupdf=false` build with no JPEG
- decoder.
+ onto libjpeg instead would leave a pardes without the PDF addon with no
+ JPEG decoder.
- **MuPDF's fitz image loaders** (`fz_load_png`, `_jpeg`, `_gif`, `_bmp`,
`_tiff`, `_pnm`, `_psd`; 16.7 KiB together). They are compiled because
mupdf.zig builds all of `source/fitz`. They are reachable only through
diff --git a/docs/typ/building.typ b/docs/typ/building.typ
index 50b85986..311d98c0 100644
--- a/docs/typ/building.typ
+++ b/docs/typ/building.typ
@@ -11,10 +11,11 @@ pieces fit. To install it, see #doc("setup", section: "install").
Zig *0.17.0* (`build.zig.zon` pins `minimum_zig_version`). Dependencies are
fetched and pinned by the manifest; the terminal build needs no system
-package. The SDL shell builds SDL3 and FreeType from source. PDF support
-is an addon, `pdf.so`, built over MuPDF (its own FreeType and zlib in it)
-and on by default (`-Dmupdf=false` leaves it out); the binaries hold no
-MuPDF.
+package. The SDL shell builds SDL3 and FreeType from source. Pictures and
+PDFs are addons, each its own step: `zig build image`, `zig build pdf`
+(`pdf.so`, over MuPDF, its own FreeType and zlib in it), or `zig build
+addons` for both; the binaries hold neither, and MuPDF is compiled only
+for the `pdf` step and the tests.
#pairs(
[`zig build`], [the terminal shell and the SDL window together, *installed into `~/.local/bin`* (`pardes` and `pardes-gui`)],
@@ -40,7 +41,6 @@ must share with its session; `pardes --help` lists every flag.
#pairs(
[`-Dplatform`], [`tui`, `gui`, `macos`; absent: the tui and SDL shells together, installed into `~/.local`],
[`-Dstatic`], [bool, `false`],
- [`-Dmupdf`], [bool, `true`: build and install the PDF addon],
[`-Djpx`], [bool, `true`: JPEG 2000, and with it scanned PDFs],
[`-Dtree-sitter`], [`disabled`, `zig`, `minimal`, `full`; `full`],
[`-Dembed-sources`], [bool, `false`: serve the sources under #file("/src")],
diff --git a/docs/typ/install.typ b/docs/typ/install.typ
index 6b7c2d34..28ed67c8 100644
--- a/docs/typ/install.typ
+++ b/docs/typ/install.typ
@@ -22,9 +22,9 @@ With Zig 0.17 (the build fetches everything else; once that is
downloaded, a first build from a clean cache took 62 seconds on 16 cores):
#cmd("# pardes, in a terminal\nzig build -Dplatform=tui --prefix ~/.local")
#cmd("# pardes-gui, its own window\nzig build -Dplatform=gui --prefix ~/.local")
-Then run `pardes` or `pardes FILE`. Each also installs
+#cmd("# the image and PDF addons (or `zig build image pdf`)\nzig build addons -Dplatform=tui --prefix ~/.local")
+Then run `pardes` or `pardes FILE`. The addons are steps of their own:
`lib/pardes/addons/image.so`, the image addon, and
-`lib/pardes/addons/pdf.so`, the PDF addon (MuPDF, left out by
-`-Dmupdf=false`), which pardes loads at start from its prefix: a pardes
-without them (a downloaded binary alone) shows image files and PDFs as
-text.
+`lib/pardes/addons/pdf.so`, the PDF addon (over MuPDF), which pardes
+loads at start from its prefix; a pardes without them (a downloaded binary
+alone) shows image files and PDFs as text.
diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ
index 20c3bf06..ff035fac 100644
--- a/docs/typ/reference.typ
+++ b/docs/typ/reference.typ
@@ -983,11 +983,12 @@ Exec, a message, a new text pane, its selection) it is handed at load.
`addons/fake/fake.c` uses every function and `addons/snake/snake.c` is a
game in it; a kind with only a head and `paint` is a valid one. Pictures
are an addon too, `addons/image/image.c` (PNG, JPEG, GIF, BMP, PPM, PGM and
-TGA through stb_image, at most 1280 pixels a side), which the build
+TGA through stb_image, at most 1280 pixels a side), which `zig build image`
installs as `<prefix>/lib/pardes/addons/image.so`, and so are PDFs,
`addons/pdf/pdf.c` over MuPDF (its pages rendered on jobs, two at once),
-installed as `<prefix>/lib/pardes/addons/pdf.so` (none with
-`-Dmupdf=false`); without them an image file and a PDF open as text. A
+which `zig build pdf` installs as `<prefix>/lib/pardes/addons/pdf.so`
+(`zig build addons`, both); without them an image file and a PDF open as
+text. A
PDF on a terminal without graphics shows its page's text layer, the moving
keys and the wheel a page a step; with them its pages, a fast scroll
rendering only the rows each page shows until it rests, a touchpad's turn
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index 30ee23cc..1ce7a3bf 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -2,6 +2,9 @@
## Unreleased
+- The addons are build steps: `zig build image`, `zig build pdf`, or
+ `zig build addons` for both, install them in `lib/pardes/addons`; the
+ default install is the binaries alone, and `-Dmupdf` is gone.
- `Plumb`: rules of your own for what a `Look` opens, one a line in
plumb(6)'s order, `Plumb suffix .svg to image`, `Plumb prefix gopher://
to url`; tried before the built-in ones, the first that matches wins.
diff --git a/test/session.zig b/test/session.zig
index d5f5cae8..7399ab0f 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -403,8 +403,8 @@ pub const Session = struct {
// pdf:
- /// The pdf addon (addons/pdf/pdf.c), as the build makes it; a build
- /// without it (-Dmupdf=false) has none.
+ /// The pdf addon (addons/pdf/pdf.c), as the build makes it; none
+ /// before the build has fetched MuPDF.
pub const pdf_addon: ?[]const u8 = if (@import("session_options").has_pdf_addon) @import("session_options").pdf_addon else null;
/// The pdf addon loaded into the session, once: a test of a PDF in a