Skip to content

Commit 3ef44a9

Browse files
committed
macos stage3: add link support for system libc++
- activates when -DZIG_SHARED_LLVM=ON - activates when llvm_config is used and --shared-mode is shared - otherwise vendored libc++ is used closes #23189
1 parent 525466b commit 3ef44a9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

build.zig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,17 @@ fn addCmakeCfgOptionsToExe(
782782
mod.linkSystemLibrary("unwind", .{});
783783
},
784784
.ios, .macos, .watchos, .tvos, .visionos => {
785-
mod.link_libcpp = true;
785+
if (static or !std.zig.system.darwin.isSdkInstalled(b.allocator)) {
786+
mod.link_libcpp = true;
787+
} else {
788+
// Avoid using `mod.linkSystemLibrary()`, which:
789+
// - is semantically equivalent to `-lc++`
790+
// - and enables `mod.link_libcpp`
791+
// Instead, add the full object pathname.
792+
const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse return error.SdkDetectFailed;
793+
const libcxx = b.pathJoin(&.{ sdk, "usr/lib/libc++.tbd" });
794+
exe.root_module.addObjectFile(.{ .cwd_relative = libcxx });
795+
}
786796
},
787797
.windows => {
788798
if (target.abi != .msvc) mod.link_libcpp = true;

0 commit comments

Comments
 (0)