Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 pythonAtLeast, 5 pythonOlder, 6 fetchFromGitHub, 7 python, 8 buildPythonPackage, 9 setuptools, 10 numpy, 11 numpy_2, 12 llvmlite, 13 libcxx, 14 importlib-metadata, 15 substituteAll, 16 runCommand, 17 symlinkJoin, 18 writers, 19 numba, 20 21 config, 22 23 # CUDA-only dependencies: 24 addDriverRunpath, 25 autoAddDriverRunpath, 26 cudaPackages, 27 28 # CUDA flags: 29 cudaSupport ? config.cudaSupport, 30}: 31 32let 33 cudatoolkit = cudaPackages.cuda_nvcc; 34in 35buildPythonPackage rec { 36 version = "0.60.0"; 37 pname = "numba"; 38 pyproject = true; 39 40 disabled = pythonOlder "3.8" || pythonAtLeast "3.13"; 41 42 src = fetchFromGitHub { 43 owner = "numba"; 44 repo = "numba"; 45 rev = "refs/tags/${version}"; 46 # Upstream uses .gitattributes to inject information about the revision 47 # hash and the refname into `numba/_version.py`, see: 48 # 49 # - https://git-scm.com/docs/gitattributes#_export_subst and 50 # - https://github.com/numba/numba/blame/5ef7c86f76a6e8cc90e9486487294e0c34024797/numba/_version.py#L25-L31 51 # 52 # Hence this hash may change if GitHub / Git will change it's behavior. 53 # Hopefully this will not happen until the next release. We are fairly sure 54 # that upstream relies on those strings to be valid, that's why we don't 55 # use `forceFetchGit = true;`.` If in the future we'll observe the hash 56 # changes too often, we can always use forceFetchGit, and inject the 57 # relevant strings ourselves, using `sed` commands, in extraPostFetch. 58 hash = "sha256-hUL281wHLA7wo8umzBNhiGJikyIF2loCzjLECuC+pO0="; 59 }; 60 61 postPatch = '' 62 substituteInPlace numba/cuda/cudadrv/driver.py \ 63 --replace-fail \ 64 "dldir = [" \ 65 "dldir = [ '${addDriverRunpath.driverLink}/lib', " 66 ''; 67 68 env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1"; 69 70 build-system = [ 71 setuptools 72 numpy_2 73 ]; 74 75 nativeBuildInputs = lib.optionals cudaSupport [ 76 autoAddDriverRunpath 77 cudaPackages.cuda_nvcc 78 ]; 79 80 buildInputs = lib.optionals cudaSupport [ cudaPackages.cuda_cudart ]; 81 82 dependencies = [ 83 numpy 84 llvmlite 85 setuptools 86 ] ++ lib.optionals (pythonOlder "3.9") [ importlib-metadata ]; 87 88 patches = lib.optionals cudaSupport [ 89 (substituteAll { 90 src = ./cuda_path.patch; 91 cuda_toolkit_path = cudatoolkit; 92 cuda_toolkit_lib_path = lib.getLib cudatoolkit; 93 }) 94 ]; 95 96 # run a smoke test in a temporary directory so that 97 # a) Python picks up the installed library in $out instead of the build files 98 # b) we have somewhere to put $HOME so some caching tests work 99 # c) it doesn't take 6 CPU hours for the full suite 100 checkPhase = '' 101 runHook preCheck 102 103 pushd $(mktemp -d) 104 HOME=. ${python.interpreter} -m numba.runtests -m $NIX_BUILD_CORES numba.tests.test_usecases 105 popd 106 107 runHook postCheck 108 ''; 109 110 pythonImportsCheck = [ "numba" ]; 111 112 passthru.testers.cuda-detect = 113 writers.writePython3Bin "numba-cuda-detect" 114 { libraries = [ (numba.override { cudaSupport = true; }) ]; } 115 '' 116 from numba import cuda 117 cuda.detect() 118 ''; 119 passthru.tests = { 120 # CONTRIBUTOR NOTE: numba also contains CUDA tests, though these cannot be run in 121 # this sandbox environment. Consider running similar commands to those below outside the 122 # sandbox manually if you have the appropriate hardware; support will be detected 123 # and the corresponding tests enabled automatically. 124 # Also, the full suite currently does not complete on anything but x86_64-linux. 125 fullSuite = runCommand "${pname}-test" { } '' 126 pushd $(mktemp -d) 127 # pip and python in $PATH is needed for the test suite to pass fully 128 PATH=${ 129 python.withPackages (p: [ 130 p.numba 131 p.pip 132 ]) 133 }/bin:$PATH 134 HOME=$PWD python -m numba.runtests -m $NIX_BUILD_CORES 135 popd 136 touch $out # stop Nix from complaining no output was generated and failing the build 137 ''; 138 }; 139 140 meta = with lib; { 141 description = "Compiling Python code using LLVM"; 142 homepage = "https://numba.pydata.org/"; 143 license = licenses.bsd2; 144 mainProgram = "numba"; 145 }; 146}