diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 13:39:00 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 14:24:59 -0300 |
| commit | 31706a1d1c13c26c69f67f107b72179019cbd255 (patch) | |
| tree | 9cb7ee1e529155d4a80c9409fd1104130588647e /build.zig | |
| parent | 0f81de017ca7b52e951bb70f6f5f3e8c88b425e6 (diff) | |
| download | pardes-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 'build.zig')
| -rw-r--r-- | build.zig | 44 |
1 files changed, 38 insertions, 6 deletions
@@ -86,7 +86,6 @@ pub fn build(b: *std.Build) void { }, }); const optimize = b.standardOptimizeOption(.{}); - const static = b.option(bool, "static", "statically link") orelse false; // one substring, because that is what a dev loop needs: see the unit-test // step for why the whole-binary run is worth narrowing const test_filters: []const []const u8 = if (b.option([]const u8, "test-filter", "run only tests whose name contains this")) |f| @@ -195,6 +194,15 @@ pub fn build(b: *std.Build) void { .link_libc = true, }) else null; + // `zig build static`'s: the terminal's, the addons compiled in + // (Addon.zig); musl's alone, as glibc links only dynamically. + const static_mod: ?*std.Build.Module = if (platform == .tui and target.result.isMuslLibC()) b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("src/main.zig"), + .link_libc = true, + }) else null; + const gui_mod: ?*std.Build.Module = if (also_gui) b.createModule(.{ .target = target, .optimize = optimize, @@ -203,8 +211,8 @@ pub fn build(b: *std.Build) void { }) else null; const CoreMod = struct { mod: ?*std.Build.Module, shell: Platform }; - var core_mods_buf: [4]*std.Build.Module = undefined; - var core_shells_buf: [4]Platform = undefined; + var core_mods_buf: [5]*std.Build.Module = undefined; + var core_shells_buf: [5]Platform = undefined; var core_mods_len: usize = 0; // root_mod FIRST: the module map below is folded out of its import table. for ([_]CoreMod{ @@ -213,6 +221,7 @@ pub fn build(b: *std.Build) void { // configuration compiled two more ways, not two more frontends. .{ .mod = core_module, .shell = platform }, .{ .mod = isolated_mod, .shell = platform }, + .{ .mod = static_mod, .shell = platform }, .{ .mod = gui_mod, .shell = .gui }, }) |entry| if (entry.mod) |m| { core_mods_buf[core_mods_len] = m; @@ -483,6 +492,17 @@ pub fn build(b: *std.Build) void { 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; + // ...and for a static pardes the same C compiled into it, its + // export renamed: it is one of two in a binary (Addon.zig). + if (static_mod) |m| { + const in = b.addLibrary(.{ .name = "pdf-builtin", .linkage = .static, .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }) }); + mupdf.linkTo(in.root_module); + in.root_module.addIncludePath(b.path("src/kinds")); + in.root_module.addIncludePath(b.path("addons/pdf")); + in.root_module.addCSourceFile(.{ .file = b.path("addons/pdf/pdf.c"), .flags = &.{ "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-Dpardes_addon=pardes_addon_pdf" } }); + in.root_module.addCSourceFile(.{ .file = b.path("addons/pdf/pdf_bridge.c"), .flags = &.{"-std=gnu11"} }); + m.linkLibrary(in); + } mupdf_check.dependOn(mupdf_build.addProbe(b, mupdf, .{ .target = target, .pdf = b.path("docs/design.pdf"), @@ -818,6 +838,7 @@ pub fn build(b: *std.Build) void { image_mod.addIncludePath(zstbi_dep.path("libs/stbi")); image_mod.addCSourceFile(.{ .file = b.path("addons/image/stb.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } }); const image_addon = b.addLibrary(.{ .name = "image", .linkage = .dynamic, .root_module = image_mod }); + if (static_mod) |m| m.addImport("image_addon", image_mod); for (core_mods) |m| wireCore(m, .{ .kind = kind_mod, .themes = themes_mod, @@ -838,12 +859,17 @@ pub fn build(b: *std.Build) void { iso_off.addOption(bool, "isolated", false); const iso_on = b.addOptions(); iso_on.addOption(bool, "isolated", true); + const builtin_off = b.addOptions(); + builtin_off.addOption(bool, "on", false); + const builtin_on = b.addOptions(); + builtin_on.addOption(bool, "on", true); for (core_mods, core_shells) |mod, shell| { // config.zig's test checks the words and keys docs/typ names exist. mod.addOptions("doc_typ", doc_typ_opts); mod.addOptions("pardes_config", if (also_gui and shell == .gui) gui_opts.? else opts); mod.addOptions("pardes_isolation", if (isolated_mod == mod) iso_on else iso_off); + mod.addOptions("builtin_addons", if (static_mod == mod) builtin_on else builtin_off); } // docs/typ/builtins-<platform>.json: every builtin, from the registry and the Help @@ -1113,7 +1139,6 @@ pub fn build(b: *std.Build) void { exe_name = b.fmt("{s}-{s}-{s}", .{ exe_name, @tagName(target.result.os.tag), @tagName(target.result.cpu.arch) }); const exe = b.addExecutable(.{ .name = exe_name, - .linkage = if (static) .static else null, .root_module = root_mod, }); installHome(b, exe, home_bin); @@ -1141,17 +1166,24 @@ pub fn build(b: *std.Build) void { gui_name = b.fmt("{s}-{s}-{s}", .{ gui_name, @tagName(target.result.os.tag), @tagName(target.result.cpu.arch) }); const gui_exe = b.addExecutable(.{ .name = gui_name, - .linkage = if (static) .static else null, .root_module = gm, }); installHome(b, gui_exe, home_bin); } + // One static pardes, never the default: the terminal's, both + // addons compiled in and registered at start as if loaded. It is + // also how a build for macOS, whose loader has no memfd, could have + // image and PDF panes. + const static_step = b.step("static", "a static pardes with the image and pdf addons in it (-Dplatform=tui -Dtarget=x86_64-linux-musl)"); + if (static_mod) |m| + static_step.dependOn(&b.addInstallArtifact(b.addExecutable(.{ .name = "pardes", .linkage = .static, .root_module = m }), .{}).step) + else + static_step.dependOn(&b.addFail("static is the terminal's and musl's: -Dplatform=tui -Dtarget=x86_64-linux-musl").step); const run = b.addRunArtifact(exe); b.step("run", "descend to the pardes").dependOn(&run.step); if (isolated_mod) |iso| { const iso_exe = b.addExecutable(.{ .name = "pardes-isolate", - .linkage = if (static) .static else null, .root_module = iso, }); const run_iso = b.addRunArtifact(iso_exe); |
