diff options
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/llvm/12/libcxx/default.nix')
-rw-r--r-- | nixpkgs/pkgs/development/compilers/llvm/12/libcxx/default.nix | 144 |
1 files changed, 102 insertions, 42 deletions
diff --git a/nixpkgs/pkgs/development/compilers/llvm/12/libcxx/default.nix b/nixpkgs/pkgs/development/compilers/llvm/12/libcxx/default.nix index 67e2aed35cb6..7c6174711456 100644 --- a/nixpkgs/pkgs/development/compilers/llvm/12/libcxx/default.nix +++ b/nixpkgs/pkgs/development/compilers/llvm/12/libcxx/default.nix @@ -1,68 +1,128 @@ -{ lib, stdenv, llvm_meta, fetch, cmake, python3, llvm, fixDarwinDylibNames, version -, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi -, libcxxabi, libcxxrt +{ lib, stdenv, llvm_meta +, fetchFromGitHub, runCommand, substitute +, cmake, lndir, ninja, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null +, libcxxrt, libunwind , enableShared ? !stdenv.hostPlatform.isStatic }: -assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi"; +# external cxxabi is not supported on Darwin as the build will not link libcxx +# properly and not re-export the cxxabi symbols into libcxx +# https://github.com/NixOS/nixpkgs/issues/166205 +# https://github.com/NixOS/nixpkgs/issues/269548 +assert cxxabi == null || !stdenv.hostPlatform.isDarwin; +let + basename = "libcxx"; + cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}"; + runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi"; -stdenv.mkDerivation { - pname = "libcxx"; - inherit version; + # Note: useLLVM is likely false for Darwin but true under pkgsLLVM + useLLVM = stdenv.hostPlatform.useLLVM or false; - src = fetch "libcxx" "05cx39ldlxchck454lgfly1xj0c7x65iyx4hqhiihrlg6p6qj854"; + cxxabiCMakeFlags = lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ + "-DLIBCXXABI_USE_COMPILER_RT=ON" + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; - postUnpack = '' - unpackFile ${libcxxabi.src} - mv libcxxabi-* libcxxabi - unpackFile ${llvm.src} - mv llvm-* llvm - ''; + cxxCMakeFlags = [ + "-DLIBCXX_CXX_ABI=${cxxabiName}" + ] ++ lib.optionals (cxxabi != null) [ + "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" + ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ + "-DLIBCXX_HAS_MUSL_LIBC=1" + ] ++ lib.optionals useLLVM [ + "-DLIBCXX_USE_COMPILER_RT=ON" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXX_ENABLE_SHARED=OFF" + ]; + + cmakeFlags = [ + "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" + ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ + # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, + # but that does not appear to be the case for example when building + # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). + "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" + "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker + ] ++ cxxCMakeFlags + ++ lib.optionals (cxxabi == null) cxxabiCMakeFlags; + +in + +stdenv.mkDerivation rec { + pname = basename; + inherit version cmakeFlags; + + src = fetchFromGitHub { + owner = "llvm"; + repo = "llvm-project"; + rev = "refs/tags/llvmorg-${version}"; + sparseCheckout = [ + "libcxx" + "libcxxabi" + "llvm/cmake" + "llvm/utils" + "runtimes" + ]; + hash = "sha256-etxgXIdWxMTmbZ83Hsc0w6Jt5OSQSUEPVEWqLkHsNBY="; + }; outputs = [ "out" "dev" ]; patches = [ - ./gnu-install-dirs.patch + (substitute { + src = ../../common/libcxxabi/wasm.patch; + replacements = [ + "--replace-fail" "/cmake/" "/llvm/cmake/" + ]; + }) ] ++ lib.optionals stdenv.hostPlatform.isMusl [ - ../../common/libcxx/libcxx-0001-musl-hacks.patch + (substitute { + src = ../../common/libcxx/libcxx-0001-musl-hacks.patch; + replacements = [ + "--replace-fail" "/include/" "/libcxx/include/" + ]; + }) ]; + postPatch = '' + cd runtimes + ''; + preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' patchShebangs utils/cat_files.py ''; - nativeBuildInputs = [ cmake python3 ] - ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; + nativeBuildInputs = [ cmake ninja python3 ] + ++ lib.optional stdenv.isDarwin fixDarwinDylibNames + ++ lib.optional (cxxabi != null) lndir; - buildInputs = [ cxxabi ]; + buildInputs = [ cxxabi ] + ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ libunwind ]; - cmakeFlags = [ - "-DLIBCXX_CXX_ABI=${cxxabi.pname}" - ] ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" - ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" - ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXX_ENABLE_THREADS=OFF" - "-DLIBCXX_ENABLE_FILESYSTEM=OFF" - "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; - - preInstall = lib.optionalString (stdenv.isDarwin) '' - for file in lib/*.dylib; do - if [ -L "$file" ]; then continue; fi - - baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1)) - installName="$out/lib/$baseName" - abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') - - for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do - ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file - done - done + # 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) '' + lndir ${lib.getDev cxxabi}/include $out/include/c++/v1 + lndir ${lib.getLib cxxabi}/lib $out/lib ''; passthru = { isLLVM = true; - inherit cxxabi; }; meta = llvm_meta // { |