Skip to content

Commit 67f11a2

Browse files
committed
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: #185766
1 parent 8abde38 commit 67f11a2

11 files changed

Lines changed: 154 additions & 0 deletions

File tree

pkgs/development/compilers/llvm/10/libcxx/default.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ stdenv.mkDerivation {
5151
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
5252
] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF";
5353

54+
preInstall = lib.optionalString (stdenv.isDarwin) ''
55+
for file in lib/*.dylib; do
56+
if [ -L "$file" ]; then continue; fi
57+
58+
baseName=$(basename $(otool -D $file | tail -n 1))
59+
installName="$out/lib/$baseName"
60+
abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/')
61+
62+
for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
63+
${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file
64+
done
65+
done
66+
'';
67+
5468
passthru = {
5569
isLLVM = true;
5670
};

pkgs/development/compilers/llvm/11/libcxx/default.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ stdenv.mkDerivation {
6767
stdenv.hostPlatform != stdenv.buildPlatform
6868
) "-DCMAKE_SYSTEM_VERSION=20.1.0";
6969

70+
preInstall = lib.optionalString (stdenv.isDarwin) ''
71+
for file in lib/*.dylib; do
72+
if [ -L "$file" ]; then continue; fi
73+
74+
baseName=$(basename $(otool -D $file | tail -n 1))
75+
installName="$out/lib/$baseName"
76+
abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/')
77+
78+
for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
79+
${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file
80+
done
81+
done
82+
'';
83+
7084
passthru = {
7185
isLLVM = true;
7286
};

pkgs/development/compilers/llvm/12/libcxx/default.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ stdenv.mkDerivation {
4242
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
4343
] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF";
4444

45+
preInstall = lib.optionalString (stdenv.isDarwin) ''
46+
for file in lib/*.dylib; do
47+
if [ -L "$file" ]; then continue; fi
48+
49+
baseName=$(basename $(otool -D $file | tail -n 1))
50+
installName="$out/lib/$baseName"
51+
abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/')
52+
53+
for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
54+
${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file
55+
done
56+
done
57+
'';
58+
4559
passthru = {
4660
isLLVM = true;
4761
};

pkgs/development/compilers/llvm/13/libcxx/default.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ stdenv.mkDerivation rec {
4646
buildFlags = lib.optional headersOnly "generate-cxx-headers";
4747
installTargets = lib.optional headersOnly "install-cxx-headers";
4848

49+
preInstall = lib.optionalString (stdenv.isDarwin && !headersOnly) ''
50+
for file in lib/*.dylib; do
51+
if [ -L "$file" ]; then continue; fi
52+
53+
baseName=$(basename $(otool -D $file | tail -n 1))
54+
installName="$out/lib/$baseName"
55+
abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/')
56+
57+
for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
58+
${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file
59+
done
60+
done
61+
'';
62+
4963
# At this point, cxxabi headers would be installed in the dev output, which
5064
# prevents moveToOutput from doing its job later in the build process.
5165
postInstall = lib.optionalString (!headersOnly) ''

pkgs/development/compilers/llvm/14/libcxx/default.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ stdenv.mkDerivation rec {
6262
buildFlags = lib.optional headersOnly "generate-cxx-headers";
6363
installTargets = lib.optional headersOnly "install-cxx-headers";
6464

65+
preInstall = lib.optionalString (stdenv.isDarwin && !headersOnly) ''
66+
for file in lib/*.dylib; do
67+
if [ -L "$file" ]; then continue; fi
68+
69+
baseName=$(basename $(otool -D $file | tail -n 1))
70+
installName="$out/lib/$baseName"
71+
abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/')
72+
73+
for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
74+
${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file
75+
done
76+
done
77+
'';
78+
6579
passthru = {
6680
isLLVM = true;
6781
};

pkgs/development/compilers/llvm/5/libcxx/default.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ stdenv.mkDerivation {
4141
"-DLIBCXX_CXX_ABI=libcxxabi"
4242
] ++ lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1";
4343

44+
preInstall = lib.optionalString (stdenv.isDarwin) ''
45+
for file in lib/*.dylib; do
46+
if [ -L "$file" ]; then continue; fi
47+
48+
baseName=$(basename $(otool -D $file | tail -n 1))
49+
installName="$out/lib/$baseName"
50+
abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/')
51+
52+
for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
53+
${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file
54+
done
55+
done
56+
'';
57+
4458
passthru = {
4559
isLLVM = true;
4660
};

pkgs/development/compilers/llvm/6/libcxx/default.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ stdenv.mkDerivation {
4747
"-DLIBCXX_CXX_ABI=libcxxabi"
4848
] ++ lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1";
4949

50+
preInstall = lib.optionalString (stdenv.isDarwin) ''
51+
for file in lib/*.dylib; do
52+
if [ -L "$file" ]; then continue; fi
53+
54+
baseName=$(basename $(otool -D $file | tail -n 1))
55+
installName="$out/lib/$baseName"
56+
abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/')
57+
58+
for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
59+
${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file
60+
done
61+
done
62+
'';
63+
5064
passthru = {
5165
isLLVM = true;
5266
};

pkgs/development/compilers/llvm/7/libcxx/default.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ stdenv.mkDerivation {
5252
++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON"
5353
++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" ;
5454

55+
preInstall = lib.optionalString (stdenv.isDarwin) ''
56+
for file in lib/*.dylib; do
57+
if [ -L "$file" ]; then continue; fi
58+
59+
baseName=$(basename $(otool -D $file | tail -n 1))
60+
installName="$out/lib/$baseName"
61+
abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/')
62+
63+
for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
64+
${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file
65+
done
66+
done
67+
'';
68+
5569
passthru = {
5670
isLLVM = true;
5771
};

pkgs/development/compilers/llvm/8/libcxx/default.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ stdenv.mkDerivation {
5555
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
5656
] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF";
5757

58+
preInstall = lib.optionalString (stdenv.isDarwin) ''
59+
for file in lib/*.dylib; do
60+
if [ -L "$file" ]; then continue; fi
61+
62+
baseName=$(basename $(otool -D $file | tail -n 1))
63+
installName="$out/lib/$baseName"
64+
abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/')
65+
66+
for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
67+
${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file
68+
done
69+
done
70+
'';
71+
5872
passthru = {
5973
isLLVM = true;
6074
};

pkgs/development/compilers/llvm/9/libcxx/default.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ stdenv.mkDerivation {
5151
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
5252
] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF";
5353

54+
preInstall = lib.optionalString (stdenv.isDarwin) ''
55+
for file in lib/*.dylib; do
56+
if [ -L "$file" ]; then continue; fi
57+
58+
baseName=$(basename $(otool -D $file | tail -n 1))
59+
installName="$out/lib/$baseName"
60+
abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/')
61+
62+
for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
63+
${stdenv.cc.targetPrefix}install_name_tool -change $other ${libcxxabi}/lib/$abiName $file
64+
done
65+
done
66+
'';
67+
5468
passthru = {
5569
isLLVM = true;
5670
};

0 commit comments

Comments
 (0)