python3Packages.{numba,numba-cuda,cuda-bindings}: find libcuda in cuda_compat's compat dir

cuda_compat installs `libcuda.so.1` into `$out/compat`, not `$out/lib`, so with
`config.enableCudaDriverCompat` these packages pointed at a path that doesn't
exist. Use the library directory directly, as autoAddCudaCompatRunpath does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Connor Baker
2026-10-14 19:36:06 -07:00
parent ddc4f6e886
commit 627def2ec0
5 changed files with 18 additions and 18 deletions

View File

@@ -31,13 +31,13 @@ let
cudaLibPaths = {
libcuda =
# Use cuda_compat to provide libcuda.so on pre-Thor Jetsons
# Use cuda_compat to provide libcuda.so from its `compat` directory
if (cudaPackages.cuda_compat.meta.available or false) then
cudaPackages.cuda_compat
"${cudaPackages.cuda_compat}/compat"
# Else, use the host CUDA driver library
else
addDriverRunpath.driverLink;
"${addDriverRunpath.driverLink}/lib";
libcudart = lib.getLib cudaPackages.cuda_cudart;
# libcudla is only available on Xavier and Orin Jetson devices
libcudla =
@@ -112,12 +112,12 @@ buildPythonPackage (finalAttrs: {
substituteInPlace cuda/bindings/_internal/nvjitlink_linux.pyx \
--replace-fail \
"handle = dlopen('libcuda.so.1'" \
"handle = dlopen('${cudaLibPaths.libcuda}/lib/libcuda.so.1'"
"handle = dlopen('${cudaLibPaths.libcuda}/libcuda.so.1'"
substituteInPlace cuda/bindings/_bindings/cydriver.pyx.in \
--replace-fail \
"path = 'libcuda.so.1'" \
"path = '${cudaLibPaths.libcuda}/lib/libcuda.so.1'"
"path = '${cudaLibPaths.libcuda}/libcuda.so.1'"
''
+ (versionSpecificAttrs.postPatch or "");

View File

@@ -66,7 +66,7 @@ index 6fc1ca20c77..6090745eb4e 100644
+ try:
+ handle = CDLL("libcuda.so.1")._handle
+ except OSError:
+ handle = CDLL("@libcuda@/lib/libcuda.so.1")._handle
+ handle = CDLL("@libcuda@/libcuda.so.1")._handle
return <void*>handle
@@ -204,7 +204,7 @@ index 1ae37127bd1..eb7b9054cf1 100644
+ CDLL("libcuda.so.1")
+except OSError:
+ try:
+ CDLL("@libcuda@/lib/libcuda.so.1")
+ CDLL("@libcuda@/libcuda.so.1")
+ except OSError:
+ pass
+

View File

@@ -37,13 +37,13 @@ let
else
lib.getLib cudaPackages.libnvvm;
libCudaPath =
# `cuda_compat` provides `libcuda.so` on pre-Thor Jetsons
libCudaDir =
# `cuda_compat` provides `libcuda.so` in its `compat` directory
if (cudaPackages.cuda_compat.meta.available or false) then
cudaPackages.cuda_compat
"${cudaPackages.cuda_compat}/compat"
# Else: the host driver library
else
addDriverRunpath.driverLink;
"${addDriverRunpath.driverLink}/lib";
cudartInclude = "${lib.getInclude cudaPackages.cuda_cudart}/include";
# `cuda/atomic` & al., to compile the NRT headers with NVRTC
@@ -89,7 +89,7 @@ buildPythonPackage.override { stdenv = cudaPackages.backendStdenv; } (finalAttrs
substituteInPlace numba_cuda/numba/cuda/cudadrv/driver.py \
--replace-fail \
'dldir = ["/usr/lib", "/usr/lib64"]' \
'dldir = ["${libCudaPath}/lib"]'
'dldir = ["${libCudaDir}"]'
''
# Expanded at parse time even when overridden, making the build log look like `make` failed
+ ''

View File

@@ -47,13 +47,13 @@ let
else
"${lib.getLib cudaPackages.libnvvm}";
libCudaPath =
# Use cuda_compat to provide libcuda.so on pre-Thor Jetsons
libCudaDir =
# Use cuda_compat to provide libcuda.so from its `compat` directory
if (cudaPackages.cuda_compat.meta.available or false) then
cudaPackages.cuda_compat
"${cudaPackages.cuda_compat}/compat"
# Else, use the host CUDA driver library
else
addDriverRunpath.driverLink;
"${addDriverRunpath.driverLink}/lib";
in
buildPythonPackage (finalAttrs: {
version = "0.67.0";
@@ -80,7 +80,7 @@ buildPythonPackage (finalAttrs: {
# Hardcode the paths of the NVIDIA libraries which numba looks up at runtime, instead of
# relying on its discovery heuristics (conda environment, `CUDA_HOME`, `/usr/local/cuda`, ...)
(replaceVars ./nvidia-libs-paths.patch {
libcuda = libCudaPath;
libcuda = libCudaDir;
libcudart = lib.getLib cudaPackages.cuda_cudart;
libcudart_static = lib.getOutput "static" cudaPackages.cuda_cudart;
libnvrtc = lib.getLib cudaPackages.cuda_nvrtc;

View File

@@ -37,7 +37,7 @@ index bea271fce..79312f1ae 100644
# Assume to be *nix like
dlloader = ctypes.CDLL
- dldir = ['/usr/lib', '/usr/lib64']
+ dldir = ['@libcuda@/lib']
+ dldir = ['@libcuda@']
dlnames = ['libcuda.so', 'libcuda.so.1']
if envpath: