summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 05:19:21 -0300
committerGabriel Schneider <[email protected]>2026-11-06 05:55:49 -0300
commitc8553032ef84aec74cbb5d07d07f934eecf3d4a9 (patch)
treee47d3dd72b83e0b95d53271df9f5932dab389959 /build.zig
parentde0447471febe1253b42a32fe9a1d6cdccc9d5b9 (diff)
downloadpardes-c8553032ef84aec74cbb5d07d07f934eecf3d4a9.tar.gz
pardes-c8553032ef84aec74cbb5d07d07f934eecf3d4a9.zip
kinds #9, the core's image code gone: src/image.zig (558 lines) and the static table go, so no kind is compiled in (Registry.init, Kind.image, compiledIn, `static` in /addons and "is compiled in" with them) and a test of the core's side of a kind's pane opens Kind.test_kind (a picture of one pixel, no library); a placement's fit (NativeGeometry, containGeometry) moves to surface.zig and a PDF's fit modes to pdf_view.zig; a terminal's kitty PNG decodes in TerminalImages.zig through wuffs as before, its downscale through stb_image_resize, the one part of zstbi the core keeps (stb_image patched out of it, the wuffs_images option, tag_image and image_exts gone); the image cases load the built image.so by path: test/panes.zig's and fs_namespace's through Addon.perform, T1 through Addon load (a new behaviour case: PNG, JPEG and PPM through 9P, the art words, a refused corrupt PNG, a dump's placeholder and its picture back, which replaces the decode unit test and ctl.zig's corrupt-image case), the snapshot, process and image harnesses by linking it into each session's data directory; images.snap unchanged
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.zig42
1 files changed, 25 insertions, 17 deletions
diff --git a/build.zig b/build.zig
index 132b3640..5178b735 100644
--- a/build.zig
+++ b/build.zig
@@ -758,28 +758,29 @@ 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.
+ // One PNG decoder (docs/shared-libs.md): ghostty's, wuffs, which
+ // ghostty-vt links for kitty graphics whatever pardes does; a terminal's
+ // PNG is decoded through it (TerminalImages.zig), and of zstbi only its
+ // resize is left, for the PNG's downscale: stb_image and its writer
+ // (with the deflate it carries) are patched out, here at build time so
+ // a fresh fetch keeps it. The image addon has its own (addons/image).
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) {
+ {
var sources: usize = 0;
for (zstbi_mod.link_objects.items) |obj| switch (obj) {
.c_source_file => |csf| {
sources += 1;
- const src = configureRead(b, io, zstbi_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");
+ var src = configureRead(b, io, zstbi_dep.builder.root, "src/zstbi.c", 1 << 20) catch @panic("read zstbi.c");
+ // zstbi.deinit still resets the reader's and the writer's
+ // flip flags, and Image.deinit frees the resize's output.
+ for ([_][2][]const u8{
+ .{ "#define STB_IMAGE_IMPLEMENTATION\n#include \"stb_image.h\"\n", "void stbi_set_flip_vertically_on_load(int flag) { (void)flag; }\nvoid stbi_image_free(void *p) { zstbiFreePtr(p); }\n" },
+ .{ "#define STB_IMAGE_WRITE_IMPLEMENTATION\n#include \"stb_image_write.h\"\n", "void stbi_flip_vertically_on_write(int flag) { (void)flag; }\n" },
+ }) |cut| {
+ if (std.mem.count(u8, src, cut[0]) != 1) std.debug.panic("zstbi.c changed at `{s}`: redo its patch in build.zig", .{cut[0]});
+ src = std.mem.replaceOwned(u8, b.allocator, src, cut[0], cut[1]) catch @panic("OOM");
+ }
+ csf.file = b.addWriteFiles().add("zstbi.c", src);
},
else => {},
};
@@ -1171,6 +1172,7 @@ pub fn build(b: *std.Build) void {
snap_build.addTty(b, .{
.exe = exe,
+ .image_addon = image_addon,
.target = target,
.optimize = optimize,
.ghostty_vt = ghostty_vt_for_snap,
@@ -1194,6 +1196,7 @@ pub fn build(b: *std.Build) void {
}
const run_image_harness = b.addRunArtifact(image_harness);
run_image_harness.addArtifactArg(exe);
+ run_image_harness.addArtifactArg(image_addon);
run_image_harness.addArg(if (platform == .gui) "gui" else "tui");
run_image_harness.has_side_effects = true;
b.step("image-harness", "exercise native Kitty/SDL image rendering end to end").dependOn(&run_image_harness.step);
@@ -1236,6 +1239,7 @@ pub fn build(b: *std.Build) void {
if (enable_mupdf) {
const run_pdf_harness = b.addRunArtifact(image_harness);
run_pdf_harness.addArtifactArg(exe);
+ run_pdf_harness.addArtifactArg(image_addon);
run_pdf_harness.addArg(if (platform == .gui) "gui" else "tui");
run_pdf_harness.addArg("pdf");
run_pdf_harness.has_side_effects = true;
@@ -1521,6 +1525,9 @@ pub fn build(b: *std.Build) void {
});
pane_module.addImport("pardes", core_module);
pane_module.addImport("pardes_config", core_module.import_table.get("pardes_config").?);
+ const test_addons = b.addOptions();
+ test_addons.addOptionPath("image", image_addon.getEmittedBin());
+ pane_module.addOptions("test_addons", test_addons);
const pane_tests = b.addTest(.{ .root_module = pane_module, .filters = test_filters });
_ = units.add(b, pane_tests, b.step("pane-test", "run pane, output, PDF and namespace integration tests"));
@@ -1563,6 +1570,7 @@ pub fn build(b: *std.Build) void {
session_options.addOptionPath(variant[0], lib.getEmittedBin());
if (std.mem.eql(u8, variant[0], "fake_addon")) fake_addon_lib = lib;
}
+ session_options.addOptionPath("image_addon", image_addon.getEmittedBin());
session_module.addOptions("session_options", session_options);
const behaviour_module = b.createModule(.{
.target = target,