···10 finalVersion = cudatoolkitVersions.${final.cudaVersion};
1112 # Exposed as cudaPackages.backendStdenv.
13- # We don't call it just "stdenv" to avoid confusion: e.g. this toolchain doesn't contain nvcc.
14- # Instead, it's the back-end toolchain for nvcc to use.
15- # We also use this to link a compatible libstdc++ (backendStdenv.cc.cc.lib)
00016 # Cf. https://github.com/NixOS/nixpkgs/pull/218265 for context
17- backendStdenv = prev.pkgs."${finalVersion.gcc}Stdenv";
0001819 ### Add classic cudatoolkit package
20 cudatoolkit =
···10 finalVersion = cudatoolkitVersions.${final.cudaVersion};
1112 # Exposed as cudaPackages.backendStdenv.
13+ # This is what nvcc uses as a backend,
14+ # and it has to be an officially supported one (e.g. gcc11 for cuda11).
15+ #
16+ # It, however, propagates current stdenv's libstdc++ to avoid "GLIBCXX_* not found errors"
17+ # when linked with other C++ libraries.
18+ # E.g. for cudaPackages_11_8 we use gcc11 with gcc12's libstdc++
19 # Cf. https://github.com/NixOS/nixpkgs/pull/218265 for context
20+ backendStdenv = final.callPackage ./stdenv.nix {
21+ nixpkgsStdenv = prev.pkgs.stdenv;
22+ nvccCompatibleStdenv = prev.pkgs.buildPackages."${finalVersion.gcc}Stdenv";
23+ };
2425 ### Add classic cudatoolkit package
26 cudatoolkit =
···1{ lib
02, backendStdenv
3, fetchurl
4, autoPatchelfHook
···30 ];
3132 buildInputs = [
33- # autoPatchelfHook will search for a libstdc++ and we're giving it a
34- # "compatible" libstdc++ from the same toolchain that NVCC uses.
35- #
36 # NB: We don't actually know if this is the right thing to do
37- backendStdenv.cc.cc.lib
38 ];
3940 dontBuild = true;
···1{ lib
2+, stdenv
3, backendStdenv
4, fetchurl
5, autoPatchelfHook
···31 ];
3233 buildInputs = [
34+ # autoPatchelfHook will search for a libstdc++ and we're giving it
35+ # one that is compatible with the rest of nixpkgs, even when
36+ # nvcc forces us to use an older gcc
37 # NB: We don't actually know if this is the right thing to do
38+ stdenv.cc.cc.lib
39 ];
4041 dontBuild = true;
+17
pkgs/development/compilers/cudatoolkit/stdenv.nix
···00000000000000000
···1+{ nixpkgsStdenv
2+, nvccCompatibleStdenv
3+, overrideCC
4+, wrapCCWith
5+}:
6+7+overrideCC nixpkgsStdenv (wrapCCWith {
8+ cc = nvccCompatibleStdenv.cc.cc;
9+10+ # This option is for clang's libcxx, but we (ab)use it for gcc's libstdc++.
11+ # Note that libstdc++ maintains forward-compatibility: if we load a newer
12+ # libstdc++ into the process, we can still use libraries built against an
13+ # older libstdc++. This, in practice, means that we should use libstdc++ from
14+ # the same stdenv that the rest of nixpkgs uses.
15+ # We currently do not try to support anything other than gcc and linux.
16+ libcxx = nixpkgsStdenv.cc.cc.lib;
17+})