diff options
Diffstat (limited to 'pkgs/development/cuda-modules')
-rw-r--r-- | pkgs/development/cuda-modules/backend-stdenv.nix | 37 | ||||
-rw-r--r-- | pkgs/development/cuda-modules/cuda/overrides.nix | 19 |
2 files changed, 30 insertions, 26 deletions
diff --git a/pkgs/development/cuda-modules/backend-stdenv.nix b/pkgs/development/cuda-modules/backend-stdenv.nix index 10fedd1e6f271..3b4c8d47c5e8b 100644 --- a/pkgs/development/cuda-modules/backend-stdenv.nix +++ b/pkgs/development/cuda-modules/backend-stdenv.nix @@ -2,38 +2,29 @@ lib, nvccCompatibilities, cudaVersion, - buildPackages, + pkgs, overrideCC, stdenv, wrapCCWith, + stdenvAdapters, }: + let gccMajorVersion = nvccCompatibilities.${cudaVersion}.gccMaxMajorVersion; - # We use buildPackages (= pkgsBuildHost) because we look for a gcc that - # runs on our build platform, and that produces executables for the host - # platform (= platform on which we deploy and run the downstream packages). - # The target platform of buildPackages.gcc is our host platform, so its - # .lib output should be the libstdc++ we want to be writing in the runpaths - # Cf. https://github.com/NixOS/nixpkgs/pull/225661#discussion_r1164564576 - nixpkgsCompatibleLibstdcxx = buildPackages.gcc.cc.lib; - nvccCompatibleCC = buildPackages."gcc${gccMajorVersion}".cc; - - cc = wrapCCWith { - cc = nvccCompatibleCC; - - # 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 = nixpkgsCompatibleLibstdcxx; - }; - cudaStdenv = overrideCC stdenv cc; + cudaStdenv = stdenvAdapters.useLibsFrom stdenv pkgs."gcc${gccMajorVersion}Stdenv"; passthruExtra = { - inherit nixpkgsCompatibleLibstdcxx; + nixpkgsCompatibleLibstdcxx = lib.warn "cudaPackages.backendStdenv.nixpkgsCompatibleLibstdcxx is misnamed, deprecated, and will be removed after 24.05" cudaStdenv.cc.cxxStdlib.package; # cc already exposed }; assertCondition = true; in + +# We should use libstdc++ at least as new as nixpkgs' stdenv's one. +assert let + cxxStdlibCuda = cudaStdenv.cc.cxxStdlib.package; + cxxStdlibNixpkgs = stdenv.cc.cxxStdlib.package; +in +((stdenv.cc.cxxStdlib.kind or null) == "libstdc++") +-> lib.versionAtLeast cxxStdlibCuda.version cxxStdlibNixpkgs.version; + lib.extendDerivation assertCondition passthruExtra cudaStdenv diff --git a/pkgs/development/cuda-modules/cuda/overrides.nix b/pkgs/development/cuda-modules/cuda/overrides.nix index e40d58736e8b8..b4b59ce1f4a6e 100644 --- a/pkgs/development/cuda-modules/cuda/overrides.nix +++ b/pkgs/development/cuda-modules/cuda/overrides.nix @@ -85,7 +85,20 @@ attrsets.filterAttrs (attr: _: (builtins.hasAttr attr prev)) { ); cuda_nvcc = prev.cuda_nvcc.overrideAttrs ( - oldAttrs: { + oldAttrs: + let + # This replicates the logic in stdenvAdapters.useLibsFrom, except we use + # gcc from pkgsHostTarget and not from buildPackages. + ccForLibs-wrapper = final.pkgs.stdenv.cc; + gccMajorVersion = final.nvccCompatibilities.${cudaVersion}.gccMaxMajorVersion; + cc = final.pkgs.wrapCCWith { + cc = final.pkgs."gcc${gccMajorVersion}".cc; + useCcForLibs = true; + gccForLibs = ccForLibs-wrapper.cc; + }; + cxxStdlibDir = ccForLibs-wrapper.cxxStdlib.solib; + in + { outputs = oldAttrs.outputs ++ lists.optionals (!(builtins.elem "lib" oldAttrs.outputs)) [ "lib" ]; @@ -119,8 +132,8 @@ attrsets.filterAttrs (attr: _: (builtins.hasAttr attr prev)) { cat << EOF >> bin/nvcc.profile # Fix a compatible backend compiler - PATH += ${lib.getBin final.backendStdenv.cc}/bin: - LIBRARIES += "-L${lib.getLib final.backendStdenv.nixpkgsCompatibleLibstdcxx}/lib" + PATH += ${lib.getBin cc}/bin: + LIBRARIES += "-L${cxxStdlibDir}/lib" # Expose the split-out nvvm LIBRARIES =+ -L''${!outputBin}/nvvm/lib |