Skip to content

darwin.libcxx: (╯°□°)╯︵ ┻━┻#398727

Merged
emilazy merged 11 commits intoNixOS:stagingfrom
reckenrode:push-tquznrszxwpz
Sep 15, 2025
Merged

darwin.libcxx: (╯°□°)╯︵ ┻━┻#398727
emilazy merged 11 commits intoNixOS:stagingfrom
reckenrode:push-tquznrszxwpz

Conversation

@reckenrode
Copy link
Copy Markdown
Contributor

@reckenrode reckenrode commented Apr 15, 2025

Darwin currently uses libc++ from nixpkgs, but it probably shouldn’t (at least not by default). The libc++ that is built in nixpkgs comes from LLVM. According to Louis Dionne (of Apple and a member of the C++ committee), the libc++ shipped by Apple should be considered distinct from the libc++ in LLVM. We’ve been lucky that we have not had problems with ODR violations. This PR was prompted by leakage of symbols from the system libc++ that started happening with the release of macOS 15.4. It changes a number of things to improve the compatibility of C++ on Darwin.

  • It makes the system libc++ the default C++. The Darwin bootstrap is built against it. The default stdenv uses it. This is done by making the libc++ headers and text-based stubs available from the 15.2 SDK. This is safe to do because using symbols that are not available on your deployment target results in a compile-time error.

Testing

I also confirmed that all of the packages updated in this PR built (except for servo, which is broken due to Darwin having a case-insensitive build location), that Qt 5 and opencv4 built on x86_64-darwin, and that my configs built (except for util-linux, which appears broken again on Darwin).

Breaking Change

The primary points of breakage are as follows:

  • Packages (such as Bazel and MoltenVK) that work around #150655 by referencing libcxx should instead reference stdenv.cc.libcxx. (Those are also fixed in this PR.)
  • The system libc++ expects Clang 16 or newer (due to libc++ support policies). To build with an older Clang, you need to override the SDK used by libc++ to make it use older libc++ headers.
  • overrideLibcxx doesn’t work with the system libc++. If you really need to use it, you should use it with llvmPackages.libcxxStdenv.

Notes about fixed packages

  • Several packages depend on qt6.qtdeclarative, but it doesn’t build. Fixed in #398849.
  • python3Packages.py3exid2 looks for Boost in /usr/local/lib. Fixed in #399005.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: ocaml OCaml is a general-purpose, high-level, multi-paradigm programming language. 6.topic: stdenv Standard environment 6.topic: R R is a programming language for statistical computing and data visualization. 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related labels Apr 15, 2025
@github-actions github-actions bot added the 8.has: documentation This PR adds or changes documentation label Apr 15, 2025
@reckenrode reckenrode force-pushed the push-tquznrszxwpz branch 2 times, most recently from edac098 to 34d2d14 Compare April 15, 2025 01:33
@reckenrode reckenrode force-pushed the push-tquznrszxwpz branch 3 times, most recently from bc18c00 to d111455 Compare April 15, 2025 02:13
@github-actions github-actions bot added 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Apr 15, 2025
@github-actions github-actions bot added the 6.topic: qt/kde Object-oriented framework for GUI creation label Apr 17, 2025
@reckenrode
Copy link
Copy Markdown
Contributor Author

Fixed the signatures. I think I’m going to need to look into Sequoia as a replacement for GnuPG ….

Anyway, I confirmed that all of the packages changed in this PR build except for servo, which fails due to having README.md and Readme.md in one of its vendored crates (i.e., case-insensitive /tmp issues). I also confirmed that both Qt 5 and opencv4 build with their workarounds reverted from the last staging-next cycle.

@reckenrode reckenrode marked this pull request as ready for review April 17, 2025 00:16
@ofborg ofborg bot added the 6.topic: darwin Running or building packages on Darwin label Apr 17, 2025
@booxter booxter mentioned this pull request Apr 18, 2025
13 tasks
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 17, 2025
@reckenrode reckenrode force-pushed the push-tquznrszxwpz branch from 02a2048 to 8e5554e Compare May 30, 2025 00:27
@github-actions github-actions bot removed the 6.topic: python Python is a high-level, general-purpose programming language. label May 30, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 26, 2025
Copy link
Copy Markdown
Member

@emilazy emilazy left a comment

Choose a reason for hiding this comment

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

Needs rebase; otherwise LGTM. Left a comment about the one unresolved thing (version).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

overrideLibcxx in pkgs/stdenv/adapters.nix does, I wonder who we should blame for that? 😆

But since Swift and Qt 5 are the only user (and hopefully Swift won’t be soon? and the Qt 5 one seems dubious to me), that’s hopefully not the end of the world; we can potentially just drop it and the assertion is harmless anyway since 15 > 12.

This is not a blocker for me, but it would be nice for the package name in the store path to be distinguished from an LLVM one, and maybe we can solve both problems at once. Some proposals:

  • libcxx-apple-sdk-15.2
  • libcxx-0-apple-sdk-15.2 (ensures version comparisons will at least fail harder)

I think that ideally, we’d have something like libcxx-⟨closest upstream LLVM version⟩-apple-sdk-⟨macOS SDK version⟩. But it might be hard to reliably determine the corresponding LLVM version, given what Apple’s tree is like.

@github-project-automation github-project-automation bot moved this to In Progress in Stdenv Jul 29, 2025
@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jul 29, 2025
@emilazy emilazy force-pushed the push-tquznrszxwpz branch 2 times, most recently from 088c7a6 to 996bbf6 Compare September 15, 2025 17:34
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 15, 2025
@emilazy emilazy enabled auto-merge September 15, 2025 18:09
@emilazy emilazy disabled auto-merge September 15, 2025 18:09
emilazy and others added 11 commits September 15, 2025 19:24
Adds the headers and text-based stubs for the system libc++.

This package is using the newest available version (currently 15.5)
because libc++ uses static availability checks to prevent using features
not supported by older deployment targets.

Co-authored-by: Emily <vcs@emily.moe>
This reverts commit 04b49f4.

This workaround has a non-trivial cost in build time. Since it’s not
needed when linking against the system libc++, just drop it.
We now use the latest SDK’s libc++ headers, and longer have Clang
versions old enough for version compatibility to be a concern.
Darwin now uses the system libc++ by default, so drop the replacement.
The nixpkgs libc++ is not ABI-compatible with the system libc++, so this
replacement was not guaranteed to work anyway.

See: https://discourse.llvm.org/t/apples-libc-now-provides-std-type-descriptor-t-functionality-not-found-in-upstream-libc/73881/3
The libc++ in nixpkgs is not ABI-compatible with the system libc++, so
replacements are not guaranteed to work.

See: https://discourse.llvm.org/t/apples-libc-now-provides-std-type-descriptor-t-functionality-not-found-in-upstream-libc/73881/3
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. and removed 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Sep 15, 2025
@emilazy emilazy merged commit 1b180b8 into NixOS:staging Sep 15, 2025
28 checks passed
@philiptaron
Copy link
Copy Markdown
Contributor

Woohoo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: darwin Running or building packages on Darwin 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 6.topic: stdenv Standard environment 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants