diff options
| -rw-r--r-- | build.zig | 19 | ||||
| -rw-r--r-- | docs/typ/building.typ | 6 | ||||
| -rw-r--r-- | src/Addon.zig | 10 | ||||
| -rw-r--r-- | src/macos.zig | 2 |
4 files changed, 26 insertions, 11 deletions
@@ -149,6 +149,7 @@ pub fn build(b: *std.Build) void { const c_optimize: std.lang.Optimize = if (optimize == .debug) .fast else optimize; const tree_sitter_grammars = b.option(TreeSitterGrammars, "tree-sitter", "tree-sitter grammar set: disabled, zig, minimal (c/c++/zig), full") orelse .full; const tracy = b.option([]const u8, "tracy", "enable Tracy profiling; supply the path to a Tracy source checkout"); + const macos_sdk = b.option([]const u8, "macos-sdk", "the macOS SDK a gui built for macOS from another system takes SDL's headers and frameworks from"); const macos_identity = b.option([]const u8, "macos-identity", "codesigning identity for pardes.app (default: ad-hoc)") orelse "-"; const prebuilt_shaders = b.option(bool, "prebuilt-shaders", "embed the committed shaders/prebuilt/*.spv instead of running glslc (default: on for a bare `zig build`, off when -Dplatform names a shell)") orelse also_gui; @@ -235,6 +236,10 @@ pub fn build(b: *std.Build) void { const cloud9 = b.dependency("cloud9", .{ .target = target, .optimize = optimize }).module("cloud9"); for (core_mods) |mod| mod.addImport("cloud9", cloud9); const core_shells = core_shells_buf[0..core_mods_len]; + // The modules the addons are compiled into (Addon.zig reads their + // `pardes_addon`): the static step's, and every one for a system + // Addon.zig's loader, over a Linux memfd, does not run on. + const builtin_mods: []const *std.Build.Module = if (target.result.os.tag != .linux) core_mods else if (static_mod) |m| b.allocator.dupe(*std.Build.Module, &.{m}) catch @panic("OOM") else &.{}; // The conditional dependencies, hoisted so one `wireCore` call at the end // can name them all. The unconditional ones are ordinary consts below. @@ -513,9 +518,9 @@ pub fn build(b: *std.Build) void { const lib = b.addLibrary(.{ .name = "pdf", .linkage = .dynamic, .root_module = pdf_mod }); lib.setVersionScript(b.addWriteFiles().add("pdf.map", "{ global: pardes_addon; local: *; };\n")); pdf_addon = lib; - // ...and for a static pardes the same module compiled into it, - // which exports nothing there (Addon.zig reads its declaration). - if (static_mod) |m| m.addImport("pdf_addon", pdf_mod); + // ...and the same module compiled into a pardes, which exports + // nothing there (addon.exportLib). + for (builtin_mods) |m| m.addImport("pdf_addon", pdf_mod); mupdf_check.dependOn(mupdf_build.addProbe(b, mupdf, .{ .target = target, .pdf = b.path("docs/design.pdf"), @@ -849,7 +854,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 (builtin_mods) |m| m.addImport("image_addon", image_mod); for (core_mods) |m| wireCore(m, .{ .kind = kind_mod, .themes = themes_mod, @@ -880,7 +885,7 @@ pub fn build(b: *std.Build) void { 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); + mod.addOptions("builtin_addons", if (std.mem.indexOfScalar(*std.Build.Module, builtin_mods, mod) != null) builtin_on else builtin_off); } // docs/typ/builtins-<platform>.json: every builtin, from the registry and the Help @@ -909,7 +914,9 @@ pub fn build(b: *std.Build) void { // The static step's gui module is a gui shell too. const gui_shell_mods: [2]?*std.Build.Module = .{ gui_shell_mod, if (platform == .gui) static_mod else null }; for (gui_shell_mods) |gui_shell_entry| if (gui_shell_entry) |gm| { - const sdl_dep = b.lazyDependency("sdl", .{ .target = target, .optimize = optimize, .sanitize_c = .off, .preferred_linkage = .static }); + // SDL's build asks a cross build for macOS for the SDK's paths. + const sdk: ?std.Build.LazyPath = if (macos_sdk) |p| .{ .cwd_relative = p } else null; + const sdl_dep = b.lazyDependency("sdl", .{ .target = target, .optimize = optimize, .sanitize_c = .off, .preferred_linkage = .static, .system_include_path = if (sdk) |p| p.path(b, "usr/include") else null, .system_framework_path = if (sdk) |p| p.path(b, "System/Library/Frameworks") else null, .library_path = if (sdk) |p| p.path(b, "usr/lib") else null }); if (sdl_dep) |dep| { const sdl_lib = dep.artifact("SDL3"); // SDL's own stb_image (SDL_stb.c, for SDL_LoadPNG and a camera's diff --git a/docs/typ/building.typ b/docs/typ/building.typ index 61641cba..41fadbb2 100644 --- a/docs/typ/building.typ +++ b/docs/typ/building.typ @@ -33,6 +33,11 @@ MuPDF is compiled only for the steps and tests that use `pdf.so`. [`zig build static -Dplatform=gui`], [`pardes-gui` with the two addons compiled in, linked dynamically (SDL and the GPU take the display's libraries)], ) +Off Linux the addons are always compiled in, as in a static build: +`Addon.zig` loads a library through a Linux memfd, and `Addon load` +elsewhere says `not on this platform`. A gui for macOS built on another +system takes the SDK SDL needs with `-Dmacos-sdk=<path>`. + A bare `zig build` installs into the prefix (`zig-out`, or `--prefix <dir>`) and copies the binaries into `~/.local/bin`; `-Dhome-install=false` leaves that copy out. Zig 0.17 keeps the prefix from the build script, so @@ -57,6 +62,7 @@ must share with its session; `pardes --help` lists every flag. [`-Dstamp-commit`], [bool: the git commit in `--version` and crash records; on for release builds and the `~/.local` install], [`-Dtheme-animation`], [bool, `true`], [`-Dworkspace-tag`], [bool: draw the workspace tag row; on except for macOS, whose menu bar carries it], + [`-Dmacos-sdk`], [path: the macOS SDK SDL's headers and frameworks come from, for a gui built for macOS elsewhere], [`-Dprebuilt-shaders`], [bool: embed the committed SPIR-V; on for a bare `zig build`, off with `-Dplatform`; `zig build shaders` refreshes it with glslc], [`-Dtracy`], [path to a Tracy checkout; off], [`-Dmacos-identity`], [codesigning identity for `pardes.app`; `-` (ad hoc)], diff --git a/src/Addon.zig b/src/Addon.zig index d39a27f3..67939f57 100644 --- a/src/Addon.zig +++ b/src/Addon.zig @@ -112,7 +112,7 @@ fn read(data: []const u8, path: []const u8, words: *[64]LoadedWord, why: *Why) L /// (dlopen hands back the handle it has for a path it has), unless this /// process holds those very bytes already. fn hold(path: []const u8, hash: *[32]u8, why: *Why) ?*Lib { - if (comptime compiled_in.len > 0) return failNull(why, "not on this platform: its addons are compiled in", .{}); + if (comptime compiled_in.len > 0 or @import("builtin").os.tag != .linux) return failNull(why, "not on this platform: its addons are compiled in", .{}); var z: [4096]u8 = undefined; const path_z = std.fmt.bufPrintSentinel(&z, "{s}", .{path}, 0) catch return failNull(why, "the path is too long", .{}); const f = std.c.fopen(path_z, "r") orelse return failNull(why, "cannot read it", .{}); @@ -175,10 +175,10 @@ var found_words: [Kind.max_kinds][64]LoadedWord = undefined; var found_text: [Kind.max_kinds][2][4096]u8 = undefined; var nfound: usize = 0; -/// A static pardes's addons (`zig build static`), compiled in: the image -/// and pdf modules' `pardes_addon` declarations, which only a library -/// exports. A static binary cannot dlopen, and macOS's loader has no -/// memfd: this is how either has image and PDF panes. +/// The addons compiled in (`zig build static`, and any build off Linux): +/// the image and pdf modules' `pardes_addon` declarations, which only a +/// library exports. A static binary cannot dlopen, and the loader below +/// is Linux's (a 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, &@import("pdf_addon").pardes_addon } else &.{}; /// The addons compiled in, as if loaded (`builtin` their path); else every diff --git a/src/macos.zig b/src/macos.zig index 7b996ca3..9a734bcc 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -512,6 +512,8 @@ fn initCore(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) !void { pardes.TerminalImages.start(io, allocs.image); pardes.Kind.heap = allocs.addon; + // Its addons are compiled in (no loader runs here): image and PDF panes. + opts.addons = pardes.Addon.scan(); errdefer pardes.TerminalImages.stop(); pardes.syntax.start(allocs.tree_sitter); errdefer pardes.syntax.stop(); |
