mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-24 05:40:15 +00:00
build: disable ubsan in C deps for MSVC static linking
Zig's ubsan runtime cannot be bundled on Windows (LNK4229), leaving __ubsan_handle_* symbols unresolved when the static archive is consumed by an external linker like MSVC link.exe. freetype, glslang, spirv-cross, and highway already suppress ubsan unconditionally. Add MSVC-conditional suppression to the seven C dependencies that were missing it: harfbuzz, libpng, dcimgui, wuffs, oniguruma, zlib, and stb. The fix is gated on abi == .msvc so ubsan coverage is preserved on Linux and macOS where bundle_ubsan_rt works.
This commit is contained in:
@@ -60,6 +60,12 @@ pub fn build(b: *std.Build) !void {
|
||||
"-DIMGUI_USE_WCHAR32=1",
|
||||
"-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1",
|
||||
});
|
||||
if (target.result.abi == .msvc) {
|
||||
try flags.appendSlice(b.allocator, &.{
|
||||
"-fno-sanitize=undefined",
|
||||
"-fno-sanitize-trap=undefined",
|
||||
});
|
||||
}
|
||||
if (freetype) try flags.appendSlice(b.allocator, &.{
|
||||
"-DIMGUI_ENABLE_FREETYPE=1",
|
||||
});
|
||||
|
||||
@@ -123,6 +123,15 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu
|
||||
try flags.appendSlice(b.allocator, &.{
|
||||
"-DHAVE_STDBOOL_H",
|
||||
});
|
||||
// Disable ubsan for MSVC: Zig's ubsan runtime cannot be bundled
|
||||
// on Windows (LNK4229), leaving __ubsan_handle_* unresolved when
|
||||
// the static archive is consumed by an external linker.
|
||||
if (target.result.abi == .msvc) {
|
||||
try flags.appendSlice(b.allocator, &.{
|
||||
"-fno-sanitize=undefined",
|
||||
"-fno-sanitize-trap=undefined",
|
||||
});
|
||||
}
|
||||
if (target.result.os.tag != .windows) {
|
||||
try flags.appendSlice(b.allocator, &.{
|
||||
"-DHAVE_UNISTD_H",
|
||||
|
||||
@@ -54,6 +54,12 @@ pub fn build(b: *std.Build) !void {
|
||||
"-DPNG_INTEL_SSE_OPT=0",
|
||||
"-DPNG_MIPS_MSA_OPT=0",
|
||||
});
|
||||
if (target.result.abi == .msvc) {
|
||||
try flags.appendSlice(b.allocator, &.{
|
||||
"-fno-sanitize=undefined",
|
||||
"-fno-sanitize-trap=undefined",
|
||||
});
|
||||
}
|
||||
|
||||
lib.addCSourceFiles(.{
|
||||
.root = upstream.path(""),
|
||||
|
||||
@@ -103,6 +103,12 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu
|
||||
|
||||
var flags: std.ArrayList([]const u8) = .empty;
|
||||
defer flags.deinit(b.allocator);
|
||||
if (target.result.abi == .msvc) {
|
||||
try flags.appendSlice(b.allocator, &.{
|
||||
"-fno-sanitize=undefined",
|
||||
"-fno-sanitize-trap=undefined",
|
||||
});
|
||||
}
|
||||
lib.addCSourceFiles(.{
|
||||
.root = upstream.path(""),
|
||||
.flags = flags.items,
|
||||
|
||||
@@ -20,6 +20,10 @@ pub fn build(b: *std.Build) !void {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,12 @@ pub fn build(b: *std.Build) !void {
|
||||
"-DHAVE_STDINT_H",
|
||||
"-DHAVE_STDDEF_H",
|
||||
});
|
||||
if (target.result.abi == .msvc) {
|
||||
try flags.appendSlice(b.allocator, &.{
|
||||
"-fno-sanitize=undefined",
|
||||
"-fno-sanitize-trap=undefined",
|
||||
});
|
||||
}
|
||||
if (target.result.os.tag != .windows) {
|
||||
try flags.append(b.allocator, "-DZ_HAVE_UNISTD_H");
|
||||
}
|
||||
|
||||
@@ -412,7 +412,16 @@ pub fn add(
|
||||
// C files
|
||||
step.linkLibC();
|
||||
step.addIncludePath(b.path("src/stb"));
|
||||
step.addCSourceFiles(.{ .files = &.{"src/stb/stb.c"} });
|
||||
// Disable ubsan for MSVC: Zig's ubsan runtime cannot be bundled
|
||||
// on Windows (LNK4229), leaving __ubsan_handle_* unresolved when
|
||||
// the static archive is consumed by an external linker.
|
||||
step.addCSourceFiles(.{
|
||||
.files = &.{"src/stb/stb.c"},
|
||||
.flags = if (step.rootModuleTarget().abi == .msvc)
|
||||
&.{ "-fno-sanitize=undefined", "-fno-sanitize-trap=undefined" }
|
||||
else
|
||||
&.{},
|
||||
});
|
||||
if (step.rootModuleTarget().os.tag == .linux) {
|
||||
step.addIncludePath(b.path("src/apprt/gtk"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user