diff --git a/pkgs/development/compilers/llvm/common/libcxx/default.nix b/pkgs/development/compilers/llvm/common/libcxx/default.nix index 0e91f50551c55..caaec47569893 100644 --- a/pkgs/development/compilers/llvm/common/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/common/libcxx/default.nix @@ -123,9 +123,30 @@ stdenv.mkDerivation (rec { # libc++.so is a linker script which expands to multiple libraries, # libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't # support linker scripts so the external cxxabi needs to be symlinked in - postInstall = lib.optionalString (cxxabi != null) '' + postInstall = '' + libcxxabi=$out/lib/libc++abi.a + '' + lib.optionalString (cxxabi != null) '' lndir ${lib.getDev cxxabi}/include $dev/include/c++/v1 lndir ${lib.getLib cxxabi}/lib $out/lib + libcxxabi=$out/lib/lib${cxxabi.libName}.a + '' + # LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON doesn't work for LLVM < 16 or + # external cxxabi libraries so merge libc++abi.a into libc++.a ourselves. + + '' + if [[ -f $out/lib/libc++.a && -e $libcxxabi ]]; then + scratch="$(mktemp -d)" + mv $out/lib/libc++.a $scratch/libcxx.a + cp -d $libcxxabi $scratch/libcxxabi.a + $AR -M <&2 || echo "failed" >&2 ''} + ${lib.optionalString isCxx '' + echo "checking whether can link with libc++... " >&2 + $CXX ${./cxx-main.cc} -c -o cxx-main.o + $CC cxx-main.o -lc++ -o cxx-main + $CC cxx-main.o -l:libc++.a -o cxx-main-static + ${emulator} ./cxx-main + ${emulator} ./cxx-main-static + rm cxx-main{,-static,.o} + ''} + ${lib.optionalString (stdenv.isDarwin && stdenv.cc.isClang) '' echo "checking whether compiler can build with CoreFoundation.framework... " >&2 mkdir -p foo/lib