build: skip bundled compiler_rt and ubsan_rt in Windows static lib

Zig's compiler_rt produces COFF objects with invalid COMDAT
sections that the MSVC linker rejects (LNK1143), and its ubsan_rt
emits /exclude-symbols directives that MSVC does not understand
(LNK4229). Skip bundling both in the static library on Windows
since the MSVC CRT provides the needed builtins (memcpy, memset,
etc.). The shared library continues to bundle compiler_rt as it
needs to be self-contained.
This commit is contained in:
Mitchell Hashimoto
2026-03-23 11:20:20 -07:00
parent 69f82ec751
commit 2c89bef860

View File

@@ -94,12 +94,20 @@ fn initLib(
);
if (kind == .static) {
const is_windows = target.result.os.tag == .windows;
// 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 Windows, Zig's compiler_rt produces COFF objects with
// invalid COMDAT sections (LNK1143) and its ubsan_rt emits
// /exclude-symbols directives the MSVC linker rejects
// (LNK4229). Both are skipped since the MSVC CRT provides
// the needed builtins (memcpy, memset, etc.).
lib.bundle_compiler_rt = !is_windows;
lib.bundle_ubsan_rt = !is_windows;
// Enable PIC so the static library can be linked into PIE
// executables, which is the default on most Linux distributions.