onnxruntime: use system eigen

This commit is contained in:
Someone Serge 2024-02-07 17:11:24 +00:00
parent 28c1d05437
commit 3392575c40
No known key found for this signature in database
GPG key ID: 7B0E3B1390D61DA4
2 changed files with 58 additions and 9 deletions

View file

@ -0,0 +1,45 @@
From a29cffa646356228d6ec7bd7ce21fe3ab90fdd19 Mon Sep 17 00:00:00 2001
From: Someone Serge <sergei.kozlukov@aalto.fi>
Date: Wed, 7 Feb 2024 16:59:09 +0000
Subject: [PATCH] eigen: allow dependency injection
---
cmake/external/eigen.cmake | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/cmake/external/eigen.cmake b/cmake/external/eigen.cmake
index c0f7ddc50e..996b83d18a 100644
--- a/cmake/external/eigen.cmake
+++ b/cmake/external/eigen.cmake
@@ -1,4 +1,3 @@
-
if (onnxruntime_USE_PREINSTALLED_EIGEN)
add_library(eigen INTERFACE)
file(TO_CMAKE_PATH ${eigen_SOURCE_PATH} eigen_INCLUDE_DIRS)
@@ -10,14 +9,21 @@ else ()
URL ${DEP_URL_eigen}
URL_HASH SHA1=${DEP_SHA1_eigen}
PATCH_COMMAND ${Patch_EXECUTABLE} --ignore-space-change --ignore-whitespace < ${PROJECT_SOURCE_DIR}/patches/eigen/Fix_Eigen_Build_Break.patch
+ FIND_PACKAGE_ARGS NAMES Eigen3
)
else()
FetchContent_Declare(
eigen
URL ${DEP_URL_eigen}
URL_HASH SHA1=${DEP_SHA1_eigen}
+ FIND_PACKAGE_ARGS NAMES Eigen3
)
endif()
- FetchContent_Populate(eigen)
- set(eigen_INCLUDE_DIRS "${eigen_SOURCE_DIR}")
+ FetchContent_MakeAvailable(eigen)
+ add_library(eigen ALIAS Eigen3::Eigen)
+
+ # Onnxruntime doesn't always use `eigen` as a target in
+ # `target_link_libraries`, sometimes it just uses
+ # `target_include_directories`:
+ get_target_property(eigen_INCLUDE_DIRS Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES)
endif()
--
2.42.0

View file

@ -5,6 +5,7 @@
, Foundation
, abseil-cpp
, cmake
, eigen
, gtest
, libpng
, nlohmann_json
@ -28,14 +29,6 @@ let
sha256 = "sha256-BYL7wxsYRI45l8C3VwxYIIocn5TzJnBtU0UZ9pHwwZw=";
};
eigen = fetchFromGitLab {
owner = "libeigen";
repo = "eigen";
# https://github.com/microsoft/onnxruntime/blob/v1.16.3/cgmanifests/cgmanifest.json#L571
rev = "e7248b26a1ed53fa030c5c459f7ea095dfd276ac";
hash = "sha256-uQ1YYV3ojbMVfHdqjXRyUymRPjJZV3WHT36PTxPRius=";
};
mp11 = fetchFromGitHub {
owner = "boostorg";
repo = "mp11";
@ -94,6 +87,17 @@ stdenv.mkDerivation rec {
fetchSubmodules = true;
};
patches = [
# If you stumble on these patches trying to update onnxruntime, check
# `git blame` and ping the introducers.
# Context: we want the upstream to
# - always try find_package first (FIND_PACKAGE_ARGS),
# - use MakeAvailable instead of the low-level Populate,
# - use Eigen3::Eigen as the target name (as declared by libeigen/eigen).
./0001-eigen-allow-dependency-injection.patch
];
nativeBuildInputs = [
cmake
pkg-config
@ -108,6 +112,7 @@ stdenv.mkDerivation rec {
]);
buildInputs = [
eigen
libpng
zlib
nlohmann_json
@ -142,7 +147,6 @@ stdenv.mkDerivation rec {
"-DFETCHCONTENT_QUIET=OFF"
"-DFETCHCONTENT_SOURCE_DIR_ABSEIL_CPP=${abseil-cpp.src}"
"-DFETCHCONTENT_SOURCE_DIR_DATE=${howard-hinnant-date}"
"-DFETCHCONTENT_SOURCE_DIR_EIGEN=${eigen}"
"-DFETCHCONTENT_SOURCE_DIR_FLATBUFFERS=${flatbuffers}"
"-DFETCHCONTENT_SOURCE_DIR_GOOGLE_NSYNC=${nsync.src}"
"-DFETCHCONTENT_SOURCE_DIR_MP11=${mp11}"