nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 99 lines 3.7 kB view raw
1# TODO(@connorbaker): cuda_cudart.dev depends on crt/host_config.h, which is from 2# (getDev cuda_nvcc). It would be nice to be able to encode that. 3{ 4 _cuda, 5 addDriverRunpath, 6 buildRedist, 7 cuda_cccl, 8 cuda_compat, 9 cuda_crt, 10 cuda_nvcc, 11 cudaAtLeast, 12 lib, 13}: 14buildRedist (finalAttrs: { 15 redistName = "cuda"; 16 pname = "cuda_cudart"; 17 18 # NOTE: A number of packages expect cuda_cudart to be in a single directory. We restrict the package to a single 19 # output to avoid breaking these assumptions. As an example, CMake expects the static libraries to exist alongside 20 # the dynamic libraries. 21 outputs = [ 22 "out" 23 ]; 24 25 # We have stubs but we don't have an explicit stubs output. 26 includeRemoveStubsFromRunpathHook = true; 27 28 propagatedBuildOutputs = 29 # required by CMake 30 lib.optionals (lib.elem "static" finalAttrs.outputs) [ "static" ] 31 # always propagate, even when cuda_compat is used, to avoid symbol linking errors 32 ++ lib.optionals (lib.elem "stubs" finalAttrs.outputs) [ "stubs" ]; 33 34 # When cuda_compat is available, propagate it. 35 # NOTE: `cuda_compat` can be disabled by setting the package to `null`. This is useful in cases where 36 # the host OS has a recent enough CUDA driver that the compatibility library isn't needed. 37 propagatedBuildInputs = 38 # TODO(@SomeoneSerge): Consider propagating `crt/host_config.h`, but only 39 # once we managed to split out `cuda_nvcc`'s headers into a separate output 40 # 41 # TODO(@connorbaker): Check that the dependency offset for this is correct. 42 # 43 # [ (lib.getInclude cuda_nvcc) ] 44 45 # TODO(@connorbaker): From CUDA 13.0, crt/host_config.h is in cuda_crt 46 lib.optionals (cudaAtLeast "13.0") [ (lib.getOutput "include" cuda_crt) ] 47 # Add the dependency on CCCL's include directory. 48 # - nv/target 49 # TODO(@connorbaker): Check that the dependency offset for this is correct. 50 ++ [ (lib.getOutput "include" cuda_cccl) ] 51 # NOTE: cuda_compat may be null or unavailable 52 ++ lib.optionals (cuda_compat.meta.available or false) [ cuda_compat ]; 53 54 allowFHSReferences = false; 55 56 # Patch the `cudart` package config files so they reference lib 57 postPatch = '' 58 local path="" 59 while IFS= read -r -d $'\0' path; do 60 nixLog "patching $path" 61 sed -i \ 62 -e "s|^cudaroot\s*=.*\$||" \ 63 -e "s|^Libs\s*:\(.*\)\$|Libs: \1 -Wl,-rpath,${addDriverRunpath.driverLink}/lib|" \ 64 "$path" 65 done < <(find -iname 'cudart-*.pc' -print0) 66 unset -v path 67 '' 68 # Patch the `cuda` package config files so they reference stubs 69 # TODO: Will this always pull in the stubs output and cause its setup hook to be executed? 70 + '' 71 local path="" 72 while IFS= read -r -d $'\0' path; do 73 nixLog "patching $path" 74 sed -i \ 75 -e "s|^cudaroot\s*=.*\$||" \ 76 -e "s|^libdir\s*=.*/lib\$|libdir=''${!outputStubs:?}/lib/stubs|" \ 77 -e "s|^Libs\s*:\(.*\)\$|Libs: \1 -Wl,-rpath,${addDriverRunpath.driverLink}/lib|" \ 78 "$path" 79 done < <(find -iname 'cuda-*.pc' -print0) 80 unset -v path 81 ''; 82 83 # Namelink may not be enough, add a soname. 84 # Cf. https://gitlab.kitware.com/cmake/cmake/-/issues/25536 85 # NOTE: Relative symlinks is fine since this is all within the same output. 86 postInstall = '' 87 pushd "''${!outputStubs:?}/lib/stubs" >/dev/null 88 if [[ -f libcuda.so && ! -f libcuda.so.1 ]]; then 89 nixLog "creating versioned symlink for libcuda.so stub" 90 ln -srv libcuda.so libcuda.so.1 91 fi 92 popd >/dev/null 93 ''; 94 95 # "Never again", cf. https://github.com/NixOS/nixpkgs/pull/457424 96 disallowedRequisites = [ (lib.getBin cuda_nvcc) ]; 97 98 meta.description = "CUDA Runtime"; 99})