diff --git a/pkgs/development/compilers/cudatoolkit/common.nix b/pkgs/development/compilers/cudatoolkit/common.nix index 8082756b1edb..e4ad19406b72 100644 --- a/pkgs/development/compilers/cudatoolkit/common.nix +++ b/pkgs/development/compilers/cudatoolkit/common.nix @@ -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" diff --git a/pkgs/development/compilers/cudatoolkit/extension.nix b/pkgs/development/compilers/cudatoolkit/extension.nix index dd6f7ff2abe7..7ed3e0426180 100644 --- a/pkgs/development/compilers/cudatoolkit/extension.nix +++ b/pkgs/development/compilers/cudatoolkit/extension.nix @@ -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 = diff --git a/pkgs/development/compilers/cudatoolkit/redist/build-cuda-redist-package.nix b/pkgs/development/compilers/cudatoolkit/redist/build-cuda-redist-package.nix index 1b216ee625a8..a0242a91a03b 100644 --- a/pkgs/development/compilers/cudatoolkit/redist/build-cuda-redist-package.nix +++ b/pkgs/development/compilers/cudatoolkit/redist/build-cuda-redist-package.nix @@ -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; diff --git a/pkgs/development/compilers/cudatoolkit/stdenv.nix b/pkgs/development/compilers/cudatoolkit/stdenv.nix new file mode 100644 index 000000000000..42ee7f7b3317 --- /dev/null +++ b/pkgs/development/compilers/cudatoolkit/stdenv.nix @@ -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; +})