cudaPackages: use same libstdc++ as the rest of nixpkgs

This commit is contained in:
Someone Serge 2023-03-29 02:39:46 +03:00
parent 3cde9b5e4d
commit bd62420fd3
No known key found for this signature in database
GPG key ID: 7B0E3B1390D61DA4
4 changed files with 35 additions and 10 deletions

View file

@ -29,6 +29,7 @@ args@
, python3 # FIXME: CUDAToolkit 10 may still need python27
, pulseaudio
, requireFile
, stdenv
, backendStdenv # E.g. gcc11Stdenv, set in extension.nix
, unixODBC
, wayland
@ -121,8 +122,8 @@ backendStdenv.mkDerivation rec {
(placeholder "lib")
(placeholder "out")
"${placeholder "out"}/nvvm"
# Is it not handled by autoPatchelf automatically?
"${lib.getLib backendStdenv.cc.cc}/lib64"
# NOTE: use the same libstdc++ as the rest of nixpkgs, not from backendStdenv
"${lib.getLib stdenv.cc.cc}/lib64"
"${placeholder "out"}/jre/lib/amd64/jli"
"${placeholder "out"}/lib64"
"${placeholder "out"}/nvvm/lib64"

View file

@ -10,11 +10,17 @@ final: prev: let
finalVersion = cudatoolkitVersions.${final.cudaVersion};
# Exposed as cudaPackages.backendStdenv.
# We don't call it just "stdenv" to avoid confusion: e.g. this toolchain doesn't contain nvcc.
# Instead, it's the back-end toolchain for nvcc to use.
# We also use this to link a compatible libstdc++ (backendStdenv.cc.cc.lib)
# This is what nvcc uses as a backend,
# and it has to be an officially supported one (e.g. gcc11 for cuda11).
#
# It, however, propagates current stdenv's libstdc++ to avoid "GLIBCXX_* not found errors"
# when linked with other C++ libraries.
# E.g. for cudaPackages_11_8 we use gcc11 with gcc12's libstdc++
# Cf. https://github.com/NixOS/nixpkgs/pull/218265 for context
backendStdenv = prev.pkgs."${finalVersion.gcc}Stdenv";
backendStdenv = final.callPackage ./stdenv.nix {
nixpkgsStdenv = prev.pkgs.stdenv;
nvccCompatibleStdenv = prev.pkgs.buildPackages."${finalVersion.gcc}Stdenv";
};
### Add classic cudatoolkit package
cudatoolkit =

View file

@ -1,4 +1,5 @@
{ lib
, stdenv
, backendStdenv
, fetchurl
, autoPatchelfHook
@ -30,11 +31,11 @@ backendStdenv.mkDerivation {
];
buildInputs = [
# autoPatchelfHook will search for a libstdc++ and we're giving it a
# "compatible" libstdc++ from the same toolchain that NVCC uses.
#
# autoPatchelfHook will search for a libstdc++ and we're giving it
# one that is compatible with the rest of nixpkgs, even when
# nvcc forces us to use an older gcc
# NB: We don't actually know if this is the right thing to do
backendStdenv.cc.cc.lib
stdenv.cc.cc.lib
];
dontBuild = true;

View file

@ -0,0 +1,17 @@
{ nixpkgsStdenv
, nvccCompatibleStdenv
, overrideCC
, wrapCCWith
}:
overrideCC nixpkgsStdenv (wrapCCWith {
cc = nvccCompatibleStdenv.cc.cc;
# This option is for clang's libcxx, but we (ab)use it for gcc's libstdc++.
# Note that libstdc++ maintains forward-compatibility: if we load a newer
# libstdc++ into the process, we can still use libraries built against an
# older libstdc++. This, in practice, means that we should use libstdc++ from
# the same stdenv that the rest of nixpkgs uses.
# We currently do not try to support anything other than gcc and linux.
libcxx = nixpkgsStdenv.cc.cc.lib;
})