···257257258258 libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
259259260260- libcxx = callPackage ./libcxx {
261261- inherit llvm_meta;
262262- stdenv = if stdenv.hostPlatform.useLLVM or false
263263- then overrideCC stdenv buildLlvmTools.clangNoLibcxx
264264- else stdenv;
265265- };
266266-267260 libcxxabi = let
268268- stdenv_ = if stdenv.hostPlatform.useLLVM or false
269269- then overrideCC stdenv buildLlvmTools.clangNoLibcxx
270270- else stdenv;
261261+ # CMake will "require" a compiler capable of compiling C++ programs
262262+ # cxx-header's build does not actually use one so it doesn't really matter
263263+ # what stdenv we use here, as long as CMake is happy.
271264 cxx-headers = callPackage ./libcxx {
272265 inherit llvm_meta;
273273- stdenv = stdenv_;
274266 headersOnly = true;
275267 };
268268+269269+ # `libcxxabi` *doesn't* need a compiler with a working C++ stdlib but it
270270+ # *does* need a relatively modern C++ compiler (see:
271271+ # https://releases.llvm.org/15.0.0/projects/libcxx/docs/index.html#platform-and-compiler-support).
272272+ #
273273+ # So, we use the clang from this LLVM package set, like libc++
274274+ # "boostrapping builds" do:
275275+ # https://releases.llvm.org/15.0.0/projects/libcxx/docs/BuildingLibcxx.html#bootstrapping-build
276276+ #
277277+ # We cannot use `clangNoLibcxx` because that contains `compiler-rt` which,
278278+ # on macOS, depends on `libcxxabi`, thus forming a cycle.
279279+ stdenv_ = overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc;
276280 in callPackage ./libcxxabi {
277281 stdenv = stdenv_;
278282 inherit llvm_meta cxx-headers;
283283+ };
284284+285285+ # Like `libcxxabi` above, `libcxx` requires a fairly modern C++ compiler,
286286+ # so: we use the clang from this LLVM package set instead of the regular
287287+ # stdenv's compiler.
288288+ libcxx = callPackage ./libcxx {
289289+ inherit llvm_meta;
290290+ stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
279291 };
280292281293 libunwind = callPackage ./libunwind {
···5858 cmakeFlags = [
5959 "-DLLVM_ENABLE_RUNTIMES=libcxxabi"
6060 "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1"
6161+6262+ # `libcxxabi`'s build does not need a toolchain with a c++ stdlib attached
6363+ # (we specify the headers it should use explicitly above).
6464+ #
6565+ # CMake however checks for this anyways; this flag tells it not to. See:
6666+ # https://github.com/llvm/llvm-project/blob/4bd3f3759259548e159aeba5c76efb9a0864e6fa/llvm/runtimes/CMakeLists.txt#L243
6767+ "-DCMAKE_CXX_COMPILER_WORKS=ON"
6168 ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
6269 "-DLLVM_ENABLE_LIBCXX=ON"
6370 "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"