From 20b7fe0e1dd485af1f64ff5ce5d08135274896e9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 6 Apr 2026 10:30:00 -0700 Subject: [PATCH] libghostty: gate kitty graphics placement types on build option The PlacementIterator, PlacementMap, and PlacementIteratorWrapper types in the C API were unconditionally referencing kitty_storage.ImageStorage, which transitively pulled in Image.transmit_time (std.time.Instant). On wasm32-freestanding, std.time.Instant requires posix.timespec which does not exist, causing a compilation error. Gate these types behind build_options.kitty_graphics, matching the existing pattern used for KittyGraphics and ImageHandle. When kitty graphics is disabled, they fall back to opaque/void types. Add early-return guards to placement_iterator_new and placement_iterator_free which directly operate on the wrapper struct. --- src/terminal/c/kitty_graphics.zig | 34 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/terminal/c/kitty_graphics.zig b/src/terminal/c/kitty_graphics.zig index 5444b8bab..f5811a024 100644 --- a/src/terminal/c/kitty_graphics.zig +++ b/src/terminal/c/kitty_graphics.zig @@ -24,18 +24,27 @@ else ?*const anyopaque; /// C: GhosttyKittyGraphicsPlacementIterator -pub const PlacementIterator = ?*PlacementIteratorWrapper; +pub const PlacementIterator = if (build_options.kitty_graphics) + ?*PlacementIteratorWrapper +else + ?*anyopaque; -const PlacementMap = std.AutoHashMapUnmanaged( - kitty_storage.ImageStorage.PlacementKey, - kitty_storage.ImageStorage.Placement, -); +const PlacementMap = if (build_options.kitty_graphics) + std.AutoHashMapUnmanaged( + kitty_storage.ImageStorage.PlacementKey, + kitty_storage.ImageStorage.Placement, + ) +else + void; -const PlacementIteratorWrapper = struct { - alloc: std.mem.Allocator, - inner: PlacementMap.Iterator = undefined, - entry: ?PlacementMap.Entry = null, -}; +const PlacementIteratorWrapper = if (build_options.kitty_graphics) + struct { + alloc: std.mem.Allocator, + inner: PlacementMap.Iterator = undefined, + entry: ?PlacementMap.Entry = null, + } +else + void; /// C: GhosttyKittyGraphicsData pub const Data = enum(c_int) { @@ -204,6 +213,10 @@ pub fn placement_iterator_new( alloc_: ?*const CAllocator, out: *PlacementIterator, ) callconv(lib.calling_conv) Result { + if (comptime !build_options.kitty_graphics) { + out.* = null; + return .no_value; + } const alloc = lib.alloc.default(alloc_); const ptr = alloc.create(PlacementIteratorWrapper) catch { out.* = null; @@ -215,6 +228,7 @@ pub fn placement_iterator_new( } pub fn placement_iterator_free(iter_: PlacementIterator) callconv(lib.calling_conv) void { + if (comptime !build_options.kitty_graphics) return; const iter = iter_ orelse return; iter.alloc.destroy(iter); }