From 67f11a2185dba0851c520e617526b65d82fb8c5b Mon Sep 17 00:00:00 2001 From: Josh Channings Date: Mon, 14 Nov 2022 01:31:26 +0000 Subject: [PATCH] libcxx: Link libc++.dylib to matching libc++abi.dylib Same adjustment as made for libc++abi in #185766, for the same reason: the unamended dylib links to the libc++abi in the build stdenv, which is the wrong version. Tested on Darwin with LLVM 14 stdenv, but the phase is added to all versions, including 11 - so this will cause a mass rebuild. See: https://github.com/NixOS/nixpkgs/pull/185766 --- .../compilers/llvm/10/libcxx/default.nix | 14 ++++++++++++++ .../compilers/llvm/11/libcxx/default.nix | 14 ++++++++++++++ .../compilers/llvm/12/libcxx/default.nix | 14 ++++++++++++++ .../compilers/llvm/13/libcxx/default.nix | 14 ++++++++++++++ .../compilers/llvm/14/libcxx/default.nix | 14 ++++++++++++++ .../compilers/llvm/5/libcxx/default.nix | 14 ++++++++++++++ .../compilers/llvm/6/libcxx/default.nix | 14 ++++++++++++++ .../compilers/llvm/7/libcxx/default.nix | 14 ++++++++++++++ .../compilers/llvm/8/libcxx/default.nix | 14 ++++++++++++++ .../compilers/llvm/9/libcxx/default.nix | 14 ++++++++++++++ .../compilers/llvm/git/libcxx/default.nix | 14 ++++++++++++++ 11 files changed, 154 insertions(+) diff --git a/pkgs/development/compilers/llvm/10/libcxx/default.nix b/pkgs/development/compilers/llvm/10/libcxx/default.nix index 6a4e645bb300..bf3ddeb58c30 100644 --- a/pkgs/development/compilers/llvm/10/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/10/libcxx/default.nix @@ -51,6 +51,20 @@ stdenv.mkDerivation { "-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 $(otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/11/libcxx/default.nix b/pkgs/development/compilers/llvm/11/libcxx/default.nix index 2a83b36fc425..135fed03beef 100644 --- a/pkgs/development/compilers/llvm/11/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/11/libcxx/default.nix @@ -67,6 +67,20 @@ stdenv.mkDerivation { stdenv.hostPlatform != stdenv.buildPlatform ) "-DCMAKE_SYSTEM_VERSION=20.1.0"; + preInstall = lib.optionalString (stdenv.isDarwin) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/12/libcxx/default.nix b/pkgs/development/compilers/llvm/12/libcxx/default.nix index 1386d3680f91..fdd1690310c5 100644 --- a/pkgs/development/compilers/llvm/12/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/12/libcxx/default.nix @@ -42,6 +42,20 @@ stdenv.mkDerivation { "-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 $(otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/13/libcxx/default.nix b/pkgs/development/compilers/llvm/13/libcxx/default.nix index 0ce73ed97af6..664e593d3de7 100644 --- a/pkgs/development/compilers/llvm/13/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/13/libcxx/default.nix @@ -46,6 +46,20 @@ stdenv.mkDerivation rec { buildFlags = lib.optional headersOnly "generate-cxx-headers"; installTargets = lib.optional headersOnly "install-cxx-headers"; + preInstall = lib.optionalString (stdenv.isDarwin && !headersOnly) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file + done + done + ''; + # At this point, cxxabi headers would be installed in the dev output, which # prevents moveToOutput from doing its job later in the build process. postInstall = lib.optionalString (!headersOnly) '' diff --git a/pkgs/development/compilers/llvm/14/libcxx/default.nix b/pkgs/development/compilers/llvm/14/libcxx/default.nix index 0a684782d490..a637cdbab770 100644 --- a/pkgs/development/compilers/llvm/14/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/14/libcxx/default.nix @@ -62,6 +62,20 @@ stdenv.mkDerivation rec { buildFlags = lib.optional headersOnly "generate-cxx-headers"; installTargets = lib.optional headersOnly "install-cxx-headers"; + preInstall = lib.optionalString (stdenv.isDarwin && !headersOnly) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/5/libcxx/default.nix b/pkgs/development/compilers/llvm/5/libcxx/default.nix index 44026fba187b..f0ed61a153f7 100644 --- a/pkgs/development/compilers/llvm/5/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/5/libcxx/default.nix @@ -41,6 +41,20 @@ stdenv.mkDerivation { "-DLIBCXX_CXX_ABI=libcxxabi" ] ++ lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1"; + preInstall = lib.optionalString (stdenv.isDarwin) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/6/libcxx/default.nix b/pkgs/development/compilers/llvm/6/libcxx/default.nix index 7077081c5917..1eb3b121d500 100644 --- a/pkgs/development/compilers/llvm/6/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/6/libcxx/default.nix @@ -47,6 +47,20 @@ stdenv.mkDerivation { "-DLIBCXX_CXX_ABI=libcxxabi" ] ++ lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1"; + preInstall = lib.optionalString (stdenv.isDarwin) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/7/libcxx/default.nix b/pkgs/development/compilers/llvm/7/libcxx/default.nix index 07d84432d422..b163ceb09f9e 100644 --- a/pkgs/development/compilers/llvm/7/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/7/libcxx/default.nix @@ -52,6 +52,20 @@ stdenv.mkDerivation { ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" ++ 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 $(otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/8/libcxx/default.nix b/pkgs/development/compilers/llvm/8/libcxx/default.nix index 536801129218..db6059e2ea27 100644 --- a/pkgs/development/compilers/llvm/8/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/8/libcxx/default.nix @@ -55,6 +55,20 @@ stdenv.mkDerivation { "-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 $(otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/9/libcxx/default.nix b/pkgs/development/compilers/llvm/9/libcxx/default.nix index 31a00ba54859..6682ec6799b2 100644 --- a/pkgs/development/compilers/llvm/9/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/9/libcxx/default.nix @@ -51,6 +51,20 @@ stdenv.mkDerivation { "-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 $(otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/git/libcxx/default.nix b/pkgs/development/compilers/llvm/git/libcxx/default.nix index 5e1f875bf338..f06459258def 100644 --- a/pkgs/development/compilers/llvm/git/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/git/libcxx/default.nix @@ -76,6 +76,20 @@ stdenv.mkDerivation rec { buildFlags = lib.optional headersOnly "generate-cxx-headers"; installTargets = lib.optional headersOnly "install-cxx-headers"; + preInstall = lib.optionalString (stdenv.isDarwin && !headersOnly) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; };