diff options
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 125 |
1 files changed, 61 insertions, 64 deletions
@@ -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(©.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(©.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, |
