Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 173 lines 5.2 kB view raw
1{ 2 stdenv, 3 llvmPackages, 4 lib, 5 fetchFromGitHub, 6 cmake, 7 fetchpatch2, 8 flatbuffers, 9 libffi, 10 libpng, 11 libjpeg, 12 libgbm, 13 libGL, 14 eigen, 15 openblas, 16 blas, 17 lapack, 18 removeReferencesTo, 19 ninja, 20 pythonSupport ? false, 21 python3Packages, 22 wasmSupport ? false, 23 wabt, 24 doCheck ? true, 25 ctestCheckHook, 26}: 27 28assert blas.implementation == "openblas" && lapack.implementation == "openblas"; 29 30stdenv.mkDerivation (finalAttrs: { 31 pname = "halide"; 32 version = "19.0.0"; 33 34 src = fetchFromGitHub { 35 owner = "halide"; 36 repo = "Halide"; 37 tag = "v${finalAttrs.version}"; 38 hash = "sha256-0SFGX4G6UR8NS4UsdFOb99IBq2/hEkr/Cm2p6zkIh/8="; 39 }; 40 41 patches = [ 42 # The following two patches fix cmake/HalidePackageConfigHelpers.cmake to 43 # support specifying an absolute library install path (which is what Nix 44 # does when "lib" is included as a separate output) 45 (fetchpatch2 { 46 url = "https://github.com/halide/Halide/commit/ac2cd23951aff9ac3b765e51938f1e576f1f0ee9.diff?full_index=1"; 47 hash = "sha256-JTktOTSyReDUEHTaPPMoi+/K/Gzg39i6MI97cO3654k="; 48 }) 49 (fetchpatch2 { 50 url = "https://github.com/halide/Halide/commit/59f4fff30f4ab628da9aa7e5f77a7f1bb218a779.diff?full_index=1"; 51 hash = "sha256-yOzE+1jai1w1GQisLYfu8F9pbTE/bYg0MTLq8rPXdGk="; 52 }) 53 ]; 54 55 postPatch = 56 '' 57 substituteInPlace src/runtime/CMakeLists.txt --replace-fail \ 58 '-isystem "''${VulkanHeaders_INCLUDE_DIR}"' \ 59 '-isystem "''${VulkanHeaders_INCLUDE_DIR}" 60 -isystem "${llvmPackages.clang}/resource-root/include"' 61 '' 62 # Upstream Halide include a check in their CMake files that forces Halide to 63 # link LLVM dynamically because of WebAssembly. It unnecessarily increases 64 # the closure size in cases when the WebAssembly target is not used. Hence, 65 # the following hack 66 + lib.optionalString (!wasmSupport) '' 67 substituteInPlace cmake/FindHalide_LLVM.cmake --replace-fail \ 68 'if (comp STREQUAL "WebAssembly")' \ 69 'if (FALSE)' 70 ''; 71 72 cmakeFlags = [ 73 "-DWITH_PYTHON_BINDINGS=${if pythonSupport then "ON" else "OFF"}" 74 (lib.cmakeBool "WITH_TESTS" doCheck) 75 (lib.cmakeBool "WITH_TUTORIALS" doCheck) 76 # Disable performance tests since they may fail on busy machines 77 "-DWITH_TEST_PERFORMANCE=OFF" 78 # Disable fuzzing tests -- this has become the default upstream after the 79 # v16 release (See https://github.com/halide/Halide/commit/09c5d1d19ec8e6280ccbc01a8a12decfb27226ba) 80 # These tests also fail to compile on Darwin because of some missing command line options... 81 "-DWITH_TEST_FUZZ=OFF" 82 # Disable FetchContent and use versions from nixpkgs instead 83 "-DHalide_USE_FETCHCONTENT=OFF" 84 "-DHalide_WASM_BACKEND=${if wasmSupport then "wabt" else "OFF"}" 85 (lib.cmakeBool "Halide_LLVM_SHARED_LIBS" wasmSupport) 86 ]; 87 88 outputs = [ 89 "out" 90 "lib" 91 ]; 92 93 inherit doCheck; 94 95 disabledTests = [ 96 # Requires too much parallelism for remote builders. 97 "mullapudi2016_fibonacci" 98 # Tests performance---flaky in CI 99 "mullapudi2016_reorder" 100 # Take too long---we don't want to run these in CI. 101 "adams2019_test_apps_autoscheduler" 102 "anderson2021_test_apps_autoscheduler" 103 "correctness_cross_compilation" 104 "correctness_simd_op_check_hvx" 105 ]; 106 107 dontUseNinjaCheck = true; 108 nativeCheckInputs = [ ctestCheckHook ]; 109 110 postInstall = 111 lib.optionalString pythonSupport '' 112 mkdir -p $lib/lib/${python3Packages.python.libPrefix} 113 mv -v $lib/lib/python3/site-packages $lib/lib/${python3Packages.python.libPrefix} 114 rmdir $lib/lib/python3/ 115 '' 116 # Debug symbols in the runtime include references to clang, but they're not 117 # required for running the code. llvmPackages.clang increases the runtime 118 # closure by at least a GB which is a waste, so we remove references to clang. 119 + lib.optionalString (stdenv != llvmPackages.stdenv) '' 120 remove-references-to -t ${llvmPackages.clang} $lib/lib/libHalide* 121 ''; 122 123 # Note: only openblas and not atlas part of this Nix expression 124 # see pkgs/development/libraries/science/math/liblapack/3.5.0.nix 125 # to get a hint howto setup atlas instead of openblas 126 buildInputs = 127 [ 128 llvmPackages.llvm 129 llvmPackages.lld 130 llvmPackages.openmp 131 llvmPackages.libclang 132 libffi 133 libpng 134 libjpeg 135 eigen 136 openblas 137 ] 138 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ 139 libgbm 140 libGL 141 ] 142 ++ lib.optionals wasmSupport [ wabt ]; 143 144 nativeBuildInputs = 145 [ 146 cmake 147 flatbuffers 148 removeReferencesTo 149 ninja 150 ] 151 ++ lib.optionals pythonSupport [ 152 python3Packages.python 153 python3Packages.pybind11 154 ]; 155 156 propagatedBuildInputs = lib.optionals pythonSupport [ 157 python3Packages.numpy 158 python3Packages.imageio 159 ]; 160 161 meta = with lib; { 162 description = "C++ based language for image processing and computational photography"; 163 homepage = "https://halide-lang.org"; 164 license = licenses.mit; 165 platforms = platforms.all; 166 maintainers = with maintainers; [ 167 ck3d 168 atila 169 twesterhout 170 ]; 171 broken = !stdenv.buildPlatform.canExecute stdenv.hostPlatform; 172 }; 173})