Skip to content

Commit

Permalink
halide: 18.0.0 -> 19.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
twesterhout committed Jan 22, 2025
1 parent 041c867 commit 998cea9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 24 deletions.
89 changes: 67 additions & 22 deletions pkgs/development/compilers/halide/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
lib,
fetchFromGitHub,
cmake,
fetchpatch2,
flatbuffers,
libffi,
libpng,
Expand All @@ -14,48 +15,81 @@
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 = [
# The following two patches fix cmake/HalidePackageConfigHelpers.cmake to
# support specifying an absolute library install path (which is what Nix
# does when "lib" is included as a separate output)
(fetchpatch2 {
url = "https://github.com/halide/Halide/commit/ac2cd23951aff9ac3b765e51938f1e576f1f0ee9.diff";
hash = "sha256-kHUecmmcz/4wLGAyo7NHHF3gMBDxPvhUH8vSC/n+Pd0=";
})
(fetchpatch2 {
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"
(lib.cmakeBool "WITH_TESTS" doCheck)
(lib.cmakeBool "WITH_TUTORIALS" doCheck)
# 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"}"
(lib.cmakeBool "Halide_LLVM_SHARED_LIBS" wasmSupport)
];

doCheck = true;
outputs = [
"out"
"lib"
];

inherit doCheck;

preCheck =
let
Expand All @@ -73,11 +107,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
Expand All @@ -97,12 +138,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
Expand All @@ -124,5 +168,6 @@ stdenv.mkDerivation rec {
atila
twesterhout
];
broken = !stdenv.buildPlatform.canExecute stdenv.hostPlatform;
};
}
2 changes: 1 addition & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { });
Expand Down
2 changes: 1 addition & 1 deletion pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };

Expand Down

0 comments on commit 998cea9

Please sign in to comment.