Skip to content

Commit b39ee51

Browse files
authored
cudaPackages.cuda_nvcc: wrap binary so NVCC can always find compiler (#465329)
2 parents a3377f1 + 2fe0be4 commit b39ee51

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

pkgs/development/cuda-modules/packages/cuda_nvcc.nix

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
cuda_cccl,
99
lib,
1010
libnvvm,
11+
makeBinaryWrapper,
1112
}:
1213
buildRedist (finalAttrs: {
1314
redistName = "cuda";
@@ -22,6 +23,10 @@ buildRedist (finalAttrs: {
2223
# The nvcc and cicc binaries contain hard-coded references to /usr
2324
allowFHSReferences = true;
2425

26+
nativeBuildInputs = [
27+
makeBinaryWrapper
28+
];
29+
2530
# Entries here will be in nativeBuildInputs when cuda_nvcc is in nativeBuildInputs
2631
propagatedBuildInputs = [ setupCudaHook ];
2732

@@ -144,13 +149,19 @@ buildRedist (finalAttrs: {
144149
EOF
145150
''
146151
# Add the dependency on backendStdenv.cc to the nvcc.profile.
152+
# NOTE: NVCC explodes in horrifying fashion if GCC is not on PATH -- it fails even before
153+
# reading nvcc.profile!
147154
+ ''
148-
nixLog "adding backendStdenv.cc to nvcc.profile"
155+
nixLog "setting compiler-bindir to backendStdenv.cc in nvcc.profile"
149156
cat << EOF >> "''${!outputBin:?}/bin/nvcc.profile"
150-
151157
# Fix a compatible backend compiler
152-
PATH += "${backendStdenv.cc}/bin":
158+
compiler-bindir = ${backendStdenv.cc}/bin
153159
EOF
160+
161+
nixLog "wrapping nvcc to add backendStdenv.cc to its PATH"
162+
wrapProgramBinary \
163+
"''${!outputBin:?}/bin/nvcc" \
164+
--prefix PATH : ${lib.makeBinPath [ backendStdenv.cc ]}
154165
''
155166
);
156167

pkgs/development/cuda-modules/packages/setupCudaHook/package.nix

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ makeSetupHook {
55

66
substitutions.setupCudaHook = placeholder "out";
77

8-
# Point NVCC at a compatible compiler
9-
substitutions.ccRoot = "${backendStdenv.cc}";
10-
118
# Required in addition to ccRoot as otherwise bin/gcc is looked up
129
# when building CMakeCUDACompilerId.cu
1310
substitutions.ccFullPath = "${backendStdenv.cc}/bin/${backendStdenv.cc.targetPrefix}c++";

pkgs/development/cuda-modules/packages/setupCudaHook/setup-cuda-hook.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ setupCUDAToolkitCompilers() {
9292
export CUDAHOSTCXX="@ccFullPath@"
9393
fi
9494

95-
appendToVar NVCC_PREPEND_FLAGS "--compiler-bindir=@ccRoot@/bin"
96-
9795
# NOTE: We set -Xfatbin=-compress-all, which reduces the size of the compiled
9896
# binaries. If binaries grow over 2GB, they will fail to link. This is a problem for us, as
9997
# the default set of CUDA capabilities we build can regularly cause this to occur (for

0 commit comments

Comments
 (0)