1{ stdenv
2, llvmPackages
3, lib
4, fetchFromGitHub
5, cmake
6, libffi
7, libpng
8, libjpeg
9, mesa
10, libGL
11, eigen
12, openblas
13, blas
14, lapack
15}:
16
17assert blas.implementation == "openblas" && lapack.implementation == "openblas";
18
19stdenv.mkDerivation rec {
20 pname = "halide";
21 version = "16.0.0";
22
23 src = fetchFromGitHub {
24 owner = "halide";
25 repo = "Halide";
26 rev = "v${version}";
27 sha256 = "sha256-lJQrXkJgBmGb/QMSxwuPkkHOSgEDowLWzIolp1km2Y8=";
28 };
29
30 postPatch = ''
31 # See https://github.com/halide/Halide/issues/7785
32 substituteInPlace 'src/runtime/HalideRuntime.h' \
33 --replace '#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
34 #define HALIDE_CPP_COMPILER_HAS_FLOAT16' \
35 '#if defined(__x86_64__) || defined(__i386__)
36 #define HALIDE_CPP_COMPILER_HAS_FLOAT16'
37 ''
38 # Note: on x86_64-darwin, clang fails to find AvailabilityVersions.h, so we remove it.
39 # Halide uses AvailabilityVersions.h and TargetConditionals.h to determine whether
40 # ::aligned_alloc is available. For us, it isn't.
41 + lib.optionalString (stdenv.isDarwin && stdenv.isx86_64) ''
42 substituteInPlace 'src/runtime/HalideBuffer.h' \
43 --replace '#ifdef __APPLE__
44 #include <AvailabilityVersions.h>
45 #include <TargetConditionals.h>
46 #endif' \
47 ' ' \
48 --replace 'TARGET_OS_OSX && (__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_15)' \
49 '1' \
50 --replace 'TARGET_OS_IPHONE && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_14_0)' \
51 '0'
52 '';
53
54 cmakeFlags = [
55 "-DWARNINGS_AS_ERRORS=OFF"
56 "-DWITH_PYTHON_BINDINGS=OFF"
57 "-DTARGET_WEBASSEMBLY=OFF"
58 # Disable performance tests since they may fail on busy machines
59 "-DWITH_TEST_PERFORMANCE=OFF"
60 # Disable fuzzing tests -- this has become the default upstream after the
61 # v16 release (See https://github.com/halide/Halide/commit/09c5d1d19ec8e6280ccbc01a8a12decfb27226ba)
62 # These tests also fail to compile on Darwin because of some missing command line options...
63 "-DWITH_TEST_FUZZ=OFF"
64 ];
65
66 doCheck = true;
67
68 # Note: disable mullapudi2016_fibonacci because it requires too much
69 # parallelism for remote builders
70 preCheck = ''
71 checkFlagsArray+=("ARGS=-E 'mullapudi2016_fibonacci'")
72 '';
73
74 # Note: only openblas and not atlas part of this Nix expression
75 # see pkgs/development/libraries/science/math/liblapack/3.5.0.nix
76 # to get a hint howto setup atlas instead of openblas
77 buildInputs = [
78 llvmPackages.llvm
79 llvmPackages.lld
80 llvmPackages.openmp
81 llvmPackages.libclang
82 libffi
83 libpng
84 libjpeg
85 eigen
86 openblas
87 ] ++ lib.optionals (!stdenv.isDarwin) [
88 mesa
89 libGL
90 ];
91
92 nativeBuildInputs = [ cmake ];
93
94 meta = with lib; {
95 description = "C++ based language for image processing and computational photography";
96 homepage = "https://halide-lang.org";
97 license = licenses.mit;
98 platforms = platforms.all;
99 maintainers = with maintainers; [ ck3d atila twesterhout ];
100 };
101}