Skip to content

macos stage3: add link support for system libc++ #23264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,17 @@ fn addCmakeCfgOptionsToExe(
mod.linkSystemLibrary("unwind", .{});
},
.ios, .macos, .watchos, .tvos, .visionos => {
mod.link_libcpp = true;
if (static or !std.zig.system.darwin.isSdkInstalled(b.allocator)) {
mod.link_libcpp = true;
Comment on lines +785 to +786

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per my comment here, it's probably still worth rethinking linking to the vendored libc++ when you are using a third-party LLVM (i.e. one built not using the vendored libc++).

} else {
// Avoid using `mod.linkSystemLibrary()`, which:
// - is semantically equivalent to `-lc++`
// - and enables `mod.link_libcpp`
// Instead, add the full object pathname.
Comment on lines +788 to +791
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thank you. This reveals a contradiction in this implementation:

  • by checking for the string "c++", linkSystemLibrary reveals an assumption that there is only one possible way to link libc++.
  • The entire point of this patch rests on the assumption that there are multiple ways to link libc++.

Instead of working around it, the build system should be modified to recognize that there are two choices when linking libc++, because the logic that makes my code snippet not work for this use case is based on this incorrect assumption.

Then, my simpler code snippet which does not rely on something that requires access outside of a build sandbox (#14286) will work correctly.

const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse return error.SdkDetectFailed;
const libcxx = b.pathJoin(&.{ sdk, "usr/lib/libc++.tbd" });
exe.root_module.addObjectFile(.{ .cwd_relative = libcxx });
}
},
.windows => {
if (target.abi != .msvc) mod.link_libcpp = true;
Expand Down
Loading