diff --git a/pkgs/development/compilers/llvm/10/libcxx/default.nix b/pkgs/development/compilers/llvm/10/libcxx/default.nix index 6a4e645bb3004..0c0f535f7433e 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 $(${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 ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/10/libcxxabi/default.nix b/pkgs/development/compilers/llvm/10/libcxxabi/default.nix index b046e627d8313..d62422fc9a12a 100644 --- a/pkgs/development/compilers/llvm/10/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/10/libcxxabi/default.nix @@ -42,8 +42,10 @@ stdenv.mkDerivation { preInstall = lib.optionalString stdenv.isDarwin '' for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + # Fix up the install name. Preserve the basename, just replace the path. - installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" # this should be done in CMake, but having trouble figuring out # the magic combination of necessary CMake variables @@ -54,7 +56,7 @@ stdenv.mkDerivation { # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes # libcxxabi to sometimes link against a different version of itself. # Here we simply make that second reference point to ourselves. - for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file done done diff --git a/pkgs/development/compilers/llvm/11/libcxx/default.nix b/pkgs/development/compilers/llvm/11/libcxx/default.nix index 2a83b36fc4252..237bbd4e06101 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 $(${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 ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/11/libcxxabi/default.nix b/pkgs/development/compilers/llvm/11/libcxxabi/default.nix index 6b5cf85d1ec37..ed0efe28a170e 100644 --- a/pkgs/development/compilers/llvm/11/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/11/libcxxabi/default.nix @@ -46,8 +46,10 @@ stdenv.mkDerivation { preInstall = lib.optionalString stdenv.isDarwin '' for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + # Fix up the install name. Preserve the basename, just replace the path. - installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" # this should be done in CMake, but having trouble figuring out # the magic combination of necessary CMake variables @@ -58,7 +60,7 @@ stdenv.mkDerivation { # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes # libcxxabi to sometimes link against a different version of itself. # Here we simply make that second reference point to ourselves. - for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file done done diff --git a/pkgs/development/compilers/llvm/12/libcxx/default.nix b/pkgs/development/compilers/llvm/12/libcxx/default.nix index 1386d3680f916..ef90eedb38c98 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 $(${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 ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/12/libcxxabi/default.nix b/pkgs/development/compilers/llvm/12/libcxxabi/default.nix index 3d9a92d9305d3..41c559a52ee8e 100644 --- a/pkgs/development/compilers/llvm/12/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/12/libcxxabi/default.nix @@ -44,8 +44,10 @@ stdenv.mkDerivation { preInstall = lib.optionalString stdenv.isDarwin '' for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + # Fix up the install name. Preserve the basename, just replace the path. - installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" # this should be done in CMake, but having trouble figuring out # the magic combination of necessary CMake variables @@ -56,7 +58,7 @@ stdenv.mkDerivation { # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes # libcxxabi to sometimes link against a different version of itself. # Here we simply make that second reference point to ourselves. - for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file done done diff --git a/pkgs/development/compilers/llvm/13/libcxx/default.nix b/pkgs/development/compilers/llvm/13/libcxx/default.nix index 0ce73ed97af6c..f6b76901de3fe 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 $(${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 ${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/13/libcxxabi/default.nix b/pkgs/development/compilers/llvm/13/libcxxabi/default.nix index 9043c6bff25b8..bced2ccb789f3 100644 --- a/pkgs/development/compilers/llvm/13/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/13/libcxxabi/default.nix @@ -41,8 +41,10 @@ stdenv.mkDerivation rec { preInstall = lib.optionalString stdenv.isDarwin '' for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + # Fix up the install name. Preserve the basename, just replace the path. - installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" # this should be done in CMake, but having trouble figuring out # the magic combination of necessary CMake variables @@ -53,7 +55,7 @@ stdenv.mkDerivation rec { # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes # libcxxabi to sometimes link against a different version of itself. # Here we simply make that second reference point to ourselves. - for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file done done diff --git a/pkgs/development/compilers/llvm/14/libcxx/default.nix b/pkgs/development/compilers/llvm/14/libcxx/default.nix index 0a684782d490a..c623d41f92f61 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 $(${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 ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/14/libcxxabi/default.nix b/pkgs/development/compilers/llvm/14/libcxxabi/default.nix index 26f4c4dba8e42..3be2f964abcd2 100644 --- a/pkgs/development/compilers/llvm/14/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/14/libcxxabi/default.nix @@ -52,8 +52,10 @@ stdenv.mkDerivation rec { installPhase = if stdenv.isDarwin then '' for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + # Fix up the install name. Preserve the basename, just replace the path. - installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" # this should be done in CMake, but having trouble figuring out # the magic combination of necessary CMake variables @@ -64,7 +66,7 @@ stdenv.mkDerivation rec { # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes # libcxxabi to sometimes link against a different version of itself. # Here we simply make that second reference point to ourselves. - for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file done done diff --git a/pkgs/development/compilers/llvm/5/libcxx/default.nix b/pkgs/development/compilers/llvm/5/libcxx/default.nix index 44026fba187b7..a5a86fcab4d06 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 $(${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 ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/5/libcxxabi/default.nix b/pkgs/development/compilers/llvm/5/libcxxabi/default.nix index 925c8947ccf51..97077ac771125 100644 --- a/pkgs/development/compilers/llvm/5/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/5/libcxxabi/default.nix @@ -27,8 +27,10 @@ stdenv.mkDerivation { preInstall = lib.optionalString stdenv.isDarwin '' for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + # Fix up the install name. Preserve the basename, just replace the path. - installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" # this should be done in CMake, but having trouble figuring out # the magic combination of necessary CMake variables @@ -39,7 +41,7 @@ stdenv.mkDerivation { # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes # libcxxabi to sometimes link against a different version of itself. # Here we simply make that second reference point to ourselves. - for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file done done diff --git a/pkgs/development/compilers/llvm/6/libcxx/default.nix b/pkgs/development/compilers/llvm/6/libcxx/default.nix index 7077081c59173..a6e723753ef8c 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 $(${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 ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/6/libcxxabi/default.nix b/pkgs/development/compilers/llvm/6/libcxxabi/default.nix index 3371a8ba1a158..aea126b31d9f3 100644 --- a/pkgs/development/compilers/llvm/6/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/6/libcxxabi/default.nix @@ -27,8 +27,10 @@ stdenv.mkDerivation { preInstall = lib.optionalString stdenv.isDarwin '' for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + # Fix up the install name. Preserve the basename, just replace the path. - installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" # this should be done in CMake, but having trouble figuring out # the magic combination of necessary CMake variables @@ -39,7 +41,7 @@ stdenv.mkDerivation { # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes # libcxxabi to sometimes link against a different version of itself. # Here we simply make that second reference point to ourselves. - for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file done done diff --git a/pkgs/development/compilers/llvm/7/libcxx/default.nix b/pkgs/development/compilers/llvm/7/libcxx/default.nix index 07d84432d4220..145f0df8837c7 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 $(${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 ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/7/libcxxabi/default.nix b/pkgs/development/compilers/llvm/7/libcxxabi/default.nix index 8be9690f5f40a..d6f90634cd0b6 100644 --- a/pkgs/development/compilers/llvm/7/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/7/libcxxabi/default.nix @@ -46,8 +46,10 @@ stdenv.mkDerivation { preInstall = lib.optionalString stdenv.isDarwin '' for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + # Fix up the install name. Preserve the basename, just replace the path. - installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" # this should be done in CMake, but having trouble figuring out # the magic combination of necessary CMake variables @@ -58,7 +60,7 @@ stdenv.mkDerivation { # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes # libcxxabi to sometimes link against a different version of itself. # Here we simply make that second reference point to ourselves. - for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file done done diff --git a/pkgs/development/compilers/llvm/8/libcxx/default.nix b/pkgs/development/compilers/llvm/8/libcxx/default.nix index 5368011292186..4a078ac9cda3c 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 $(${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 ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/8/libcxxabi/default.nix b/pkgs/development/compilers/llvm/8/libcxxabi/default.nix index 6b4de0786b984..ab2d46f40a479 100644 --- a/pkgs/development/compilers/llvm/8/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/8/libcxxabi/default.nix @@ -42,8 +42,10 @@ stdenv.mkDerivation { preInstall = lib.optionalString stdenv.isDarwin '' for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + # Fix up the install name. Preserve the basename, just replace the path. - installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" # this should be done in CMake, but having trouble figuring out # the magic combination of necessary CMake variables @@ -54,7 +56,7 @@ stdenv.mkDerivation { # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes # libcxxabi to sometimes link against a different version of itself. # Here we simply make that second reference point to ourselves. - for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file done done diff --git a/pkgs/development/compilers/llvm/9/libcxx/default.nix b/pkgs/development/compilers/llvm/9/libcxx/default.nix index 31a00ba548591..65441c359d609 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 $(${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 ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/9/libcxxabi/default.nix b/pkgs/development/compilers/llvm/9/libcxxabi/default.nix index b7c0c2b0475ae..cfd1c32abd00e 100644 --- a/pkgs/development/compilers/llvm/9/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/9/libcxxabi/default.nix @@ -42,8 +42,10 @@ stdenv.mkDerivation { preInstall = lib.optionalString stdenv.isDarwin '' for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + # Fix up the install name. Preserve the basename, just replace the path. - installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" # this should be done in CMake, but having trouble figuring out # the magic combination of necessary CMake variables @@ -54,7 +56,7 @@ stdenv.mkDerivation { # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes # libcxxabi to sometimes link against a different version of itself. # Here we simply make that second reference point to ourselves. - for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file done done diff --git a/pkgs/development/compilers/llvm/git/libcxx/default.nix b/pkgs/development/compilers/llvm/git/libcxx/default.nix index 5e1f875bf338f..95e32041037a4 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 $(${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 ${libcxxabi}/lib/$abiName $file + done + done + ''; + passthru = { isLLVM = true; }; diff --git a/pkgs/development/compilers/llvm/git/libcxxabi/default.nix b/pkgs/development/compilers/llvm/git/libcxxabi/default.nix index 42a811e131b88..804acd6c7451c 100644 --- a/pkgs/development/compilers/llvm/git/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/git/libcxxabi/default.nix @@ -70,8 +70,10 @@ stdenv.mkDerivation rec { preInstall = lib.optionalString stdenv.isDarwin '' for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + # Fix up the install name. Preserve the basename, just replace the path. - installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" # this should be done in CMake, but having trouble figuring out # the magic combination of necessary CMake variables @@ -82,7 +84,7 @@ stdenv.mkDerivation rec { # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes # libcxxabi to sometimes link against a different version of itself. # Here we simply make that second reference point to ourselves. - for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file done done