Skip to content

Commit

Permalink
cudaPackages.backendStdenv: switch to stdenvAdapters.useLibsFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneSerge committed Jan 12, 2024
1 parent e6e2799 commit 497f611
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 32 deletions.
40 changes: 10 additions & 30 deletions pkgs/development/cuda-modules/backend-stdenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions pkgs/development/cuda-modules/cuda/overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 497f611

Please sign in to comment.