From deeda4618691525e977886135aa4ff18b7f81caa Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 24 Mar 2026 17:03:33 +0100 Subject: [PATCH] build: skip linkLibCpp on MSVC for dcimgui, spirv-cross, harfbuzz Zig unconditionally passes -nostdinc++ and adds its bundled libc++/libc++abi include paths, which conflict with MSVC's own C++ runtime headers. The MSVC SDK directories (added via linkLibC) already contain both C and C++ headers, so linkLibCpp is not needed. This is the same fix already applied upstream to highway, simdutf, utfcpp, glslang, SharedDeps, and GhosttyZig. Co-Authored-By: Claude Opus 4.6 (1M context) --- pkg/dcimgui/build.zig | 9 ++++++++- pkg/harfbuzz/build.zig | 9 ++++++++- pkg/spirv-cross/build.zig | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/pkg/dcimgui/build.zig b/pkg/dcimgui/build.zig index 2a1389834..01a5879d6 100644 --- a/pkg/dcimgui/build.zig +++ b/pkg/dcimgui/build.zig @@ -26,7 +26,14 @@ pub fn build(b: *std.Build) !void { .linkage = .static, }); lib.linkLibC(); - lib.linkLibCpp(); + // On MSVC, we must not use linkLibCpp because Zig unconditionally + // passes -nostdinc++ and then adds its bundled libc++/libc++abi + // include paths, which conflict with MSVC's own C++ runtime headers. + // The MSVC SDK include directories (added via linkLibC) contain + // both C and C++ headers, so linkLibCpp is not needed. + if (target.result.abi != .msvc) { + lib.linkLibCpp(); + } b.installArtifact(lib); // Zig module diff --git a/pkg/harfbuzz/build.zig b/pkg/harfbuzz/build.zig index 8696c0203..6d8f3be70 100644 --- a/pkg/harfbuzz/build.zig +++ b/pkg/harfbuzz/build.zig @@ -103,7 +103,14 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu .linkage = .static, }); lib.linkLibC(); - lib.linkLibCpp(); + // On MSVC, we must not use linkLibCpp because Zig unconditionally + // passes -nostdinc++ and then adds its bundled libc++/libc++abi + // include paths, which conflict with MSVC's own C++ runtime headers. + // The MSVC SDK include directories (added via linkLibC) contain + // both C and C++ headers, so linkLibCpp is not needed. + if (target.result.abi != .msvc) { + lib.linkLibCpp(); + } if (target.result.os.tag.isDarwin()) { try apple_sdk.addPaths(b, lib); diff --git a/pkg/spirv-cross/build.zig b/pkg/spirv-cross/build.zig index f85e74adf..72ce61eb6 100644 --- a/pkg/spirv-cross/build.zig +++ b/pkg/spirv-cross/build.zig @@ -58,7 +58,14 @@ fn buildSpirvCross( .linkage = .static, }); lib.linkLibC(); - lib.linkLibCpp(); + // On MSVC, we must not use linkLibCpp because Zig unconditionally + // passes -nostdinc++ and then adds its bundled libc++/libc++abi + // include paths, which conflict with MSVC's own C++ runtime headers. + // The MSVC SDK include directories (added via linkLibC) contain + // both C and C++ headers, so linkLibCpp is not needed. + if (target.result.abi != .msvc) { + lib.linkLibCpp(); + } if (target.result.os.tag.isDarwin()) { const apple_sdk = @import("apple_sdk"); try apple_sdk.addPaths(b, lib);