Skip to content

Commit ca59a20

Browse files
committed
llvmPackages_15.libcxx: use clang 15 instead of the stdenv's compiler
libc++ has switched to using `__attribute__((using_if_exists))` to handle incomplete libc implementations; see: llvm/llvm-project@a9c9183 These essentially require a modern C++ compiler (clang gained support in LLVM 13: llvm/llvm-project@369c648, gcc appears to not have support yet: https://gcc.gnu.org/bugzilla//show_bug.cgi?id=105584). Previously this was not an issue for us (despite the transition happening around LLVM 13) but something about the changes to the libc++/libc++-abi build has made it so that on platforms with incomplete libc impls (i.e. Darwin is missing `quick_exit`/`at_quick_exit`) we error during the `libcxx-abi` build when the stdenv's (older, not supporting `using_if_exists`) compiler tries to import libc symbols that aren't present. The libc++ docs suggest we use a modern compiler to build libc++ anyways (https://releases.llvm.org/15.0.0/projects/libcxx/docs/index.html#platform-and-compiler-support) so this commit uses stdenv's containing the package set's clang to build libcxx/libcxx-abi. This is similar to how libc++ bootstrapping builds (https://releases.llvm.org/15.0.0/projects/libcxx/docs/BuildingLibcxx.html#bootstrapping-build) work.
1 parent 4fabcf4 commit ca59a20

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

pkgs/development/compilers/llvm/15/default.nix

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,27 +247,39 @@ let
247247

248248
libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
249249

250-
libcxx = callPackage ./libcxx {
251-
inherit llvm_meta;
252-
stdenv = if stdenv.hostPlatform.useLLVM or false
253-
then overrideCC stdenv buildLlvmTools.clangNoLibcxx
254-
else stdenv;
255-
};
256-
257250
libcxxabi = let
258-
stdenv_ = if stdenv.hostPlatform.useLLVM or false
259-
then overrideCC stdenv buildLlvmTools.clangNoLibcxx
260-
else stdenv;
251+
# CMake will "require" a compiler capable of compiling C++ programs
252+
# cxx-header's build does not actually use one so it doesn't really matter
253+
# what stdenv we use here, as long as CMake is happy.
261254
cxx-headers = callPackage ./libcxx {
262255
inherit llvm_meta;
263-
stdenv = stdenv_;
264256
headersOnly = true;
265257
};
258+
259+
# `libcxxabi` *doesn't* need a compiler with a working C++ stdlib but it
260+
# *does* need a relatively modern C++ compiler (see:
261+
# https://releases.llvm.org/15.0.0/projects/libcxx/docs/index.html#platform-and-compiler-support).
262+
#
263+
# So, we use the clang from this LLVM package set, like libc++
264+
# "boostrapping builds" do:
265+
# https://releases.llvm.org/15.0.0/projects/libcxx/docs/BuildingLibcxx.html#bootstrapping-build
266+
#
267+
# We cannot use `clangNoLibcxx` because that contains `compiler-rt` which,
268+
# on macOS, depends on `libcxxabi`, thus forming a cycle.
269+
stdenv_ = overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc;
266270
in callPackage ./libcxxabi {
267271
stdenv = stdenv_;
268272
inherit llvm_meta cxx-headers;
269273
};
270274

275+
# Like `libcxxabi` above, `libcxx` requires a fairly modern C++ compiler,
276+
# so: we use the clang from this LLVM package set instead of the regular
277+
# stdenv's compiler.
278+
libcxx = callPackage ./libcxx {
279+
inherit llvm_meta;
280+
stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
281+
};
282+
271283
libunwind = callPackage ./libunwind {
272284
inherit llvm_meta;
273285
stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;

pkgs/development/compilers/llvm/15/libcxxabi/default.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ stdenv.mkDerivation rec {
5858
cmakeFlags = [
5959
"-DLLVM_ENABLE_RUNTIMES=libcxxabi"
6060
"-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1"
61+
62+
# `libcxxabi`'s build does not need a toolchain with a c++ stdlib attached
63+
# (we specify the headers it should use explicitly above).
64+
#
65+
# CMake however checks for this anyways; this flag tells it not to. See:
66+
# https://github.com/llvm/llvm-project/blob/4bd3f3759259548e159aeba5c76efb9a0864e6fa/llvm/runtimes/CMakeLists.txt#L243
67+
"-DCMAKE_CXX_COMPILER_WORKS=ON"
6168
] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
6269
"-DLLVM_ENABLE_LIBCXX=ON"
6370
"-DLIBCXXABI_USE_LLVM_UNWINDER=ON"

0 commit comments

Comments
 (0)