Skip to content

Commit

Permalink
libcxx: Link libc++.dylib to matching libc++abi.dylib
Browse files Browse the repository at this point in the history
Same adjustment as made for libc++abi in NixOS#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: NixOS#185766
  • Loading branch information
joshchngs committed Nov 15, 2022
1 parent a9bd291 commit 120b99e
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkgs/development/compilers/llvm/10/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
14 changes: 14 additions & 0 deletions pkgs/development/compilers/llvm/11/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
14 changes: 14 additions & 0 deletions pkgs/development/compilers/llvm/12/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
14 changes: 14 additions & 0 deletions pkgs/development/compilers/llvm/13/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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) ''
Expand Down
14 changes: 14 additions & 0 deletions pkgs/development/compilers/llvm/14/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
14 changes: 14 additions & 0 deletions pkgs/development/compilers/llvm/5/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
14 changes: 14 additions & 0 deletions pkgs/development/compilers/llvm/6/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
14 changes: 14 additions & 0 deletions pkgs/development/compilers/llvm/7/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
14 changes: 14 additions & 0 deletions pkgs/development/compilers/llvm/8/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
14 changes: 14 additions & 0 deletions pkgs/development/compilers/llvm/9/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
14 changes: 14 additions & 0 deletions pkgs/development/compilers/llvm/git/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 120b99e

Please sign in to comment.