aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/pkg/wuffs
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-10 21:51:57 +0300
committerGitHub <noreply@github.com>2026-09-10 21:51:57 +0300
commit425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch)
treee52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/pkg/wuffs
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/pkg/wuffs')
-rw-r--r--vendor/libghostty-vt/pkg/wuffs/build.zig97
-rw-r--r--vendor/libghostty-vt/pkg/wuffs/build.zig.zon13
-rw-r--r--vendor/libghostty-vt/pkg/wuffs/include/stdlib.h13
-rw-r--r--vendor/libghostty-vt/pkg/wuffs/include/string.h22
-rw-r--r--vendor/libghostty-vt/pkg/wuffs/src/c.zig18
-rw-r--r--vendor/libghostty-vt/pkg/wuffs/src/error.zig2
-rw-r--r--vendor/libghostty-vt/pkg/wuffs/src/jpeg.zig2
-rw-r--r--vendor/libghostty-vt/pkg/wuffs/src/main.zig48
-rw-r--r--vendor/libghostty-vt/pkg/wuffs/src/png.zig2
-rw-r--r--vendor/libghostty-vt/pkg/wuffs/src/swizzle.zig73
10 files changed, 243 insertions, 47 deletions
diff --git a/vendor/libghostty-vt/pkg/wuffs/build.zig b/vendor/libghostty-vt/pkg/wuffs/build.zig
index 95cef3e0..ce342246 100644
--- a/vendor/libghostty-vt/pkg/wuffs/build.zig
+++ b/vendor/libghostty-vt/pkg/wuffs/build.zig
@@ -1,5 +1,38 @@
const std = @import("std");
+// All the C macros defined so that the header matches the build.
+const defines = [_][]const u8{
+ "WUFFS_CONFIG__MODULES",
+ "WUFFS_CONFIG__MODULE__AUX__BASE",
+ "WUFFS_CONFIG__MODULE__AUX__IMAGE",
+ "WUFFS_CONFIG__MODULE__BASE",
+ "WUFFS_CONFIG__MODULE__ADLER32",
+ "WUFFS_CONFIG__MODULE__CRC32",
+ "WUFFS_CONFIG__MODULE__DEFLATE",
+ "WUFFS_CONFIG__MODULE__JPEG",
+ "WUFFS_CONFIG__MODULE__PNG",
+ "WUFFS_CONFIG__MODULE__ZLIB",
+};
+
+// Generated C code, includes the macros above. Designed to mimic old c.zig.
+// TODO: is this still needed, or are the -D flags enough?
+const wuffs_c_source = wuffs_c_source: {
+ const include: []const u8 = "#include <wuffs-v0.4.c>";
+ const len = len: {
+ var len: usize = 0;
+ for (defines) |d| len += std.fmt.count("#define {s}\n", .{d});
+ len += std.fmt.count("{s}\n", .{include});
+ break :len len;
+ };
+
+ var buf: [len:0]u8 = undefined;
+ var writer: std.Io.Writer = .fixed(&buf);
+ for (defines) |d| writer.print("#define {s}\n", .{d}) catch unreachable;
+ writer.print("{s}\n", .{include}) catch unreachable;
+ buf[len] = 0;
+ break :wuffs_c_source buf;
+};
+
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
@@ -8,32 +41,60 @@ pub fn build(b: *std.Build) !void {
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
- .link_libc = true,
});
const unit_tests = b.addTest(.{
.name = "test",
.root_module = module,
});
- unit_tests.linkLibC();
-
- var flags: std.ArrayList([]const u8) = .empty;
- defer flags.deinit(b.allocator);
- try flags.append(b.allocator, "-DWUFFS_IMPLEMENTATION");
- if (target.result.abi == .msvc) {
- try flags.append(b.allocator, "-fno-sanitize=undefined");
- try flags.append(b.allocator, "-fno-sanitize-trap=undefined");
- }
- inline for (@import("src/c.zig").defines) |key| {
- try flags.append(b.allocator, "-D" ++ key);
- }
- if (b.lazyDependency("wuffs", .{})) |wuffs_dep| {
- module.addIncludePath(wuffs_dep.path("release/c"));
- module.addCSourceFile(.{
- .file = wuffs_dep.path("release/c/wuffs-v0.4.c"),
- .flags = flags.items,
+ // Windows always has a libc available.
+ const windows = target.result.os.tag == .windows;
+
+ translate: {
+ const translate_c = b.lazyImport(@This(), "translate_c") orelse break :translate;
+ const translate_c_dep = b.lazyDependency("translate_c", .{}) orelse break :translate;
+ const wuffs_c: translate_c.Translator = .init(translate_c_dep, .{
+ .c_source_file = b.addWriteFiles().add("wuffs_c.h", &wuffs_c_source),
+ .target = target,
+ .optimize = optimize,
+ .link_libc = windows,
+ .libc_file = if (b.libc_file) |path| .{ .cwd_relative = path } else null,
});
+
+ // Wuffs only needs stdlib.h and string.h from libc, and only for
+ // a handful of declarations. We provide minimal versions of these
+ // headers so that wuffs can be translated and compiled without
+ // libc, notably for freestanding targets (wasm32) but this also
+ // avoids requiring an Apple SDK for translate-c on macOS.
+ if (!windows) wuffs_c.addIncludePath(b.path("include"));
+
+ var flags: std.ArrayList([]const u8) = .empty;
+ defer flags.deinit(b.allocator);
+ try flags.append(b.allocator, "-DWUFFS_IMPLEMENTATION");
+
+ // Disable ubsan on Windows to avoid undefined __ubsan_handle_*
+ // references: Zig's ubsan runtime can't be bundled on Windows
+ // (its /exclude-symbols directives break the MSVC linker), so
+ // these handlers would go unresolved. This affects both the
+ // MSVC and GNU ABIs.
+ if (windows) {
+ try flags.append(b.allocator, "-fno-sanitize=undefined");
+ try flags.append(b.allocator, "-fno-sanitize-trap=undefined");
+ }
+ inline for (defines) |key| {
+ try flags.append(b.allocator, "-D" ++ key);
+ }
+
+ if (b.lazyDependency("wuffs", .{})) |wuffs_dep| {
+ wuffs_c.addIncludePath(wuffs_dep.path("release/c"));
+ wuffs_c.mod.addCSourceFile(.{
+ .file = wuffs_dep.path("release/c/wuffs-v0.4.c"),
+ .flags = flags.items,
+ });
+ }
+
+ module.addImport("wuffs_c", wuffs_c.mod);
}
if (b.lazyDependency("pixels", .{})) |pixels_dep| {
diff --git a/vendor/libghostty-vt/pkg/wuffs/build.zig.zon b/vendor/libghostty-vt/pkg/wuffs/build.zig.zon
index eb99ba0b..2813fb77 100644
--- a/vendor/libghostty-vt/pkg/wuffs/build.zig.zon
+++ b/vendor/libghostty-vt/pkg/wuffs/build.zig.zon
@@ -3,10 +3,16 @@
.version = "0.0.0",
.fingerprint = 0x67c0c059de921c4f,
.dependencies = .{
+ .translate_c = .{
+ .lazy = true,
+ .url = "https://codeberg.org/vancluever/translate-c/archive/4e879eb8aba615de112eabd1231ea6e01920cead.tar.gz",
+ .hash = "translate_c-0.0.0-Q_BUWhVNBwDOEcIqub4VFPJPB6D9dgwzUMHTX5KWr8Xr",
+ },
+
// google/wuffs
.wuffs = .{
- .url = "https://deps.files.ghostty.org/wuffs-122037b39d577ec2db3fd7b2130e7b69ef6cc1807d68607a7c232c958315d381b5cd.tar.gz",
- .hash = "N-V-__8AAAzZywE3s51XfsLbP9eyEw57ae9swYB9aGB6fCMs",
+ .url = "https://deps.files.ghostty.org/wuffs-7411f488fe2e2c205c3d3b3d28638b7356522930.tar.gz",
+ .hash = "N-V-__8AAP5JWgCGP_AD0teWpa4krRvE9VPZzvviGdbmN4jI",
.lazy = true,
},
@@ -16,12 +22,11 @@
.hash = "N-V-__8AADYiAAB_80AWnH1AxXC0tql9thT-R-DYO1gBqTLc",
.lazy = true,
},
-
- .apple_sdk = .{ .path = "../apple-sdk" },
},
.paths = .{
"build.zig",
"build.zig.zon",
+ "include",
"src",
},
}
diff --git a/vendor/libghostty-vt/pkg/wuffs/include/stdlib.h b/vendor/libghostty-vt/pkg/wuffs/include/stdlib.h
new file mode 100644
index 00000000..5c050743
--- /dev/null
+++ b/vendor/libghostty-vt/pkg/wuffs/include/stdlib.h
@@ -0,0 +1,13 @@
+// Minimal stdlib.h so that wuffs can be translated and compiled without
+// requiring libc headers. See string.h in this directory for details.
+#ifndef GHOSTTY_WUFFS_STDLIB_H
+#define GHOSTTY_WUFFS_STDLIB_H
+
+#include <stddef.h>
+
+void *malloc(size_t size);
+void *calloc(size_t count, size_t size);
+void *realloc(void *ptr, size_t size);
+void free(void *ptr);
+
+#endif
diff --git a/vendor/libghostty-vt/pkg/wuffs/include/string.h b/vendor/libghostty-vt/pkg/wuffs/include/string.h
new file mode 100644
index 00000000..39d405d3
--- /dev/null
+++ b/vendor/libghostty-vt/pkg/wuffs/include/string.h
@@ -0,0 +1,22 @@
+// Minimal string.h so that wuffs can be translated and compiled without
+// requiring libc headers (e.g. for wasm32-freestanding targets, or to
+// avoid needing an Apple SDK for translate-c on macOS).
+//
+// Wuffs only calls the mem* family, whose symbols are provided by Zig's
+// compiler-rt on targets without libc and by libc everywhere else. The
+// declarations here match the standard C ABI, so this header is safe to
+// use on every target, including ones that do link libc.
+#ifndef GHOSTTY_WUFFS_STRING_H
+#define GHOSTTY_WUFFS_STRING_H
+
+#include <stddef.h>
+
+void *memcpy(void *dst, const void *src, size_t n);
+void *memmove(void *dst, const void *src, size_t n);
+void *memset(void *b, int c, size_t n);
+int memcmp(const void *s1, const void *s2, size_t n);
+size_t strlen(const char *s);
+int strcmp(const char *s1, const char *s2);
+int strncmp(const char *s1, const char *s2, size_t n);
+
+#endif
diff --git a/vendor/libghostty-vt/pkg/wuffs/src/c.zig b/vendor/libghostty-vt/pkg/wuffs/src/c.zig
deleted file mode 100644
index d94247df..00000000
--- a/vendor/libghostty-vt/pkg/wuffs/src/c.zig
+++ /dev/null
@@ -1,18 +0,0 @@
-pub const c = @cImport({
- for (defines) |d| @cDefine(d, "1");
- @cInclude("wuffs-v0.4.c");
-});
-
-/// All the C macros defined so that the header matches the build.
-pub const defines: []const []const u8 = &[_][]const u8{
- "WUFFS_CONFIG__MODULES",
- "WUFFS_CONFIG__MODULE__AUX__BASE",
- "WUFFS_CONFIG__MODULE__AUX__IMAGE",
- "WUFFS_CONFIG__MODULE__BASE",
- "WUFFS_CONFIG__MODULE__ADLER32",
- "WUFFS_CONFIG__MODULE__CRC32",
- "WUFFS_CONFIG__MODULE__DEFLATE",
- "WUFFS_CONFIG__MODULE__JPEG",
- "WUFFS_CONFIG__MODULE__PNG",
- "WUFFS_CONFIG__MODULE__ZLIB",
-};
diff --git a/vendor/libghostty-vt/pkg/wuffs/src/error.zig b/vendor/libghostty-vt/pkg/wuffs/src/error.zig
index 0be55cf4..e4ca5c1d 100644
--- a/vendor/libghostty-vt/pkg/wuffs/src/error.zig
+++ b/vendor/libghostty-vt/pkg/wuffs/src/error.zig
@@ -1,6 +1,6 @@
const std = @import("std");
-const c = @import("c.zig").c;
+const c = @import("wuffs_c");
pub const Error = std.mem.Allocator.Error || error{ WuffsError, Overflow };
diff --git a/vendor/libghostty-vt/pkg/wuffs/src/jpeg.zig b/vendor/libghostty-vt/pkg/wuffs/src/jpeg.zig
index 69d91c8a..a7bc4bdd 100644
--- a/vendor/libghostty-vt/pkg/wuffs/src/jpeg.zig
+++ b/vendor/libghostty-vt/pkg/wuffs/src/jpeg.zig
@@ -1,6 +1,6 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
-const c = @import("c.zig").c;
+const c = @import("wuffs_c");
const Error = @import("error.zig").Error;
const check = @import("error.zig").check;
const ImageData = @import("main.zig").ImageData;
diff --git a/vendor/libghostty-vt/pkg/wuffs/src/main.zig b/vendor/libghostty-vt/pkg/wuffs/src/main.zig
index 207d83f9..41b74cab 100644
--- a/vendor/libghostty-vt/pkg/wuffs/src/main.zig
+++ b/vendor/libghostty-vt/pkg/wuffs/src/main.zig
@@ -1,3 +1,4 @@
+const builtin = @import("builtin");
const std = @import("std");
pub const png = @import("png.zig");
@@ -15,6 +16,51 @@ pub const ImageData = struct {
data: []u8,
};
+// Wuffs' generated `wuffs_foo__bar__alloc()` convenience functions are the
+// only code that references libc's calloc/free. We never call them
+// and linker garbage collection strips them, but that isn't guaranteed.
+// Freestanding consumers may have no allocator to resolve these symbols.
+// Never export stubs for hosted targets: hidden weak symbols in a static
+// archive can override the embedding executable's dynamically linked libc.
+comptime {
+ if (!builtin.link_libc and builtin.os.tag == .freestanding) {
+ @export(&callocStub, .{
+ .name = "calloc",
+ .linkage = .weak,
+ .visibility = .hidden,
+ });
+ @export(&freeStub, .{
+ .name = "free",
+ .linkage = .weak,
+ .visibility = .hidden,
+ });
+ }
+}
+
+fn callocStub(count: usize, size: usize) callconv(.c) ?*anyopaque {
+ _ = count;
+ _ = size;
+ return null;
+}
+
+fn freeStub(ptr: ?*anyopaque) callconv(.c) void {
+ _ = ptr;
+}
+
test {
- std.testing.refAllDeclsRecursive(@This());
+ refAllDeclsRecursive(@This());
+}
+
+/// Copied from 0.15.2 stdlib (MIT license).
+fn refAllDeclsRecursive(comptime T: type) void {
+ if (!builtin.is_test) return;
+ inline for (comptime std.meta.declarations(T)) |decl| {
+ if (@TypeOf(@field(T, decl.name)) == type) {
+ switch (@typeInfo(@field(T, decl.name))) {
+ .@"struct", .@"enum", .@"union", .@"opaque" => refAllDeclsRecursive(@field(T, decl.name)),
+ else => {},
+ }
+ }
+ _ = &@field(T, decl.name);
+ }
}
diff --git a/vendor/libghostty-vt/pkg/wuffs/src/png.zig b/vendor/libghostty-vt/pkg/wuffs/src/png.zig
index 57a0e63b..4bf3d759 100644
--- a/vendor/libghostty-vt/pkg/wuffs/src/png.zig
+++ b/vendor/libghostty-vt/pkg/wuffs/src/png.zig
@@ -1,6 +1,6 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
-const c = @import("c.zig").c;
+const c = @import("wuffs_c");
const Error = @import("error.zig").Error;
const check = @import("error.zig").check;
const ImageData = @import("main.zig").ImageData;
diff --git a/vendor/libghostty-vt/pkg/wuffs/src/swizzle.zig b/vendor/libghostty-vt/pkg/wuffs/src/swizzle.zig
index 352cf2b5..d873efea 100644
--- a/vendor/libghostty-vt/pkg/wuffs/src/swizzle.zig
+++ b/vendor/libghostty-vt/pkg/wuffs/src/swizzle.zig
@@ -1,7 +1,7 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
-const c = @import("c.zig").c;
+const c = @import("wuffs_c");
const Error = @import("error.zig").Error;
const log = std.log.scoped(.wuffs_swizzler);
@@ -16,11 +16,15 @@ pub fn gToRgba(alloc: Allocator, src: []const u8) Error![]u8 {
}
pub fn gaToRgba(alloc: Allocator, src: []const u8) Error![]u8 {
+ // Wuffs doesn't support YA_PREMUL as a swizzle source. The nonpremul
+ // pair produces the same bytes (r=g=b=y, a=a, no alpha math), which
+ // is what we want: alpha semantics are preserved as-is, matching the
+ // other conversions here.
return swizzle(
alloc,
src,
- c.WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL,
- c.WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL,
+ c.WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL,
+ c.WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL,
);
}
@@ -51,6 +55,69 @@ pub fn bgraToRgba(alloc: Allocator, src: []const u8) Error![]u8 {
);
}
+/// Composite `src` over `dst` in place. Both are straight
+/// (non-premultiplied) alpha RGBA of the same length. A transparent
+/// destination pixel takes the source pixel exactly; wuffs composites
+/// everything else in 16-bit integer space.
+pub fn rgbaSrcOver(dst: []u8, src: []const u8) void {
+ assert(dst.len == src.len);
+ assert(dst.len % 4 == 0);
+
+ var swizzler: c.wuffs_base__pixel_swizzler = undefined;
+ const status = c.wuffs_base__pixel_swizzler__prepare(
+ &swizzler,
+ c.wuffs_base__make_pixel_format(c.WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL),
+ c.wuffs_base__empty_slice_u8(),
+ c.wuffs_base__make_pixel_format(c.WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL),
+ c.wuffs_base__empty_slice_u8(),
+ c.WUFFS_BASE__PIXEL_BLEND__SRC_OVER,
+ );
+ // This format pair and blend mode is a supported swizzle, so
+ // preparation can only fail on a programming error.
+ assert(c.wuffs_base__status__is_ok(&status));
+
+ _ = c.wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(
+ &swizzler,
+ c.wuffs_base__make_slice_u8(dst.ptr, dst.len),
+ c.wuffs_base__empty_slice_u8(),
+ c.wuffs_base__make_slice_u8(@constCast(src.ptr), src.len),
+ );
+}
+
+test "gaToRgba" {
+ const rgba = try gaToRgba(std.testing.allocator, &.{ 7, 100, 8, 200 });
+ defer std.testing.allocator.free(rgba);
+
+ try std.testing.expectEqualSlices(u8, &.{
+ 7, 7, 7, 100,
+ 8, 8, 8, 200,
+ }, rgba);
+}
+
+test "rgbaSrcOver" {
+ // 50% white over opaque black, opaque over anything, transparent
+ // source over anything, and anything over a transparent
+ // destination (exact source passthrough).
+ var dst = [_]u8{
+ 0, 0, 0, 255,
+ 10, 20, 30, 40,
+ 10, 20, 30, 40,
+ 0, 0, 0, 0,
+ };
+ rgbaSrcOver(&dst, &.{
+ 255, 255, 255, 128,
+ 100, 110, 120, 255,
+ 100, 110, 120, 0,
+ 200, 100, 50, 128,
+ });
+ try std.testing.expectEqualSlices(u8, &.{
+ 128, 128, 128, 255,
+ 100, 110, 120, 255,
+ 10, 20, 30, 40,
+ 200, 100, 50, 128,
+ }, &dst);
+}
+
fn swizzle(
alloc: Allocator,
src: []const u8,