From 2c89bef860efbd5518375edcce6f1f210a923c59 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 23 Mar 2026 11:20:20 -0700 Subject: [PATCH] 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. --- src/build/GhosttyLibVt.zig | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/build/GhosttyLibVt.zig b/src/build/GhosttyLibVt.zig index 408f1ebc8..fcc93e4c7 100644 --- a/src/build/GhosttyLibVt.zig +++ b/src/build/GhosttyLibVt.zig @@ -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.