Skip to content

Commit

Permalink
llvmPackages_{12,13,14,15,16,17,git}.{libcxx,libcxxabi}: merge libcxx…
Browse files Browse the repository at this point in the history
…abi into libcxx (#292043)

- merge libcxxabi into libcxx for LLVM 12, 13, 14, 15, 16, 17, and git.
- remove the link time workaround `-lc++ -lc++abi` from 58 packages as it is no longer required.
- fixes #166205
- provides alternative fixes for. #269548 NixOS/nix#9640
- pkgsCross.x86_64-freebsd builds work again

This change can be represented in 3 stages
1. merge libcxxabi into libcxx -- files: pkgs/development/compilers/llvm/[12, git]/{libcxx, libcxxabi}
2. update stdenv to account for merge -- files: stdenv.{adapters, cc.wrapper, darwin}
3. remove all references to libcxxabi outside of llvm (about 58 packages modified)

### merging libcxxabi into libcxx
- take the union of the libcxxabi and libcxx cmake flags
- eliminate the libcxx-headers-only package - it was only needed to break libcxx <-> libcxxabi circular dependency
- libcxx.cxxabi is removed. external cxxabi (freebsd) will symlink headers / libs into libcxx.
- darwin will re-export the libcxxabi symbols into libcxx so linking `-lc++` is sufficient.
- linux/freebsd `libc++.so` is a linker script `LINK(libc++.so.1, -lc++abi)` making `-lc++` sufficient.
- libcxx/default.nix [12, 17] are identical except for patches and `LIBCXX_ADDITIONAL_LIBRARIES` (only used in 16+)
- git/libcxx/defaul.nix  does not link with -nostdlib when useLLVM is true so flag is removed. this is not much different than before as libcxxabi used -nostdlib where libcxx did not, so libc was linked in anyway.

### stdenv changes
- darwin bootstrap, remove references to libcxxabi and cxxabi
- cc-wrapper: remove c++ link workaround when libcxx.cxxabi doesn't exist (still exists for LLVM pre 12)
- adapter: update overrideLibcxx to account for a pkgs.stdenv that only has libcxx

### 58 package updates
- remove `NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}` as no longer needed
- swift, nodejs_v8 remove libcxxabi references in the clang override

#292043
  • Loading branch information
a-n-n-a-l-e-e authored Mar 11, 2024
1 parent b221192 commit ce789e7
Show file tree
Hide file tree
Showing 108 changed files with 730 additions and 2,211 deletions.
3 changes: 1 addition & 2 deletions pkgs/applications/audio/nova-filters/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
, scons
, boost
, ladspaH
, libcxxabi
}:

