From 3d2c916813c495596d765d8918e0eb0d48a2aac9 Mon Sep 17 00:00:00 2001 From: "UENO, M." Date: Thu, 2 Jul 2026 14:28:40 +0000 Subject: [PATCH 1/2] fix(windows): add MSVC CRT linking for ghostty-vt shared builds --- src/build/GhosttyLibVt.zig | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/build/GhosttyLibVt.zig b/src/build/GhosttyLibVt.zig index 65f945bfd78..a7dd4a0b3fe 100644 --- a/src/build/GhosttyLibVt.zig +++ b/src/build/GhosttyLibVt.zig @@ -231,6 +231,38 @@ fn initLib( // Zig's ubsan emits /exclude-symbols linker directives that // are incompatible with the MSVC linker (LNK4229). lib.bundle_ubsan_rt = false; + + // When building a shared library (DLL) on Windows with MSVC, + // the full CRT library chain is required. linkLibC() provides + // msvcrt.lib, but that references symbols in vcruntime.lib and + // ucrt.lib. Zig's library search paths include the MSVC lib dir + // and the Windows SDK 'um' dir, but not the 'ucrt' dir. + // See the equivalent fix in GhosttyLib.zig. + if (kind == .shared and target.result.abi == .msvc) { + lib.linkSystemLibrary("libvcruntime"); + + const arch = target.result.cpu.arch; + const sdk = std.zig.WindowsSdk.find(b.allocator, arch) catch null; + if (sdk) |s| { + if (s.windows10sdk) |w10| { + const arch_str: []const u8 = switch (arch) { + .x86_64 => "x64", + .x86 => "x86", + .aarch64 => "arm64", + else => "x64", + }; + const ucrt_lib_path = std.fmt.allocPrint( + b.allocator, + "{s}\\Lib\\{s}\\ucrt\\{s}", + .{ w10.path, w10.version, arch_str }, + ) catch null; + if (ucrt_lib_path) |path| { + lib.addLibraryPath(.{ .cwd_relative = path }); + } + } + } + lib.linkSystemLibrary("libucrt"); + } } if (lib.rootModuleTarget().abi.isAndroid()) { From 386408bcdafa6b40442669bdff5b79f8779db5b3 Mon Sep 17 00:00:00 2001 From: "UENO, M." Date: Fri, 3 Jul 2026 12:27:38 +0900 Subject: [PATCH 2/2] Update comments on Windows DLL and CRT linking Clarified comments regarding Windows DLL requirements and CRT library linking. --- src/build/GhosttyLibVt.zig | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/build/GhosttyLibVt.zig b/src/build/GhosttyLibVt.zig index a7dd4a0b3fe..c9f9109568c 100644 --- a/src/build/GhosttyLibVt.zig +++ b/src/build/GhosttyLibVt.zig @@ -232,12 +232,11 @@ fn initLib( // are incompatible with the MSVC linker (LNK4229). lib.bundle_ubsan_rt = false; - // When building a shared library (DLL) on Windows with MSVC, - // the full CRT library chain is required. linkLibC() provides - // msvcrt.lib, but that references symbols in vcruntime.lib and - // ucrt.lib. Zig's library search paths include the MSVC lib dir - // and the Windows SDK 'um' dir, but not the 'ucrt' dir. - // See the equivalent fix in GhosttyLib.zig. + // On Windows with MSVC, building a DLL requires the full CRT + // library chain. Linking libc provides 'msvcrt.lib', but that + // references symbols in 'vcruntime.lib' and 'ucrt.lib'. Zig's library + // search paths include the MSVC lib dir and the Windows SDK 'um' + // dir, but not the SDK 'ucrt' dir where 'ucrt.lib' lives. if (kind == .shared and target.result.abi == .msvc) { lib.linkSystemLibrary("libvcruntime");