Skip to content

Commit cd07e02

Browse files
authored
Merge pull request #223664 from SomeoneSerge/cuda-libstdcpp
cudaPackages: use the same libstdc++ as the rest of nixpkgs
2 parents d218e35 + 3af299f commit cd07e02

File tree

6 files changed

+45
-15
lines changed

6 files changed

+45
-15
lines changed

pkgs/development/compilers/cudatoolkit/common.nix

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ args@
2929
, python3 # FIXME: CUDAToolkit 10 may still need python27
3030
, pulseaudio
3131
, requireFile
32+
, stdenv
3233
, backendStdenv # E.g. gcc11Stdenv, set in extension.nix
3334
, unixODBC
3435
, wayland
@@ -136,8 +137,8 @@ backendStdenv.mkDerivation rec {
136137
(placeholder "lib")
137138
(placeholder "out")
138139
"${placeholder "out"}/nvvm"
139-
# Is it not handled by autoPatchelf automatically?
140-
"${lib.getLib backendStdenv.cc.cc}/lib64"
140+
# NOTE: use the same libstdc++ as the rest of nixpkgs, not from backendStdenv
141+
"${lib.getLib stdenv.cc.cc}/lib64"
141142
"${placeholder "out"}/jre/lib/amd64/jli"
142143
"${placeholder "out"}/lib64"
143144
"${placeholder "out"}/nvvm/lib64"
@@ -219,6 +220,7 @@ backendStdenv.mkDerivation rec {
219220
220221
mv pkg/builds/nsight_systems/target-linux-x64 $out/target-linux-x64
221222
mv pkg/builds/nsight_systems/host-linux-x64 $out/host-linux-x64
223+
rm $out/host-linux-x64/libstdc++.so*
222224
''}
223225
${lib.optionalString (lib.versionAtLeast version "11.8")
224226
# error: auto-patchelf could not satisfy dependency libtiff.so.5 wanted by /nix/store/.......-cudatoolkit-12.0.1/host-linux-x64/Plugins/imageformats/libqtiff.so

pkgs/development/compilers/cudatoolkit/extension.nix

+10-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ final: prev: let
1010
finalVersion = cudatoolkitVersions.${final.cudaVersion};
1111

1212
# 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)
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++
1619
# Cf. https://github.com/NixOS/nixpkgs/pull/218265 for context
17-
backendStdenv = prev.pkgs."${finalVersion.gcc}Stdenv";
20+
backendStdenv = final.callPackage ./stdenv.nix {
21+
nixpkgsStdenv = prev.pkgs.stdenv;
22+
nvccCompatibleStdenv = prev.pkgs.buildPackages."${finalVersion.gcc}Stdenv";
23+
};
1824

1925
### Add classic cudatoolkit package
2026
cudatoolkit =

pkgs/development/compilers/cudatoolkit/redist/build-cuda-redist-package.nix

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{ lib
2+
, stdenv
23
, backendStdenv
34
, fetchurl
45
, autoPatchelfHook
@@ -30,11 +31,11 @@ backendStdenv.mkDerivation {
3031
];
3132

3233
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-
#
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
3637
# NB: We don't actually know if this is the right thing to do
37-
backendStdenv.cc.cc.lib
38+
stdenv.cc.cc.lib
3839
];
3940

4041
dontBuild = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
})

pkgs/development/libraries/science/math/cudnn/generic.nix

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{ stdenv,
22
backendStdenv,
33
lib,
44
zlib,
@@ -26,7 +26,6 @@
2626
maxCudaVersion,
2727
}:
2828
assert useCudatoolkitRunfile || (libcublas != null); let
29-
inherit (backendStdenv) cc;
3029
inherit (lib) lists strings trivial versions;
3130

3231
# majorMinorPatch :: String -> String
@@ -63,7 +62,10 @@ in
6362

6463
# Used by autoPatchelfHook
6564
buildInputs = [
66-
cc.cc.lib # libstdc++
65+
# Note this libstdc++ isn't from the (possibly older) nvcc-compatible
66+
# stdenv, but from the (newer) stdenv that the rest of nixpkgs uses
67+
stdenv.cc.cc.lib
68+
6769
zlib
6870
cudatoolkit_root
6971
];

pkgs/development/libraries/science/math/faiss/default.nix

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@
2525
builtins.head optLevels
2626
, faiss # To run demos in the tests
2727
, runCommand
28-
}:
28+
}@inputs:
2929

3030
assert cudaSupport -> nvidia-thrust.cudaSupport;
3131

3232
let
3333
pname = "faiss";
3434
version = "1.7.2";
3535

36-
inherit (cudaPackages) cudaFlags;
36+
inherit (cudaPackages) cudaFlags backendStdenv;
3737
inherit (cudaFlags) cudaCapabilities dropDot;
3838

39+
stdenv = if cudaSupport then backendStdenv else inputs.stdenv;
40+
3941
cudaJoined = symlinkJoin {
4042
name = "cuda-packages-unsplit";
4143
paths = with cudaPackages; [

0 commit comments

Comments
 (0)