From 09ea5703ac5ec12ea0a49d2280350d3edb3fd948 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Mon, 29 Sep 2025 22:36:46 +0000 Subject: [PATCH] cudaPackages.autoAddCudaCompatRunpath: make hook a no-op when cuda_compat is unavailable Signed-off-by: Connor Baker --- .../auto-add-cuda-compat-runpath.sh | 11 ++++++--- .../autoAddCudaCompatRunpath/package.nix | 24 +++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/pkgs/development/cuda-modules/packages/autoAddCudaCompatRunpath/auto-add-cuda-compat-runpath.sh b/pkgs/development/cuda-modules/packages/autoAddCudaCompatRunpath/auto-add-cuda-compat-runpath.sh index fc41024f1551..d4b37cce05a7 100644 --- a/pkgs/development/cuda-modules/packages/autoAddCudaCompatRunpath/auto-add-cuda-compat-runpath.sh +++ b/pkgs/development/cuda-modules/packages/autoAddCudaCompatRunpath/auto-add-cuda-compat-runpath.sh @@ -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" diff --git a/pkgs/development/cuda-modules/packages/autoAddCudaCompatRunpath/package.nix b/pkgs/development/cuda-modules/packages/autoAddCudaCompatRunpath/package.nix index 5df6535bc81d..242323052563 100644 --- a/pkgs/development/cuda-modules/packages/autoAddCudaCompatRunpath/package.nix +++ b/pkgs/development/cuda-modules/packages/autoAddCudaCompatRunpath/package.nix @@ -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