build: disable bundled compiler_rt and ubsan_rt for MSVC targets

Zig's bundled compiler_rt and ubsan_rt produce object files with
ELF-style linker directives (/exclude-symbols) and COMDAT sections
that are incompatible with the MSVC linker, causing LNK1143 and
LNK4229 errors when linking the static library.

MSVC provides its own compiler runtime so bundling Zig's versions
is unnecessary. Skip bundling both runtimes when the target ABI is
MSVC.
This commit is contained in:
Mitchell Hashimoto
2026-03-23 10:42:05 -07:00
parent 2afadfc104
commit 31285e1ac3

View File

@@ -94,12 +94,19 @@ fn initLib(
);
if (kind == .static) {
const is_msvc_abi = target.result.abi == .msvc;
// These must be bundled since we're compiling into a static lib.
// Otherwise, you get undefined symbol errors. This could cause
// problems if you're linking multiple static Zig libraries but
// we'll cross that bridge when we get to it.
lib.bundle_compiler_rt = true;
lib.bundle_ubsan_rt = true;
//
// On MSVC targets, the MSVC runtime provides these, and Zig's
// bundled versions produce object files with ELF-style linker
// directives (e.g. /exclude-symbols) and COMDAT sections that
// are incompatible with the MSVC linker (LNK1143, LNK4229).
lib.bundle_compiler_rt = !is_msvc_abi;
lib.bundle_ubsan_rt = !is_msvc_abi;
// Enable PIC so the static library can be linked into PIE
// executables, which is the default on most Linux distributions.