diff options
author | Randy Eckenrode <randy@largeandhighquality.com> | 2023-11-03 23:02:26 -0400 |
---|---|---|
committer | Randy Eckenrode <randy@largeandhighquality.com> | 2023-11-03 23:11:32 -0400 |
commit | cc4fcc147b644cb97ff47d97af3045ee1889080c (patch) | |
tree | 0b56ed89f6e1d6f147271ac709fcec1d9239fbd7 | |
parent | b4f75edb0744abef12d1203c02f23f95db4f4d64 (diff) |
stdenvAdapters: add overrideLibcxx
This was taken from #264091 to use in the interim before that PR lands (sometime after the release of 23.11). It allows different versions of clang to link the same libc++, allowing dependencies to be linked when they are built with a different version of clang than the stdenv.
-rw-r--r-- | pkgs/stdenv/adapters.nix | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 977ef2eef9c75..5fd59a550cbbb 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -42,6 +42,50 @@ rec { stdenv.override (prev: { allowedRequisites = null; extraBuildInputs = (prev.extraBuildInputs or []) ++ pkgs; }); + # Override the libc++ dynamic library used in the stdenv to use the one from the platform’s + # default stdenv. This allows building packages and linking dependencies with different + # compiler versions while still using the same libc++ implementation for compatibility. + # + # Note that this adapter still uses the headers from the new stdenv’s libc++. This is necessary + # because older compilers may not be able to parse the headers from the default stdenv’s libc++. + overrideLibcxx = stdenv: + assert stdenv.cc.libcxx != null; + let + llvmLibcxxVersion = lib.getVersion llvmLibcxx; + stdenvLibcxxVersion = lib.getVersion stdenvLibcxx; + + stdenvLibcxx = pkgs.stdenv.cc.libcxx; + stdenvCxxabi = pkgs.stdenv.cc.libcxx.cxxabi; + + llvmLibcxx = stdenv.cc.libcxx; + llvmCxxabi = stdenv.cc.libcxx.cxxabi; + + libcxx = pkgs.runCommand "${stdenvLibcxx.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit cxxabi; + isLLVM = true; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvLibcxx}' "$out" + echo '${stdenvLibcxx}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmLibcxx}/include' "$dev/include" + ''; + + cxxabi = pkgs.runCommand "${stdenvCxxabi.name}-${llvmLibcxxVersion}" { + outputs = [ "out" "dev" ]; + inherit (stdenvCxxabi) libName; + } '' + mkdir -p "$dev/nix-support" + ln -s '${stdenvCxxabi}' "$out" + echo '${stdenvCxxabi}' > "$dev/nix-support/propagated-build-inputs" + ln -s '${lib.getDev llvmCxxabi}/include' "$dev/include" + ''; + in + overrideCC stdenv (stdenv.cc.override { + inherit libcxx; + extraPackages = [ cxxabi pkgs.pkgsTargetTarget."llvmPackages_${lib.versions.major llvmLibcxxVersion}".compiler-rt ]; + }); + # Override the setup script of stdenv. Useful for testing new # versions of the setup script without causing a rebuild of # everything. |