Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvmPackages_{12,13,14,15,16,17,18,git}.libcxx: merge static libc++ab… #305876

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion pkgs/development/compilers/llvm/common/libcxx/default.nix
Expand Up @@ -123,9 +123,30 @@ stdenv.mkDerivation (rec {
# 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) ''
postInstall = ''
libcxxabi=$out/lib/libc++abi.a
'' + lib.optionalString (cxxabi != null) ''
lndir ${lib.getDev cxxabi}/include $dev/include/c++/v1
lndir ${lib.getLib cxxabi}/lib $out/lib
libcxxabi=$out/lib/lib${cxxabi.libName}.a
''
# LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON doesn't work for LLVM < 16 or
# external cxxabi libraries so merge libc++abi.a into libc++.a ourselves.
+ ''
if [[ -f $out/lib/libc++.a && -e $libcxxabi ]]; then
scratch="$(mktemp -d)"
mv $out/lib/libc++.a $scratch/libcxx.a
cp -d $libcxxabi $scratch/libcxxabi.a
$AR -M <<MRI
create libcxx.a
addlib $scratch/libcxx.a
addlib $scratch/libcxxabi.a
save
end
MRI
mv libcxx.a $out/lib/libc++.a
rm -rf $scratch
fi
'';

passthru = {
Expand Down
10 changes: 10 additions & 0 deletions pkgs/test/cc-wrapper/default.nix
Expand Up @@ -46,6 +46,16 @@ in stdenv.mkDerivation {
$READELF -d ./atomics.so | grep libatomic.so && echo "ok" >&2 || echo "failed" >&2
''}

${lib.optionalString isCxx ''
echo "checking whether can link with libc++... " >&2
$CXX ${./cxx-main.cc} -c -o cxx-main.o
$CC cxx-main.o -lc++ -o cxx-main
$CC cxx-main.o -l:libc++.a -o cxx-main-static
${emulator} ./cxx-main
${emulator} ./cxx-main-static
rm cxx-main{,-static,.o}
''}

${lib.optionalString (stdenv.isDarwin && stdenv.cc.isClang) ''
echo "checking whether compiler can build with CoreFoundation.framework... " >&2
mkdir -p foo/lib
Expand Down