guix_mirror_bot pushed a commit to branch master
in repository guix.
commit dd9028f67a7cfcc4fb144bdf614a3e950ca63c22
Author: Danny Milosavljevic <[email protected]>
AuthorDate: Fri Feb 13 22:58:38 2026 +0100
gnu: Add onnx-for-onnxruntime.
* gnu/packages/patches/onnx-1.17.0-for-onnxruntime.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register it.
* gnu/packages/machine-learning.scm (onnx-1.17.0-for-onnxruntime): New
variable.
[source]: Use patch.
Change-Id: Ib5dab812c6a0f970e65d0764a4889a3eee0ebda2
---
gnu/local.mk | 1 +
gnu/packages/machine-learning.scm | 39 +++++++++++
.../patches/onnx-1.17.0-for-onnxruntime.patch | 77 ++++++++++++++++++++++
3 files changed, 117 insertions(+)
diff --git a/gnu/local.mk b/gnu/local.mk
index 8b75128b96..77e2f39e13 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2003,6 +2003,7 @@ dist_patch_DATA =
\
%D%/packages/patches/oneko-remove-nonfree-characters.patch \
%D%/packages/patches/onetbb-other-arches.patch \
%D%/packages/patches/online-judge-tools.patch \
+ %D%/packages/patches/onnx-1.17.0-for-onnxruntime.patch \
%D%/packages/patches/onnx-optimizer-system-library.patch \
%D%/packages/patches/onnx-1.13.1-use-system-googletest.patch \
%D%/packages/patches/onnx-shared-libraries.patch \
diff --git a/gnu/packages/machine-learning.scm
b/gnu/packages/machine-learning.scm
index 3c5943961e..6b0619f33e 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -2080,6 +2080,45 @@ operators and standard data types.")
(define-deprecated-package python-onnx
onnx)
+(define-public onnx-for-onnxruntime
+ (package
+ (inherit onnx)
+ (name "onnx-for-onnxruntime")
+ (source
+ (origin
+ (inherit (package-source onnx))
+ (patches (append (search-patches "onnx-1.17.0-for-onnxruntime.patch")
+ (origin-patches (package-source onnx))))))
+ ;; Use cmake-build-system instead of pyproject-build-system so that
+ ;; only the C++ static library is built and installed. The Python
+ ;; onnx package (with schemas registered) is provided by regular
+ ;; onnx; this variant has ONNX_DISABLE_STATIC_REGISTRATION=ON which
+ ;; would break onnx.shape_inference if its Python files ended up on
+ ;; PYTHONPATH.
+ (build-system cmake-build-system)
+ (arguments
+ (list
+ #:tests? #f ; tests fail without schema registration
+ #:configure-flags
+ #~(list "-DBUILD_SHARED_LIBS=OFF"
+ "-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF"
+ ;; Disable ONNX's schema registration so onnxruntime
+ ;; handles it. See
+ ;; <https://onnxruntime.ai/docs/build/dependencies.html>.
+ "-DONNX_DISABLE_STATIC_REGISTRATION=ON"
+ "-DONNX_BUILD_TESTS=OFF"
+ "-DONNX_BUILD_BENCHMARKS=OFF"
+ "-DONNX_ML=ON"
+ "-DONNX_USE_LITE_PROTO=OFF"
+ "-DBUILD_ONNX_PYTHON=OFF")))
+ (inputs (list protobuf-static-for-onnxruntime))
+ (native-inputs (list python-minimal-wrapper pybind11))
+ (propagated-inputs '())
+ (description
+ "This variant of the ONNX package is built as a static C++ library
+with schema registration disabled, for linking into onnxruntime. It
+should not be used standalone.")))
+
(define-public onnx-optimizer
(package
(name "onnx-optimizer")
diff --git a/gnu/packages/patches/onnx-1.17.0-for-onnxruntime.patch
b/gnu/packages/patches/onnx-1.17.0-for-onnxruntime.patch
new file mode 100644
index 0000000000..91e4a34665
--- /dev/null
+++ b/gnu/packages/patches/onnx-1.17.0-for-onnxruntime.patch
@@ -0,0 +1,77 @@
+From 23f764490838c0855798471fb93ec3aadd723e18 Mon Sep 17 00:00:00 2001
+From: Changming Sun <[email protected]>
+Date: Fri, 4 Apr 2025 18:09:33 -0700
+Subject: Fix ONNX build warnings and remove std::filesystem dependency.
+
+Extracted from cmake/patches/onnx/onnx.patch in onnxruntime PR #24012
+<https://github.com/microsoft/onnxruntime/pull/24012> (commit
+23f764490838c0855798471fb93ec3aadd723e18). The ONNX_MINIMAL_BUILD
+parts were removed as they are not needed for the Guix package.
+---
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 6d7ca846..69aa622f 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -499,6 +499,7 @@ if (MSVC)
+ endif()
+ else()
+ # On non-Windows, hide all symbols we don't need
++ set(EXTRA_FLAGS "-Wno-unused-parameter")
+ set(ONNX_API_DEFINE
"-DONNX_API=__attribute__\(\(__visibility__\(\"default\"\)\)\)")
+ set_target_properties(onnx_proto PROPERTIES CXX_VISIBILITY_PRESET hidden)
+ set_target_properties(onnx_proto PROPERTIES VISIBILITY_INLINES_HIDDEN 1)
+diff --git a/onnx/common/file_utils.h b/onnx/common/file_utils.h
+index b847798e..a6c31904 100644
+--- a/onnx/common/file_utils.h
++++ b/onnx/common/file_utils.h
+@@ -6,7 +6,6 @@
+
+ #pragma once
+
+-#include <filesystem>
+ #include <fstream>
+ #include <string>
+
+@@ -17,8 +16,7 @@ namespace ONNX_NAMESPACE {
+
+ template <typename T>
+ void LoadProtoFromPath(const std::string proto_path, T& proto) {
+- std::filesystem::path proto_u8_path = std::filesystem::u8path(proto_path);
+- std::fstream proto_stream(proto_u8_path, std::ios::in | std::ios::binary);
++ std::fstream proto_stream(proto_path, std::ios::in | std::ios::binary);
+ if (!proto_stream.good()) {
+ fail_check("Unable to open proto file: ", proto_path, ". Please check if
it is a valid proto. ");
+ }
+diff --git a/onnx/onnx_pb.h b/onnx/onnx_pb.h
+index 0aab3e26..398ac2d6 100644
+--- a/onnx/onnx_pb.h
++++ b/onnx/onnx_pb.h
+@@ -47,10 +47,28 @@
+ #define ONNX_API ONNX_IMPORT
+ #endif
+
++#if defined(__GNUC__)
++#pragma GCC diagnostic push
++
++// In file included from onnx/onnx-ml.pb.h:30:
++// In file included from google/protobuf/extension_set.h:53:
++// google/protobuf/parse_context.h:328:47: error: implicit conversion loses
integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
++#if defined(__has_warning)
++#if __has_warning("-Wshorten-64-to-32")
++#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
++#endif
++#endif // defined(__has_warning)
++
++#endif // defined(__GNUC__)
++
+ #ifdef ONNX_ML
+ #include "onnx/onnx-ml.pb.h"
+ #else
+ #include "onnx/onnx.pb.h"
+ #endif
+
++#if defined(__GNUC__)
++#pragma GCC diagnostic pop
++#endif
++
+ #endif // ! ONNX_ONNX_PB_H