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 substituteInPlace src/runtime/CMakeLists.txt --replace-fail \
57 '-isystem "''${VulkanHeaders_INCLUDE_DIR}"' \
58 '-isystem "''${VulkanHeaders_INCLUDE_DIR}"
59 -isystem "${llvmPackages.clang}/resource-root/include"'
60 ''
61 # Upstream Halide include a check in their CMake files that forces Halide to
62 # link LLVM dynamically because of WebAssembly. It unnecessarily increases
63 # the closure size in cases when the WebAssembly target is not used. Hence,
64 # the following hack
65 + lib.optionalString (!wasmSupport) ''
66 substituteInPlace cmake/FindHalide_LLVM.cmake --replace-fail \
67 'if (comp STREQUAL "WebAssembly")' \
68 'if (FALSE)'
69 '';
70
71 cmakeFlags = [
72 "-DWITH_PYTHON_BINDINGS=${if pythonSupport then "ON" else "OFF"}"
73 (lib.cmakeBool "WITH_TESTS" doCheck)
74 (lib.cmakeBool "WITH_TUTORIALS" doCheck)
75 # Disable performance tests since they may fail on busy machines
76 "-DWITH_TEST_PERFORMANCE=OFF"
77 # Disable fuzzing tests -- this has become the default upstream after the
78 # v16 release (See https://github.com/halide/Halide/commit/09c5d1d19ec8e6280ccbc01a8a12decfb27226ba)
79 # These tests also fail to compile on Darwin because of some missing command line options...
80 "-DWITH_TEST_FUZZ=OFF"
81 # Disable FetchContent and use versions from nixpkgs instead
82 "-DHalide_USE_FETCHCONTENT=OFF"
83 "-DHalide_WASM_BACKEND=${if wasmSupport then "wabt" else "OFF"}"
84 (lib.cmakeBool "Halide_LLVM_SHARED_LIBS" wasmSupport)
85 ];
86
87 outputs = [
88 "out"
89 "lib"
90 ];
91
92 inherit doCheck;
93
94 disabledTests = [
95 # Requires too much parallelism for remote builders.
96 "mullapudi2016_fibonacci"
97 # Tests performance---flaky in CI
98 "mullapudi2016_reorder"
99 # Take too long---we don't want to run these in CI.
100 "adams2019_test_apps_autoscheduler"
101 "anderson2021_test_apps_autoscheduler"
102 "correctness_cross_compilation"
103 "correctness_simd_op_check_hvx"
104 ];
105
106 dontUseNinjaCheck = true;
107 nativeCheckInputs = [ ctestCheckHook ];
108
109 postInstall =
110 lib.optionalString pythonSupport ''
111 mkdir -p $lib/lib/${python3Packages.python.libPrefix}
112 mv -v $lib/lib/python3/site-packages $lib/lib/${python3Packages.python.libPrefix}
113 rmdir $lib/lib/python3/
114 ''
115 # Debug symbols in the runtime include references to clang, but they're not
116 # required for running the code. llvmPackages.clang increases the runtime
117 # closure by at least a GB which is a waste, so we remove references to clang.
118 + lib.optionalString (stdenv != llvmPackages.stdenv) ''
119 remove-references-to -t ${llvmPackages.clang} $lib/lib/libHalide*
120 '';
121
122 # Note: only openblas and not atlas part of this Nix expression
123 # see pkgs/development/libraries/science/math/liblapack/3.5.0.nix
124 # to get a hint howto setup atlas instead of openblas
125 buildInputs = [
126 llvmPackages.llvm
127 llvmPackages.lld
128 llvmPackages.openmp
129 llvmPackages.libclang
130 libffi
131 libpng
132 libjpeg
133 eigen
134 openblas
135 ]
136 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
137 libgbm
138 libGL
139 ]
140 ++ lib.optionals wasmSupport [ wabt ];
141
142 nativeBuildInputs = [
143 cmake
144 flatbuffers
145 removeReferencesTo
146 ninja
147 ]
148 ++ lib.optionals pythonSupport [
149 python3Packages.python
150 python3Packages.pybind11
151 ];
152
153 propagatedBuildInputs = lib.optionals pythonSupport [
154 python3Packages.numpy
155 python3Packages.imageio
156 ];
157
158 meta = with lib; {
159 description = "C++ based language for image processing and computational photography";
160 homepage = "https://halide-lang.org";
161 license = licenses.mit;
162 platforms = platforms.all;
163 maintainers = with maintainers; [
164 ck3d
165 atila
166 twesterhout
167 ];
168 broken = !stdenv.buildPlatform.canExecute stdenv.hostPlatform;
169 };
170})