From 497f6119e2ccb87aa2a66170f7a980333a6e0b2d Mon Sep 17 00:00:00 2001 From: Someone Serge Date: Thu, 11 Jan 2024 00:31:38 +0000 Subject: [PATCH] cudaPackages.backendStdenv: switch to stdenvAdapters.useLibsFrom --- .../cuda-modules/backend-stdenv.nix | 40 +++++-------------- .../cuda-modules/cuda/overrides.nix | 4 +- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/pkgs/development/cuda-modules/backend-stdenv.nix b/pkgs/development/cuda-modules/backend-stdenv.nix index ff54af3c2fb9..3b4c8d47c5e8 100644 --- a/pkgs/development/cuda-modules/backend-stdenv.nix +++ b/pkgs/development/cuda-modules/backend-stdenv.nix @@ -2,49 +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 - ccForLibs = stdenv.cc.cc; - cxxStdlib = lib.getLib ccForLibs; - nvccCompatibleCC = buildPackages."gcc${gccMajorVersion}".cc; - - cc = wrapCCWith { - cc = nvccCompatibleCC; - - # Note: normally the `useCcForLibs`/`gccForLibs` mechanism is used to get a - # clang based `cc` to use `libstdc++` (from gcc). - - # Here we (ab)use it to use a `libstdc++` from a different `gcc` than our - # `cc`. - - # Note that this does not inhibit our `cc`'s lib dir from being added to - # cflags/ldflags (see `cc_solib` in `cc-wrapper`) but this is okay: our - # `gccForLibs`'s paths should take precedence. - useCcForLibs = true; - gccForLibs = ccForLibs; - }; - cudaStdenv = overrideCC stdenv cc; + cudaStdenv = stdenvAdapters.useLibsFrom stdenv pkgs."gcc${gccMajorVersion}Stdenv"; passthruExtra = { - nixpkgsCompatibleLibstdcxx = lib.warn "cudaPackages.backendStdenv.nixpkgsCompatibleLibstdcxx is misnamed, deprecated, and will be removed after 24.05" cxxStdlib; + 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 ((stdenv.cc.cxxStdlib.kind or null) == "libstdc++") - -> lib.versionAtLeast cxxStdlib.version stdenv.cc.cxxStdlib.package.version; +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 d6068456e4dc..b4b59ce1f4a6 100644 --- a/pkgs/development/cuda-modules/cuda/overrides.nix +++ b/pkgs/development/cuda-modules/cuda/overrides.nix @@ -87,8 +87,8 @@ attrsets.filterAttrs (attr: _: (builtins.hasAttr attr prev)) { cuda_nvcc = prev.cuda_nvcc.overrideAttrs ( oldAttrs: let - # This replicates the logic in backend-stdenv.nix, except the stdenv uses - # buildPackages and we use pkgsHostTarget. + # 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 {