cudaPackages.cuda_nvcc: wrap binary so NVCC can always find compiler (#465329)

This commit is contained in:
Someone
2025-11-28 10:42:40 +00:00
committed by GitHub
3 changed files with 14 additions and 8 deletions
@@ -8,6 +8,7 @@
cuda_cccl,
lib,
libnvvm,
makeBinaryWrapper,
}:
buildRedist (finalAttrs: {
redistName = "cuda";
@@ -22,6 +23,10 @@ buildRedist (finalAttrs: {
# The nvcc and cicc binaries contain hard-coded references to /usr
allowFHSReferences = true;
nativeBuildInputs = [
makeBinaryWrapper
];
# Entries here will be in nativeBuildInputs when cuda_nvcc is in nativeBuildInputs
propagatedBuildInputs = [ setupCudaHook ];
@@ -144,13 +149,19 @@ buildRedist (finalAttrs: {
EOF
''
# Add the dependency on backendStdenv.cc to the nvcc.profile.
# NOTE: NVCC explodes in horrifying fashion if GCC is not on PATH -- it fails even before
# reading nvcc.profile!
+ ''
nixLog "adding backendStdenv.cc to nvcc.profile"
nixLog "setting compiler-bindir to backendStdenv.cc in nvcc.profile"
cat << EOF >> "''${!outputBin:?}/bin/nvcc.profile"
# Fix a compatible backend compiler
PATH += "${backendStdenv.cc}/bin":
compiler-bindir = ${backendStdenv.cc}/bin
EOF
nixLog "wrapping nvcc to add backendStdenv.cc to its PATH"
wrapProgramBinary \
"''${!outputBin:?}/bin/nvcc" \
--prefix PATH : ${lib.makeBinPath [ backendStdenv.cc ]}
''
);
@@ -5,9 +5,6 @@ makeSetupHook {
substitutions.setupCudaHook = placeholder "out";
# Point NVCC at a compatible compiler
substitutions.ccRoot = "${backendStdenv.cc}";
# Required in addition to ccRoot as otherwise bin/gcc is looked up
# when building CMakeCUDACompilerId.cu
substitutions.ccFullPath = "${backendStdenv.cc}/bin/${backendStdenv.cc.targetPrefix}c++";
@@ -92,8 +92,6 @@ setupCUDAToolkitCompilers() {
export CUDAHOSTCXX="@ccFullPath@"
fi
appendToVar NVCC_PREPEND_FLAGS "--compiler-bindir=@ccRoot@/bin"
# NOTE: We set -Xfatbin=-compress-all, which reduces the size of the compiled
# binaries. If binaries grow over 2GB, they will fail to link. This is a problem for us, as
# the default set of CUDA capabilities we build can regularly cause this to occur (for