···6868 ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
6969 "-DLLVM_ENABLE_LIBCXX=ON"
7070 "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
7171+ ] ++ lib.optionals ((stdenv.hostPlatform.useLLVM or false) ||
7272+ (stdenv.hostPlatform.isDarwin && enableShared)) [
7373+ # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib,
7474+ # but that does not appear to be the case for example when building
7575+ # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc).
7676+ "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib"
7777+ "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib"
7178 ] ++ lib.optionals stdenv.hostPlatform.isWasm [
7279 "-DLIBCXXABI_ENABLE_THREADS=OFF"
7380 "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
···3232 ++ lib.optional stdenv.isDarwin xcbuild.xcrun;
3333 buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi;
34343535- env.NIX_CFLAGS_COMPILE = toString [
3535+ env.NIX_CFLAGS_COMPILE = toString ([
3636 "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0"
3737- ];
3737+ ] ++ lib.optionals (!haveLibc) [
3838+ # The compiler got stricter about this, and there is a usellvm patch below
3939+ # which patches out the assert include causing an implicit definition of
4040+ # assert. It would be nicer to understand why compiler-rt thinks it should
4141+ # be able to #include <assert.h> in the first place; perhaps it's in the
4242+ # wrong, or perhaps there is a way to provide an assert.h.
4343+ "-Wno-error=implicit-function-declaration"
4444+ ]);
38453946 cmakeFlags = [
4047 "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON"
···102109 '' + lib.optionalString stdenv.isDarwin ''
103110 substituteInPlace cmake/config-ix.cmake \
104111 --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
105105- '' + lib.optionalString (useLLVM) ''
112112+ '' + lib.optionalString (useLLVM && !haveLibc) ''
106113 substituteInPlace lib/builtins/int_util.c \
107114 --replace "#include <stdlib.h>" ""
108115 substituteInPlace lib/builtins/clear_cache.c \
···117124 '' + lib.optionalString (useLLVM) ''
118125 ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o
119126 ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o
127127+ # Note the history of crt{begin,end}S in previous versions of llvm in nixpkg:
128128+ # The presence of crtbegin_shared has been added and removed; it's possible
129129+ # people have added/removed it to get it working on their platforms.
130130+ # Try each in turn for now.
131131+ ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o
132132+ ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o
120133 ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o
121134 ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o
122135 '' + lib.optionalString doFakeLibgcc ''
+8
pkgs/development/compilers/llvm/16/default.nix
···254254 [ "-rtlib=compiler-rt"
255255 "-Wno-unused-command-line-argument"
256256 "-B${targetLlvmLibraries.compiler-rt}/lib"
257257+258258+ # Combat "__cxxabi_config.h not found". Maybe this could be fixed by
259259+ # copying these headers into libcxx? Note that building libcxx
260260+ # outside of monorepo isn't supported anymore, might be related to
261261+ # https://github.com/llvm/llvm-project/issues/55632
262262+ # ("16.0.3 libcxx, libcxxabi: circular build dependencies")
263263+ # Looks like the machinery changed in https://reviews.llvm.org/D120727.
264264+ "-I${lib.getDev targetLlvmLibraries.libcxx.cxxabi}/include/c++/v1"
257265 ]
258266 ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind"
259267 ++ lib.optional
···6868 ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
6969 "-DLLVM_ENABLE_LIBCXX=ON"
7070 "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
7171+ ] ++ lib.optionals ((stdenv.hostPlatform.useLLVM or false) ||
7272+ (stdenv.hostPlatform.isDarwin && enableShared)) [
7373+ # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib,
7474+ # but that does not appear to be the case for example when building
7575+ # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc).
7676+ "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib"
7777+ "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib"
7178 ] ++ lib.optionals stdenv.hostPlatform.isWasm [
7279 "-DLIBCXXABI_ENABLE_THREADS=OFF"
7380 "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
···313313 # what stdenv we use here, as long as CMake is happy.
314314 cxx-headers = callPackage ./libcxx {
315315 inherit llvm_meta;
316316+ # Note that if we use the regular stdenv here we'll get cycle errors
317317+ # when attempting to use this compiler in the stdenv.
318318+ #
319319+ # The final stdenv pulls `cxx-headers` from the package set where
320320+ # hostPlatform *is* the target platform which means that `stdenv` at
321321+ # that point attempts to use this toolchain.
322322+ #
323323+ # So, we use `stdenv_` (the stdenv containing `clang` from this package
324324+ # set, defined below) to sidestep this issue.
325325+ #
326326+ # Because we only use `cxx-headers` in `libcxxabi` (which depends on the
327327+ # clang stdenv _anyways_), this is okay.
328328+ stdenv = stdenv_;
316329 headersOnly = true;
317330 };
318331
···6868 ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
6969 "-DLLVM_ENABLE_LIBCXX=ON"
7070 "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
7171+ ] ++ lib.optionals ((stdenv.hostPlatform.useLLVM or false) ||
7272+ (stdenv.hostPlatform.isDarwin && enableShared)) [
7373+ # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib,
7474+ # but that does not appear to be the case for example when building
7575+ # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc).
7676+ "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib"
7777+ "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib"
7178 ] ++ lib.optionals stdenv.hostPlatform.isWasm [
7279 "-DLIBCXXABI_ENABLE_THREADS=OFF"
7380 "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"