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.pull/12217/head
parent
94e638d084
commit
a10854654d
|
|
@ -60,6 +60,12 @@ pub fn build(b: *std.Build) !void {
|
||||||
"-DIMGUI_USE_WCHAR32=1",
|
"-DIMGUI_USE_WCHAR32=1",
|
||||||
"-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=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, &.{
|
if (freetype) try flags.appendSlice(b.allocator, &.{
|
||||||
"-DIMGUI_ENABLE_FREETYPE=1",
|
"-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, &.{
|
try flags.appendSlice(b.allocator, &.{
|
||||||
"-DHAVE_STDBOOL_H",
|
"-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) {
|
if (target.result.os.tag != .windows) {
|
||||||
try flags.appendSlice(b.allocator, &.{
|
try flags.appendSlice(b.allocator, &.{
|
||||||
"-DHAVE_UNISTD_H",
|
"-DHAVE_UNISTD_H",
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,12 @@ pub fn build(b: *std.Build) !void {
|
||||||
"-DPNG_INTEL_SSE_OPT=0",
|
"-DPNG_INTEL_SSE_OPT=0",
|
||||||
"-DPNG_MIPS_MSA_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(.{
|
lib.addCSourceFiles(.{
|
||||||
.root = upstream.path(""),
|
.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;
|
var flags: std.ArrayList([]const u8) = .empty;
|
||||||
defer flags.deinit(b.allocator);
|
defer flags.deinit(b.allocator);
|
||||||
|
if (target.result.abi == .msvc) {
|
||||||
|
try flags.appendSlice(b.allocator, &.{
|
||||||
|
"-fno-sanitize=undefined",
|
||||||
|
"-fno-sanitize-trap=undefined",
|
||||||
|
});
|
||||||
|
}
|
||||||
lib.addCSourceFiles(.{
|
lib.addCSourceFiles(.{
|
||||||
.root = upstream.path(""),
|
.root = upstream.path(""),
|
||||||
.flags = flags.items,
|
.flags = flags.items,
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ pub fn build(b: *std.Build) !void {
|
||||||
var flags: std.ArrayList([]const u8) = .empty;
|
var flags: std.ArrayList([]const u8) = .empty;
|
||||||
defer flags.deinit(b.allocator);
|
defer flags.deinit(b.allocator);
|
||||||
try flags.append(b.allocator, "-DWUFFS_IMPLEMENTATION");
|
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| {
|
inline for (@import("src/c.zig").defines) |key| {
|
||||||
try flags.append(b.allocator, "-D" ++ key);
|
try flags.append(b.allocator, "-D" ++ key);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,12 @@ pub fn build(b: *std.Build) !void {
|
||||||
"-DHAVE_STDINT_H",
|
"-DHAVE_STDINT_H",
|
||||||
"-DHAVE_STDDEF_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) {
|
if (target.result.os.tag != .windows) {
|
||||||
try flags.append(b.allocator, "-DZ_HAVE_UNISTD_H");
|
try flags.append(b.allocator, "-DZ_HAVE_UNISTD_H");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -412,7 +412,16 @@ pub fn add(
|
||||||
// C files
|
// C files
|
||||||
step.linkLibC();
|
step.linkLibC();
|
||||||
step.addIncludePath(b.path("src/stb"));
|
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) {
|
if (step.rootModuleTarget().os.tag == .linux) {
|
||||||
step.addIncludePath(b.path("src/apprt/gtk"));
|
step.addIncludePath(b.path("src/apprt/gtk"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue