From c45e1b6459b90142c78c38cdc44b7e865cf4dcec Mon Sep 17 00:00:00 2001 From: Someone Serge Date: Wed, 10 Jan 2024 23:53:40 +0000 Subject: [PATCH] cudaPackages.cuda_nvcc: use gcc from pkgsHostTarget i.e. with the same offsets as nvcc itself --- .../cuda-modules/cuda/overrides.nix | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pkgs/development/cuda-modules/cuda/overrides.nix b/pkgs/development/cuda-modules/cuda/overrides.nix index e40d58736e8b..d6068456e4dc 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 backend-stdenv.nix, except the stdenv uses + # buildPackages and we use pkgsHostTarget. + 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