Skip to content
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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mikdusan
Copy link
Member

  • activates when -DZIG_SHARED_LLVM=ON
  • activates when llvm_config is used and --shared-mode is shared
  • otherwise vendored libc++ is used

closes #23189

- activates when -DZIG_SHARED_LLVM=ON
- activates when llvm_config is used and --shared-mode is shared
- otherwise vendored libc++ is used

closes ziglang#23189
@alexrp alexrp added this to the 0.14.1 milestone Mar 16, 2025
Copy link

@carlocab carlocab left a comment

Choose a reason for hiding this comment

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

Thanks; works great. Shipped in Homebrew as Homebrew/homebrew-core#211129.

Comment on lines +788 to +790
const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse return error.SdkDetectFailed;
const @"libc++" = b.pathJoin(&.{ sdk, "usr/lib/libc++.tbd" });
exe.root_module.addObjectFile(.{ .cwd_relative = @"libc++" });

Choose a reason for hiding this comment

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

Note that you are implicitly assuming that the shared LLVM is linked against the system libc++. That's likely generally true in practice, but in theory one can build their own LLVM and link it against a non-system libc++.

I'm not suggesting that you need to support an LLVM built with a custom libc++. However, it may be worth documenting somewhere that you only support linking to a shared LLVM with the system libc++.

Comment on lines +785 to +786
if (static or !std.zig.system.darwin.isSdkInstalled(b.allocator)) {
mod.link_libcpp = true;

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++).

@i0ntempest
Copy link

Patch pushed to MacPorts: macports/macports-ports@eec7cd1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the ability to dynamically link the system libc++ when installing Zig with a package manager on macOS
4 participants