diff options
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -911,6 +911,34 @@ pub fn build(b: *std.Build) void { // override uucode on vaxis LAST so it wins over ghostty's build() wiring. vaxis_mod.addImport("uucode", uucode_mod); + // One PNG and one JPEG decoder (docs/shared-libs.md): ghostty's, wuffs, + // which ghostty-vt links for kitty graphics whatever pardes does (its + // decoders stay in through wuffs's function tables). Where it is in the + // build, image.zig decodes PNG and JPEG through it, and stb_image is + // compiled without them, so without the inflate only its PNG used. Its + // writer goes too, and the deflate it carries: pardes writes no image + // through stb. A fresh fetch keeps both: the flags and the patch are + // applied here, at build time. + const wuffs_mod: ?*std.Build.Module = if (ghostty_core_vt) |vt| vt.import_table.get("wuffs") else null; + for ([_]?*std.Build.Step.Options{ opts, gui_opts }) |o| if (o) |x| x.addOption(bool, "wuffs_images", wuffs_mod != null); + if (wuffs_mod != null) if (zstbi_dep) |dep| { + var sources: usize = 0; + for (zstbi_mod.link_objects.items) |obj| switch (obj) { + .c_source_file => |csf| { + sources += 1; + const src = configureRead(b, io, dep.builder.root, "src/zstbi.c", 1 << 20) catch @panic("read zstbi.c"); + const writer = "#define STB_IMAGE_WRITE_IMPLEMENTATION\n#include \"stb_image_write.h\"\n"; + if (std.mem.count(u8, src, writer) != 1) std.debug.panic("zstbi.c changed at `{s}`: redo its patch in build.zig", .{writer}); + // zstbi.deinit still resets the writer's flip flag. + const patched = std.mem.replaceOwned(u8, b.allocator, src, writer, "void stbi_flip_vertically_on_write(int flag) { (void)flag; }\n") catch @panic("OOM"); + csf.file = b.addWriteFiles().add("zstbi.c", patched); + csf.flags = std.mem.concat(b.allocator, []const u8, &.{ csf.flags, &.{ "-DSTBI_NO_PNG", "-DSTBI_NO_JPEG" } }) catch @panic("OOM"); + }, + else => {}, + }; + if (sources != 1) @panic("zstbi's build no longer compiles one C file: redo its patch in build.zig"); + }; + // One call per module instead of one line per module per dependency, and // BEFORE the fold below, which reads what these imports put in the table. for (core_mods) |m| wireCore(m, .{ @@ -925,6 +953,7 @@ pub fn build(b: *std.Build) void { .ghostty_vt = ghostty_core_vt, .vaxis = vaxis_mod, .uucode = uucode_mod, + .wuffs = wuffs_mod, }); const iso_off = b.addOptions(); @@ -973,6 +1002,10 @@ pub fn build(b: *std.Build) void { const sdl_dep = b.lazyDependency("sdl", .{ .target = target, .optimize = optimize, .sanitize_c = .off, .preferred_linkage = .static }); 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 + // MJPEG, neither of which pardes calls) is a second PNG and JPEG + // decoder beside the build's: off (docs/shared-libs.md). + sdl_lib.root_module.addCMacro("SDL_DISABLE_STB", "1"); gm.linkLibrary(sdl_lib); gm.addIncludePath(dep.path("include")); // gui.zig's `c`: SDL and the font shim, which @cImport gave it before Zig 0.17. @@ -1682,6 +1715,25 @@ pub fn build(b: *std.Build) void { b.step("history", "compare command output and test/build runtime across jj revisions").dependOn(&run_history.step); const unit_step = b.step("unit-test", "run native shell and module unit tests"); + // One copy of each codec in the binary (docs/shared-libs.md): the + // linked symbol table, read for the families the build chose against. + // ELF only; it runs with every unit-test, like the perf gate. + if (target.result.ofmt == .elf) { + const libs_check = b.addExecutable(.{ + .name = "pardes-shared-libs-check", + .root_module = b.createModule(.{ + .target = b.graph.host, + .optimize = .debug, + .root_source_file = b.path("tools/shared_libs_check.zig"), + .link_libc = true, + }), + }); + const run_libs_check = b.addRunArtifact(libs_check); + run_libs_check.addArtifactArg(exe); + const libs_check_step = b.step("shared-libs-check", "fail when the binary links a second copy of a codec the build chose one of (docs/shared-libs.md)"); + libs_check_step.dependOn(&run_libs_check.step); + unit_step.dependOn(&run_libs_check.step); + } // The perf gate runs with every unit-test (a regression like a // contrast search per grapheme costs 100x, far past the gate). unit_step.dependOn(perf_gate_step); @@ -2055,6 +2107,7 @@ fn wireCore(m: *std.Build.Module, d: struct { ghostty_vt: ?*std.Build.Module = null, vaxis: ?*std.Build.Module = null, uucode: ?*std.Build.Module = null, + wuffs: ?*std.Build.Module = null, }) void { if (d.themes) |x| m.addImport("generated_themes", x); if (d.tree_sitter) |x| m.addImport("tree-sitter", x); @@ -2067,6 +2120,7 @@ fn wireCore(m: *std.Build.Module, d: struct { if (d.ghostty_vt) |x| m.addImport("ghostty-vt", x); if (d.vaxis) |x| m.addImport("vaxis", x); if (d.uucode) |x| m.addImport("uucode", x); + if (d.wuffs) |x| m.addImport("wuffs", x); } /// The CPU feature set for the ESP32-P4 firmware target, as a `Cpu.Feature.Set`. Spelled as a |
