diff --git a/pkgs/development/compilers/halide/default.nix b/pkgs/development/compilers/halide/default.nix index a21fdd937d4d63..83cf5120850dee 100644 --- a/pkgs/development/compilers/halide/default.nix +++ b/pkgs/development/compilers/halide/default.nix @@ -4,6 +4,7 @@ lib, fetchFromGitHub, cmake, + fetchpatch, flatbuffers, libffi, libpng, @@ -14,48 +15,78 @@ openblas, blas, lapack, + removeReferencesTo, + ninja, pythonSupport ? false, python3Packages ? null, + wasmSupport ? false, + wabt, + doCheck ? true, }: assert blas.implementation == "openblas" && lapack.implementation == "openblas"; stdenv.mkDerivation rec { pname = "halide"; - version = "18.0.0"; + version = "19.0.0"; src = fetchFromGitHub { owner = "halide"; repo = "Halide"; rev = "v${version}"; - hash = "sha256-BPalUh9EgdCqVaWC1HoreyyRcPQc4QMIYnLrRoNDDCI="; + hash = "sha256-0SFGX4G6UR8NS4UsdFOb99IBq2/hEkr/Cm2p6zkIh/8="; }; - postPatch = '' - # See https://github.com/halide/Halide/issues/7785 - substituteInPlace 'src/runtime/HalideRuntime.h' \ - --replace '#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__) - #define HALIDE_CPP_COMPILER_HAS_FLOAT16' \ - '#if defined(__x86_64__) || defined(__i386__) - #define HALIDE_CPP_COMPILER_HAS_FLOAT16' - ''; + patches = [ + (fetchpatch { + url = "https://github.com/halide/Halide/commit/ac2cd23951aff9ac3b765e51938f1e576f1f0ee9.diff"; + hash = "sha256-kHUecmmcz/4wLGAyo7NHHF3gMBDxPvhUH8vSC/n+Pd0="; + }) + (fetchpatch { + url = "https://github.com/halide/Halide/commit/59f4fff30f4ab628da9aa7e5f77a7f1bb218a779.diff"; + hash = "sha256-r+InpY1kDWeqWJUqbynFfwZZmnHG+fo3CVdAUlYCvcA="; + }) + ]; + + postPatch = + '' + substituteInPlace src/runtime/CMakeLists.txt --replace-fail \ + '-isystem "''${VulkanHeaders_INCLUDE_DIR}"' \ + '-isystem "''${VulkanHeaders_INCLUDE_DIR}" + -isystem "${llvmPackages.clang}/resource-root/include"' + '' + # Upstream Halide include a check in their CMake files that forces Halide to + # link LLVM dynamically because of WebAssembly. It unnecessarily increases + # the closure size in cases when the WebAssembly target is not used. Hence, + # the following hack + + lib.optionalString (!wasmSupport) '' + substituteInPlace cmake/FindHalide_LLVM.cmake --replace-fail \ + 'if (comp STREQUAL "WebAssembly")' \ + 'if (FALSE)' + ''; cmakeFlags = [ - "-DWARNINGS_AS_ERRORS=OFF" "-DWITH_PYTHON_BINDINGS=${if pythonSupport then "ON" else "OFF"}" - "-DTARGET_WEBASSEMBLY=OFF" + "-DWITH_TESTS=${if doCheck then "ON" else "OFF"}" + "-DWITH_TUTORIALS=${if doCheck then "ON" else "OFF"}" # Disable performance tests since they may fail on busy machines "-DWITH_TEST_PERFORMANCE=OFF" # Disable fuzzing tests -- this has become the default upstream after the # v16 release (See https://github.com/halide/Halide/commit/09c5d1d19ec8e6280ccbc01a8a12decfb27226ba) # These tests also fail to compile on Darwin because of some missing command line options... "-DWITH_TEST_FUZZ=OFF" - # Disable FetchContent for flatbuffers and use the version from nixpkgs instead - "-DFLATBUFFERS_USE_FETCHCONTENT=OFF" - "-DPYBIND11_USE_FETCHCONTENT=OFF" + # Disable FetchContent and use versions from nixpkgs instead + "-DHalide_USE_FETCHCONTENT=OFF" + "-DHalide_WASM_BACKEND=${if wasmSupport then "wabt" else "OFF"}" + "-DHalide_LLVM_SHARED_LIBS=${if wasmSupport then "ON" else "OFF"}" ]; - doCheck = true; + outputs = [ + "out" + "lib" + ]; + + inherit doCheck; preCheck = let @@ -73,11 +104,18 @@ stdenv.mkDerivation rec { checkFlagsArray+=("ARGS=-E '${disabledTests}'") ''; - postInstall = lib.optionalString pythonSupport '' - mkdir -p $out/${builtins.dirOf python3Packages.python.sitePackages} - mv -v $out/lib/python3/site-packages $out/${python3Packages.python.sitePackages} - rmdir $out/lib/python3/ - ''; + postInstall = + lib.optionalString pythonSupport '' + mkdir -p $lib/${builtins.dirOf python3Packages.python.sitePackages} + mv -v $lib/lib/python3/site-packages $lib/${python3Packages.python.sitePackages} + rmdir $lib/lib/python3/ + '' + # Debug symbols in the runtime include references to clang, but they're not + # required for running the code. llvmPackages.clang increases the runtime + # closure by at least a GB which is a waste, so we remove references to clang. + + lib.optionalString (stdenv != llvmPackages.stdenv) '' + remove-references-to -t ${llvmPackages.clang} $lib/lib/libHalide* + ''; # Note: only openblas and not atlas part of this Nix expression # see pkgs/development/libraries/science/math/liblapack/3.5.0.nix @@ -97,12 +135,15 @@ stdenv.mkDerivation rec { ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ libgbm libGL - ]; + ] + ++ lib.optionals wasmSupport [ wabt ]; nativeBuildInputs = [ cmake flatbuffers + removeReferencesTo + ninja ] ++ lib.optionals pythonSupport [ python3Packages.python @@ -124,5 +165,6 @@ stdenv.mkDerivation rec { atila twesterhout ]; + broken = !stdenv.buildPlatform.canExecute stdenv.hostPlatform; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index a7ba597d8c07e6..080715fa998cc9 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3621,7 +3621,7 @@ with pkgs; hal-hardware-analyzer = libsForQt5.callPackage ../applications/science/electronics/hal-hardware-analyzer { }; halide = callPackage ../development/compilers/halide { - llvmPackages = llvmPackages_18; + llvmPackages = llvmPackages_19; }; hareThirdParty = recurseIntoAttrs (callPackage ./hare-third-party.nix { }); diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 9dbb671c5b2b25..ab024ea28bbc99 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -5769,7 +5769,7 @@ self: super: with self; { hakuin = callPackage ../development/python-modules/hakuin { }; - halide = toPythonModule (pkgs.halide.override { pythonSupport = true; python3Packages = self; }); + halide = toPythonModule (pkgs.halide.override { pythonSupport = true; python3Packages = self; }).lib; halo = callPackage ../development/python-modules/halo { };