···257258 libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
2590000000260 libcxxabi = let
261+ # CMake will "require" a compiler capable of compiling C++ programs
262+ # cxx-header's build does not actually use one so it doesn't really matter
263+ # what stdenv we use here, as long as CMake is happy.
264 cxx-headers = callPackage ./libcxx {
265 inherit llvm_meta;
0266 headersOnly = true;
267 };
268+269+ # `libcxxabi` *doesn't* need a compiler with a working C++ stdlib but it
270+ # *does* need a relatively modern C++ compiler (see:
271+ # https://releases.llvm.org/15.0.0/projects/libcxx/docs/index.html#platform-and-compiler-support).
272+ #
273+ # So, we use the clang from this LLVM package set, like libc++
274+ # "boostrapping builds" do:
275+ # https://releases.llvm.org/15.0.0/projects/libcxx/docs/BuildingLibcxx.html#bootstrapping-build
276+ #
277+ # We cannot use `clangNoLibcxx` because that contains `compiler-rt` which,
278+ # on macOS, depends on `libcxxabi`, thus forming a cycle.
279+ stdenv_ = overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc;
280 in callPackage ./libcxxabi {
281 stdenv = stdenv_;
282 inherit llvm_meta cxx-headers;
283+ };
284+285+ # Like `libcxxabi` above, `libcxx` requires a fairly modern C++ compiler,
286+ # so: we use the clang from this LLVM package set instead of the regular
287+ # stdenv's compiler.
288+ libcxx = callPackage ./libcxx {
289+ inherit llvm_meta;
290+ stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
291 };
292293 libunwind = callPackage ./libunwind {
···58 cmakeFlags = [
59 "-DLLVM_ENABLE_RUNTIMES=libcxxabi"
60 "-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"
68 ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
69 "-DLLVM_ENABLE_LIBCXX=ON"
70 "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"