stdenv.mkDerivation (finalAttrs: {
Expand All @@ -23,7 +22,7 @@ stdenv.mkDerivation (finalAttrs: {
--replace "-fomit-frame-pointer -ffast-math -mfpmath=sse" "-I${boost.dev}/include -I${ladspaH}/include" \
--replace "env.has_key('cxx')" "True" \
--replace "env['cxx']" "'${stdenv.cc.targetPrefix}c++'" \
--replace "-Wl,--strip-all" "${lib.optionalString stdenv.isDarwin "-L${libcxxabi}/lib"}"
--replace "-Wl,--strip-all" ""
substituteInPlace filters.cpp \
--replace "LADSPA_HINT_SAMPLE_RATE, 0, 0.5" "LADSPA_HINT_SAMPLE_RATE, 0.0001, 0.5"
Expand Down
4 changes: 0 additions & 4 deletions pkgs/applications/editors/lapce/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ rustPlatform.buildRustPackage rec {

# This variable is read by build script, so that Lapce editor knows its version
RELEASE_TAG_NAME = "v${version}";

} // lib.optionalAttrs stdenv.cc.isClang {
# Work around https://github.com/NixOS/nixpkgs/issues/166205.
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};

postPatch = ''
Expand Down
5 changes: 0 additions & 5 deletions pkgs/applications/editors/neovim/neovide/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ rustPlatform.buildRustPackage.override { stdenv = clangStdenv; } rec {
darwin.apple_sdk.frameworks.AppKit
];

env = lib.optionalAttrs stdenv.isDarwin {
# Work around https://github.com/NixOS/nixpkgs/issues/166205
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};

postFixup = let
libPath = lib.makeLibraryPath ([
libglvnd
Expand Down
2 changes: 0 additions & 2 deletions pkgs/applications/misc/done/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ stdenv.mkDerivation rec {

env = lib.optionalAttrs stdenv.isDarwin {
GETTEXT_DIR = gettext;
# Work around https://github.com/NixOS/nixpkgs/issues/166205.
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};

meta = with lib; {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/networking/browsers/firefox/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ let
# We only link c++ libs here, our compiler wrapper can find wasi libc and crt itself.
wasiSysRoot = runCommand "wasi-sysroot" {} ''
mkdir -p $out/lib/wasm32-wasi
for lib in ${pkgsCross.wasi32.llvmPackages.libcxx}/lib/* ${pkgsCross.wasi32.llvmPackages.libcxxabi}/lib/*; do
for lib in ${pkgsCross.wasi32.llvmPackages.libcxx}/lib/*; do
ln -s $lib $out/lib/wasm32-wasi
done
'';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let
[ zlib glib libpng freetype xorg.libSM xorg.libICE xorg.libXrender openssl
xorg.libXrandr xorg.libXfixes xorg.libXcursor xorg.libXinerama
xorg.libxcb fontconfig xorg.libXext xorg.libX11 alsa-lib qtbase qtwebengine qtwebchannel qtsvg
qtwebsockets libpulseaudio quazip llvmPackages.libcxx llvmPackages.libcxxabi
qtwebsockets libpulseaudio quazip llvmPackages.libcxx
];

desktopItem = makeDesktopItem {
Expand Down
5 changes: 1 addition & 4 deletions pkgs/applications/networking/pjsip/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ stdenv.mkDerivation (finalAttrs: {
++ lib.optional stdenv.isLinux alsa-lib
++ lib.optionals stdenv.isDarwin [ AppKit CoreFoundation Security ];

env = lib.optionalAttrs (stdenv.cc.libcxx != null) {
# work around https://github.com/NixOS/nixpkgs/issues/166205
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
} // lib.optionalAttrs stdenv.cc.isClang {
env = lib.optionalAttrs stdenv.cc.isClang {
CXXFLAGS = "-std=c++11";
} // lib.optionalAttrs stdenv.isDarwin {
NIX_CFLAGS_LINK = "-headerpad_max_install_names";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
, file, atk, alsa-lib, cairo, fontconfig, gdk-pixbuf, glib, webkitgtk, gtk2-x11, gtk3
, heimdal, krb5, libsoup, libvorbis, speex, openssl, zlib, xorg, pango, gtk2
, gnome2, mesa, nss, nspr, gtk_engines, freetype, dconf, libpng12, libxml2
, libjpeg, libredirect, tzdata, cacert, systemd, libcxxabi, libcxx, e2fsprogs, symlinkJoin
, libjpeg, libredirect, tzdata, cacert, systemd, libcxx, e2fsprogs, symlinkJoin
, libpulseaudio, pcsclite, glib-networking, llvmPackages_12, opencv4
, libfaketime
, libinput, libcap, libjson, libsecret, libcanberra-gtk3
Expand Down Expand Up @@ -84,7 +84,6 @@ stdenv.mkDerivation rec {
libcap
libcanberra-gtk3
libcxx
libcxxabi
libinput
libjpeg
libjson
Expand Down
5 changes: 0 additions & 5 deletions pkgs/applications/office/espanso/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ rustPlatform.buildRustPackage rec {
--replace '"/usr/local/bin/espanso"' '"${placeholder "out"}/bin/espanso"'
'';

env = lib.optionalAttrs stdenv.cc.isClang {
# Work around https://github.com/NixOS/nixpkgs/issues/166205.
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};

# Some tests require networking
doCheck = false;

Expand Down
5 changes: 0 additions & 5 deletions pkgs/applications/science/logic/lean4/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ stdenv.mkDerivation (finalAttrs: {
"-DINSTALL_LICENSE=OFF"
];

# Work around https://github.com/NixOS/nixpkgs/issues/166205.
env = lib.optionalAttrs stdenv.cc.isClang {
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};

passthru.tests = {
version = testers.testVersion {
package = finalAttrs.finalPackage;
Expand Down
9 changes: 1 addition & 8 deletions pkgs/applications/version-management/p4/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
, lib
, emptyDirectory
, linkFarm
, symlinkJoin
, jam
, libcxx
, libcxxabi
, openssl
, xcbuild
, CoreServices
Expand All @@ -33,10 +30,6 @@ let
# cone-based Git sparse checkout, either.)
{ name = "contrib"; path = "${src}/contrib"; }
];
libcxxUnified = symlinkJoin {
inherit (libcxx) name;
paths = [ libcxx libcxxabi ];
};
in
stdenv.mkDerivation rec {
pname = "p4";
Expand Down Expand Up @@ -70,7 +63,7 @@ stdenv.mkDerivation rec {
++ lib.optionals stdenv.isDarwin [
"-sOSVER=1013"
"-sMACOSX_SDK=${emptyDirectory}"
"-sLIBC++DIR=${libcxxUnified}/lib"
"-sLIBC++DIR=${lib.getLib stdenv.cc.libcxx}/lib"
];

CCFLAGS =
Expand Down
5 changes: 4 additions & 1 deletion pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,11 @@ stdenv.mkDerivation {
''
+ optionalString (libcxx.isLLVM or false) ''
echo "-isystem ${lib.getDev libcxx}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags
echo "-isystem ${lib.getDev libcxx.cxxabi}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags
echo "-stdlib=libc++" >> $out/nix-support/libcxx-ldflags
''
# can remove once LLVM9 and LLVM11 are dropped from nixpkgs
+ optionalString (libcxx.isLLVM or false && lib.versionOlder (lib.getVersion libcxx) "12" && libcxx ? cxxabi.libName) ''
echo "-isystem ${lib.getDev libcxx.cxxabi}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags
echo "-l${libcxx.cxxabi.libName}" >> $out/nix-support/libcxx-ldflags
''

Expand Down
5 changes: 0 additions & 5 deletions pkgs/by-name/as/ast-grep/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ rustPlatform.buildRustPackage rec {

cargoHash = "sha256-48ZVbRJkpMO+kJE5Kz96McjXhMtu4TzzjfyYdggNWkQ=";

# Work around https://github.com/NixOS/nixpkgs/issues/166205.
env = lib.optionalAttrs stdenv.cc.isClang {
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};

nativeBuildInputs = [ installShellFiles ];

# error: linker `aarch64-linux-gnu-gcc` not found
Expand Down
5 changes: 0 additions & 5 deletions pkgs/by-name/gc/gcs/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ buildGoModule rec {
flags = [ "-a -trimpath" ];
ldflags = [ "-s" "-w" "-X github.com/richardwilkes/toolbox/cmdline.AppVersion=${version}" ];

# Workaround for https://github.com/NixOS/nixpkgs/issues/166205
env = lib.optionalAttrs (stdenv.cc.libcxx != null) {
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};

installPhase = ''
runHook preInstall
install -Dm755 $GOPATH/bin/gcs -t $out/bin
Expand Down
5 changes: 0 additions & 5 deletions pkgs/by-name/ni/nickel/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ rustPlatform.buildRustPackage rec {

cargoBuildFlags = [ "-p nickel-lang-cli" "-p nickel-lang-lsp" ];

env = lib.optionalAttrs stdenv.cc.isClang {
# Work around https://github.com/NixOS/nixpkgs/issues/166205.
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};

nativeBuildInputs = [
python3
];
Expand Down
3 changes: 0 additions & 3 deletions pkgs/by-name/sy/symbolicator/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ rustPlatform.buildRustPackage rec {
SYMBOLICATOR_GIT_VERSION = src.rev;
SYMBOLICATOR_RELEASE = version;
ZSTD_SYS_USE_PKG_CONFIG = true;
} // lib.optionalAttrs stdenv.cc.isClang {
# Work around https://github.com/NixOS/nixpkgs/issues/166205.
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};

# tests require network access
Expand Down
8 changes: 1 addition & 7 deletions pkgs/by-name/ta/tabby/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ let
cudaBuildInputs = [ llamaccpPackage ];
rocmBuildInputs = [ llamaccpPackage ];

LLAMA_CPP_LIB = "${llamaccpPackage.outPath}/lib";

in
rustPlatform.buildRustPackage {
inherit pname version;
Expand Down Expand Up @@ -148,11 +146,7 @@ rustPlatform.buildRustPackage {
++ optionals enableRocm rocmBuildInputs
;

env = lib.mergeAttrsList [
{ inherit LLAMA_CPP_LIB; }
# Work around https://github.com/NixOS/nixpkgs/issues/166205
(lib.optionalAttrs stdenv.cc.isClang { NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}"; })
];
env.LLAMA_CPP_LIB = "${lib.getLib llamaccpPackage}/lib";
patches = [ ./0001-nix-build-use-nix-native-llama-cpp-package.patch ];

# Fails with:
Expand Down
5 changes: 0 additions & 5 deletions pkgs/by-name/us/usql/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ buildGoModule rec {
"no_adodb"
];

# Work around https://github.com/NixOS/nixpkgs/issues/166205.
env = lib.optionalAttrs stdenv.cc.isClang {
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};

ldflags = [
"-s"
"-w"
Expand Down
7 changes: 1 addition & 6 deletions pkgs/development/compilers/bfc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ rustPlatform.buildRustPackage rec {
zlib
];

env = {
LLVM_SYS_130_PREFIX = llvmPackages_13.llvm.dev;
} // lib.optionalAttrs stdenv.cc.isClang {
# Work around https://github.com/NixOS/nixpkgs/issues/166205.
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};
env.LLVM_SYS_130_PREFIX = llvmPackages_13.llvm.dev;

# process didn't exit successfully: <...> SIGSEGV
doCheck = false;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/crystal/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ let
# Darwin links against libc++ not libstdc++. Newer versions of clang (12+) require
# libc++abi to be linked explicitly (see https://github.com/NixOS/nixpkgs/issues/166205).
substituteInPlace src/llvm/lib_llvm.cr \
--replace '@[Link("stdc++")]' '@[Link("c++", "-l${stdenv.cc.libcxx.cxxabi.libName}")]'
--replace '@[Link("stdc++")]' '@[Link("c++")]'
'';

# Defaults are 4
Expand Down
5 changes: 2 additions & 3 deletions pkgs/development/compilers/llvm/12/compiler-rt/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lib, stdenv, llvm_meta, version, fetch
, cmake, python3, xcbuild, libllvm, linuxHeaders, libcxxabi, libxcrypt
, cmake, python3, xcbuild, libllvm, linuxHeaders, libxcrypt
, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD
}:

Expand All @@ -20,8 +20,7 @@ stdenv.mkDerivation {
nativeBuildInputs = [ cmake python3 libllvm.dev ]
++ lib.optional stdenv.isDarwin xcbuild.xcrun;
buildInputs =
lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders
++ lib.optional stdenv.hostPlatform.isDarwin libcxxabi;
lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders;

env.NIX_CFLAGS_COMPILE = toString [
"-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0"
Expand Down
17 changes: 2 additions & 15 deletions pkgs/development/compilers/llvm/12/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ let
cc = tools.clang-unwrapped;
libcxx = targetLlvmLibraries.libcxx;
extraPackages = [
libcxx.cxxabi
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = mkExtraBuildCommands cc;
Expand Down Expand Up @@ -163,7 +162,6 @@ let
libcxx = targetLlvmLibraries.libcxx;
bintools = bintools';
extraPackages = [
libcxx.cxxabi
targetLlvmLibraries.compiler-rt
] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [
targetLlvmLibraries.libunwind
Expand Down Expand Up @@ -257,24 +255,13 @@ let

libcxx = callPackage ./libcxx {
inherit llvm_meta;
stdenv = if stdenv.hostPlatform.useLLVM or false
then overrideCC stdenv buildLlvmTools.clangNoLibcxx
else stdenv;
};

libcxxabi = callPackage ./libcxxabi {
inherit llvm_meta;
stdenv = if stdenv.hostPlatform.useLLVM or false
then overrideCC stdenv buildLlvmTools.clangNoLibcxx
else stdenv;
stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
};

libunwind = callPackage ./libunwind {
inherit llvm_meta;
inherit (buildLlvmTools) llvm;
stdenv = if stdenv.hostPlatform.useLLVM or false
then overrideCC stdenv buildLlvmTools.clangNoLibcxx
else stdenv;
stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
};

openmp = callPackage ./openmp {
Expand Down
Loading

0 comments on commit ce789e7

Please sign in to comment.