···68 ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
69 "-DLLVM_ENABLE_LIBCXX=ON"
70 "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
71+ ] ++ lib.optionals ((stdenv.hostPlatform.useLLVM or false) ||
72+ (stdenv.hostPlatform.isDarwin && enableShared)) [
73+ # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib,
74+ # but that does not appear to be the case for example when building
75+ # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc).
76+ "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib"
77+ "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib"
78 ] ++ lib.optionals stdenv.hostPlatform.isWasm [
79 "-DLIBCXXABI_ENABLE_THREADS=OFF"
80 "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
···32 ++ lib.optional stdenv.isDarwin xcbuild.xcrun;
33 buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi;
3435+ env.NIX_CFLAGS_COMPILE = toString ([
36 "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0"
37+ ] ++ lib.optionals (!haveLibc) [
38+ # The compiler got stricter about this, and there is a usellvm patch below
39+ # which patches out the assert include causing an implicit definition of
40+ # assert. It would be nicer to understand why compiler-rt thinks it should
41+ # be able to #include <assert.h> in the first place; perhaps it's in the
42+ # wrong, or perhaps there is a way to provide an assert.h.
43+ "-Wno-error=implicit-function-declaration"
44+ ]);
4546 cmakeFlags = [
47 "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON"
···109 '' + lib.optionalString stdenv.isDarwin ''
110 substituteInPlace cmake/config-ix.cmake \
111 --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
112+ '' + lib.optionalString (useLLVM && !haveLibc) ''
113 substituteInPlace lib/builtins/int_util.c \
114 --replace "#include <stdlib.h>" ""
115 substituteInPlace lib/builtins/clear_cache.c \
···124 '' + lib.optionalString (useLLVM) ''
125 ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o
126 ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o
127+ # Note the history of crt{begin,end}S in previous versions of llvm in nixpkg:
128+ # The presence of crtbegin_shared has been added and removed; it's possible
129+ # people have added/removed it to get it working on their platforms.
130+ # Try each in turn for now.
131+ ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o
132+ ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o
133 ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o
134 ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o
135 '' + lib.optionalString doFakeLibgcc ''
···254 [ "-rtlib=compiler-rt"
255 "-Wno-unused-command-line-argument"
256 "-B${targetLlvmLibraries.compiler-rt}/lib"
257+258+ # Combat "__cxxabi_config.h not found". Maybe this could be fixed by
259+ # copying these headers into libcxx? Note that building libcxx
260+ # outside of monorepo isn't supported anymore, might be related to
261+ # https://github.com/llvm/llvm-project/issues/55632
262+ # ("16.0.3 libcxx, libcxxabi: circular build dependencies")
263+ # Looks like the machinery changed in https://reviews.llvm.org/D120727.
264+ "-I${lib.getDev targetLlvmLibraries.libcxx.cxxabi}/include/c++/v1"
265 ]
266 ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind"
267 ++ lib.optional
···68 ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
69 "-DLLVM_ENABLE_LIBCXX=ON"
70 "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
71+ ] ++ lib.optionals ((stdenv.hostPlatform.useLLVM or false) ||
72+ (stdenv.hostPlatform.isDarwin && enableShared)) [
73+ # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib,
74+ # but that does not appear to be the case for example when building
75+ # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc).
76+ "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib"
77+ "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib"
78 ] ++ lib.optionals stdenv.hostPlatform.isWasm [
79 "-DLIBCXXABI_ENABLE_THREADS=OFF"
80 "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
···313 # what stdenv we use here, as long as CMake is happy.
314 cxx-headers = callPackage ./libcxx {
315 inherit llvm_meta;
0000000000000316 headersOnly = true;
317 };
318
···313 # what stdenv we use here, as long as CMake is happy.
314 cxx-headers = callPackage ./libcxx {
315 inherit llvm_meta;
316+ # Note that if we use the regular stdenv here we'll get cycle errors
317+ # when attempting to use this compiler in the stdenv.
318+ #
319+ # The final stdenv pulls `cxx-headers` from the package set where
320+ # hostPlatform *is* the target platform which means that `stdenv` at
321+ # that point attempts to use this toolchain.
322+ #
323+ # So, we use `stdenv_` (the stdenv containing `clang` from this package
324+ # set, defined below) to sidestep this issue.
325+ #
326+ # Because we only use `cxx-headers` in `libcxxabi` (which depends on the
327+ # clang stdenv _anyways_), this is okay.
328+ stdenv = stdenv_;
329 headersOnly = true;
330 };
331
···68 ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
69 "-DLLVM_ENABLE_LIBCXX=ON"
70 "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
71+ ] ++ lib.optionals ((stdenv.hostPlatform.useLLVM or false) ||
72+ (stdenv.hostPlatform.isDarwin && enableShared)) [
73+ # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib,
74+ # but that does not appear to be the case for example when building
75+ # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc).
76+ "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib"
77+ "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib"
78 ] ++ lib.optionals stdenv.hostPlatform.isWasm [
79 "-DLIBCXXABI_ENABLE_THREADS=OFF"
80 "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"