aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/pkg/wuffs/build.zig
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/build.zig
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/pkg/wuffs/build.zig')
-rw-r--r--vendor/libghostty-vt/pkg/wuffs/build.zig97
1 files changed, 79 insertions, 18 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| {