cudaPackages.autoAddCudaCompatRunpath: make hook a no-op when cuda_compat is unavailable

Signed-off-by: Connor Baker <ConnorBaker01@gmail.com>
This commit is contained in:
Connor Baker
2025-09-29 22:36:46 +00:00
parent 20f3fc3cfd
commit 09ea5703ac
2 changed files with 20 additions and 15 deletions
@@ -3,18 +3,23 @@
# coming from the cuda_compat package by adding it to the RUNPATH.
echo "Sourcing auto-add-cuda-compat-runpath-hook"
if [[ -z "@libcudaPath@" ]]; then
echo "auto-add-cuda-compat-runpath-hook: cuda_compat not available, skipping hook"
return
fi
addCudaCompatRunpath() {
local libPath
local origRpath
if [[ $# -eq 0 ]]; then
echo "addCudaCompatRunpath: no library path provided" >&2
nixLog "no library path provided" >&2
exit 1
elif [[ $# -gt 1 ]]; then
echo "addCudaCompatRunpath: too many arguments" >&2
nixLog "too many arguments" >&2
exit 1
elif [[ "$1" == "" ]]; then
echo "addCudaCompatRunpath: empty library path" >&2
nixLog "empty library path" >&2
exit 1
else
libPath="$1"
@@ -6,24 +6,24 @@
{
autoFixElfFiles,
cuda_compat,
lib,
makeSetupHook,
}:
let
# cuda_compat can be null or broken, depending on the platform, CUDA release, and compute capability.
# To avoid requiring all consumers of this hook to do these checks, we do them here; the hook is a no-op if
# cuda_compat is not available.
enableHook = cuda_compat != null && cuda_compat.meta.available;
in
makeSetupHook {
name = "auto-add-cuda-compat-runpath-hook";
propagatedBuildInputs = [ autoFixElfFiles ];
propagatedBuildInputs = lib.optionals enableHook [ autoFixElfFiles ];
substitutions = {
libcudaPath = "${cuda_compat}/compat";
libcudaPath = lib.optionalString enableHook "${cuda_compat}/compat";
};
meta =
let
# Handle `null`s in pre-`cuda_compat` releases,
# and `badPlatform`s for `!isJetsonBuild`.
platforms = cuda_compat.meta.platforms or [ ];
badPlatforms = cuda_compat.meta.badPlatforms or platforms;
in
{
inherit badPlatforms platforms;
};
passthru = {
inherit enableHook;
};
} ./auto-add-cuda-compat-runpath.sh