From 7837eb1f0260044d6ebbea2f8a1034b8b926be48 Mon Sep 17 00:00:00 2001 From: CoprDistGit Date: Fri, 29 Aug 2025 06:36:58 +0000 Subject: automatic import of onnx --- .gitignore | 1 + ...shared-libraries-and-fix-install-location.patch | 80 +++++++++++++ ...oject_build-use-binaries-from-cmake_build.patch | 33 ++++++ 0002-Add-fixes-for-use-with-onnxruntime.patch | 69 +++++++++++ onnx.spec | 130 +++++++++++++++++++++ sources | 1 + 6 files changed, 314 insertions(+) create mode 100644 0000-Build-shared-libraries-and-fix-install-location.patch create mode 100644 0001-Let-pyproject_build-use-binaries-from-cmake_build.patch create mode 100644 0002-Add-fixes-for-use-with-onnxruntime.patch create mode 100644 onnx.spec create mode 100644 sources diff --git a/.gitignore b/.gitignore index e69de29..53f7270 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/onnx-1.18.0.tar.gz diff --git a/0000-Build-shared-libraries-and-fix-install-location.patch b/0000-Build-shared-libraries-and-fix-install-location.patch new file mode 100644 index 0000000..5ebf4d3 --- /dev/null +++ b/0000-Build-shared-libraries-and-fix-install-location.patch @@ -0,0 +1,80 @@ +From 8a2a2327e89fb62bb74ced121cbdf8c3a59ad04f Mon Sep 17 00:00:00 2001 +From: Alejandro Alvarez Ayllon +Date: Sat, 24 Feb 2024 14:48:45 +0100 +Subject: [PATCH 0/6] Build shared libraries and fix install location + +--- + CMakeLists.txt | 22 ++++++++++++++++++++-- + 1 file changed, 20 insertions(+), 2 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 4dd56b6e..7f79cc9a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -470,7 +470,7 @@ + list(REMOVE_ITEM __tmp_srcs ${onnx_gtests_src}) + list(APPEND ONNX_SRCS ${__tmp_srcs}) + +-add_library(onnx_proto ${ONNX_PROTO_SRCS} ${ONNX_PROTO_HDRS}) ++add_library(onnx_proto SHARED ${ONNX_PROTO_SRCS} ${ONNX_PROTO_HDRS}) + add_dependencies(onnx_proto gen_onnx_operators_proto gen_onnx_data_proto) + target_include_directories(onnx_proto PUBLIC + $ +@@ -495,6 +495,8 @@ + 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) ++ set_target_properties(onnx_proto PROPERTIES VERSION ${ONNX_VERSION} ++ SOVERSION ${ONNX_VERSION}) + endif() + target_compile_definitions(onnx_proto PRIVATE ${ONNX_API_DEFINE}) + target_compile_features(onnx_proto PUBLIC cxx_std_${CMAKE_CXX_STANDARD}) +@@ -519,10 +521,12 @@ + # So, create a object library + add_library(onnx OBJECT ${ONNX_SRCS}) + else() +- add_library(onnx ${ONNX_SRCS}) ++ add_library(onnx SHARED ${ONNX_SRCS}) ++ set_target_properties(onnx PROPERTIES VERSION ${ONNX_VERSION} ++ SOVERSION ${ONNX_VERSION}) + endif() +-set_target_properties(onnx PROPERTIES CXX_VISIBILITY_PRESET hidden) +-set_target_properties(onnx PROPERTIES VISIBILITY_INLINES_HIDDEN ON) ++set_target_properties(onnx PROPERTIES CXX_VISIBILITY_PRESET default) ++set_target_properties(onnx PROPERTIES VISIBILITY_INLINES_HIDDEN OFF) + + target_include_directories(onnx PUBLIC + $ +@@ -669,6 +673,17 @@ + FILES_MATCHING + PATTERN "*.h") + ++install(DIRECTORY ${ONNX_ROOT}/onnx ++ DESTINATION "${PY_SITEARCH}" ++ FILES_MATCHING ++ PATTERN "*.py" ++ PATTERN "test/*" EXCLUDE ) ++install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/onnx ++ DESTINATION "${PY_SITEARCH}" ++ FILES_MATCHING ++ PATTERN "*.py" ++ PATTERN "test/*" EXCLUDE ) ++ + configure_file( + ${PROJECT_SOURCE_DIR}/cmake/ONNXConfigVersion.cmake.in + ${PROJECT_BINARY_DIR}/ONNXConfigVersion.cmake +@@ -727,7 +742,9 @@ + install(TARGETS + onnx onnx_proto + EXPORT ONNXTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) +- ++install(TARGETS ++ onnx_cpp2py_export ++ DESTINATION "${PY_SITEARCH}/onnx") + if(ONNX_BUILD_TESTS) + include(${ONNX_ROOT}/cmake/unittest.cmake) + endif() +-- +2.43.0 + + diff --git a/0001-Let-pyproject_build-use-binaries-from-cmake_build.patch b/0001-Let-pyproject_build-use-binaries-from-cmake_build.patch new file mode 100644 index 0000000..31eacaf --- /dev/null +++ b/0001-Let-pyproject_build-use-binaries-from-cmake_build.patch @@ -0,0 +1,33 @@ +From 75e1082f2d17c2c2ccb3c38b429fa24a4b45bbea Mon Sep 17 00:00:00 2001 +From: Alejandro Alvarez Ayllon +Date: Sat, 24 Feb 2024 14:53:10 +0100 +Subject: [PATCH 3/4] Let pyproject_wheel use binaries from cmake_build + +--- + setup.py | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/setup.py b/setup.py +index 7d2cb9e5..af9049a1 100644 +--- a/setup.py ++++ b/setup.py +@@ -27,7 +27,7 @@ import setuptools.command.build_py + import setuptools.command.develop + + TOP_DIR = os.path.realpath(os.path.dirname(__file__)) +-CMAKE_BUILD_DIR = os.path.join(TOP_DIR, ".setuptools-cmake-build") ++CMAKE_BUILD_DIR = os.path.join(TOP_DIR, f"{platform.machine()}-openEuler-linux-gnu") + + WINDOWS = os.name == "nt" + +@@ -161,6 +161,7 @@ class CmakeBuild(setuptools.Command): + self.jobs = multiprocessing.cpu_count() + + def run(self): ++ return + assert CMAKE, "Could not find cmake in PATH" + + os.makedirs(CMAKE_BUILD_DIR, exist_ok=True) +-- +2.46.2 + diff --git a/0002-Add-fixes-for-use-with-onnxruntime.patch b/0002-Add-fixes-for-use-with-onnxruntime.patch new file mode 100644 index 0000000..c9306ca --- /dev/null +++ b/0002-Add-fixes-for-use-with-onnxruntime.patch @@ -0,0 +1,69 @@ +From 9809f77792517d0ace2874a84a181e8fe3766d8d Mon Sep 17 00:00:00 2001 +From: Alejandro Alvarez Ayllon +Date: Sat, 24 Feb 2024 14:53:33 +0100 +Subject: [PATCH 4/4] Add fixes for use with onnxruntime + +--- + onnx/defs/schema.cc | 14 ++++++++++++++ + onnx/onnxruntime_fix.h | 14 ++++++++++++++ + 2 files changed, 28 insertions(+) + create mode 100644 onnx/onnxruntime_fix.h + +diff --git a/onnx/defs/schema.cc b/onnx/defs/schema.cc +index 74bd0a63..573d0901 100644 +--- a/onnx/defs/schema.cc ++++ b/onnx/defs/schema.cc +@@ -21,8 +21,19 @@ + + #include "onnx/common/assertions.h" + #include "onnx/defs/parser.h" ++#include "onnx/onnxruntime_fix.h" + + namespace ONNX_NAMESPACE { ++ ++bool ONNXRuntimeFix::_static_registration_disabled = false; ++bool ONNXRuntimeFix::isStaticRegistrationDisabled() { ++ return _static_registration_disabled; ++} ++ ++void ONNXRuntimeFix::disableStaticRegistration() { ++ _static_registration_disabled = true; ++} ++ + // -1 means ONNX schema hasn't been loaded yet + // 0 means all versions of ONNX schema have been loaded + // Other positive integer means the ONNX schemas for the specified version have been loaded +@@ -1091,6 +1102,9 @@ OpName_Domain_Version_Schema_Map& OpSchemaRegistry::map() { + class SchemasRegisterer { + public: + SchemasRegisterer() { ++ // Check if static registration is actually disabled ++ if(ONNXRuntimeFix::isStaticRegistrationDisabled()) return; ++ + // In debug builds, the number of schema registered in this constructor + // is compared against the number of calls to schema registration macros. + #ifndef NDEBUG +diff --git a/onnx/onnxruntime_fix.h b/onnx/onnxruntime_fix.h +new file mode 100644 +index 00000000..2495b931 +--- /dev/null ++++ b/onnx/onnxruntime_fix.h +@@ -0,0 +1,14 @@ ++#pragma once ++ ++namespace ONNX_NAMESPACE { ++ ++class ONNXRuntimeFix { ++public: ++ static bool isStaticRegistrationDisabled(); ++ static void disableStaticRegistration(); ++ ++private: ++ static bool _static_registration_disabled; ++}; ++ ++} // namespace ONNX_NAMESPACE +-- +2.46.2 + + diff --git a/onnx.spec b/onnx.spec new file mode 100644 index 0000000..ef2816a --- /dev/null +++ b/onnx.spec @@ -0,0 +1,130 @@ +Name: onnx +Version: 1.18.0 +Release: 1%{?dist} +Summary: Open standard for machine learning interoperability +License: Apache-2.0 + +URL: https://github.com/onnx/onnx +Source0: https://github.com/onnx/onnx/archive/v%{version}/%{name}-%{version}.tar.gz + +# Build shared libraries and fix install location +Patch0: 0000-Build-shared-libraries-and-fix-install-location.patch +# Let pyproject_build use binaries from cmake_build +Patch1: 0001-Let-pyproject_build-use-binaries-from-cmake_build.patch +# Add fixes for use with onnxruntime +Patch2: 0002-Add-fixes-for-use-with-onnxruntime.patch + +BuildRequires: cmake >= 3.24 +BuildRequires: make +BuildRequires: findutils +BuildRequires: gcc +BuildRequires: gcc-c++ +BuildRequires: zlib-devel +BuildRequires: python3-devel +BuildRequires: python3-pip +BuildRequires: python3-wheel +BuildRequires: python3-pybind11 >= 2.12.0 +BuildRequires: protobuf-devel >= 25.1 +BuildRequires: protobuf-compiler >= 25.1 +BuildRequires: python3-build +BuildRequires: python3-parameterized +BuildRequires: pytest +BuildRequires: python3-pytest-cov +BuildRequires: python3-pytest-xdist +BuildRequires: python3-setuptools +BuildRequires: python3-pillow +BuildRequires: python3-numpy +BuildRequires: python3-protobuf + +%global _description %{expand: +%{name} provides an open source format for AI models, both deep learning and +traditional ML. It defines an extensible computation graph model, as well as +definitions of built-in operators and standard data types.} + +%description %_description + +%package libs +Summary: Libraries for %{name} + +%description libs %_description + +%package devel +Summary: Development files for %{name} +Requires: %{name}-libs = %{version}-%{release} + +%description devel %_description + +%package -n python3-onnx +Summary: %{summary} +Requires: %{name}-libs = %{version}-%{release} + +%description -n python3-onnx %_description + +%prep +%autosetup -p1 -n %{name}-%{version} + +# Drop nbval options from pytest. Plugin is not available in openEuler. +sed -r \ + -e 's/--nbval //' \ + -e 's/--nbval-current-env //' \ + -i pyproject.toml + +%build +%cmake \ + -DONNX_USE_LITE_PROTO=OFF \ + -DONNX_USE_PROTOBUF_SHARED_LIBS=ON \ + -DONNX_BUILD_PYTHON=ON \ + -DONNX_ML=1 \ + -DPython3_EXECUTABLE=%{__python3} \ + -DPY_SITEARCH=%{python3_sitearch} \ + -DCMAKE_SKIP_RPATH:BOOL=ON + + + +# Generate protobuf header and source files +%cmake_build -- gen_onnx_proto +# Build +%cmake_build +# Build python libs +%pyproject_build + +%install +%cmake_install +# Need to remove empty directories +# find "%{buildroot}%{_includedir}" -type d -empty -delete +# find "%{buildroot}%{python3_sitearch}" -type d -empty -delete +# Install *.proto files +install -p "./onnx/"*.proto -t "%{buildroot}/%{_includedir}/onnx/" + +%pyproject_install + +%check +export LD_LIBRARY_PATH=%{buildroot}%{_libdir} +export PYTHONPATH=%{buildroot}%{python3_sitearch} +%pytest \ + --ignore=onnx/test/helper_test.py \ + --ignore=onnx/test/numpy_helper_test.py \ + --ignore=onnx/test/test_backend_reference.py \ + --ignore=onnx/test/reference_evaluator_test.py + +%files libs +%license LICENSE +%doc README.md +%{_libdir}/libonnx.so.%{version} +%{_libdir}/libonnx_proto.so.%{version} + +%files devel +%{_libdir}/libonnx.so +%{_libdir}/libonnx_proto.so +%{_libdir}/cmake/ONNX +%{_includedir}/%{name}/ + +%files -n python3-onnx +%{python3_sitearch}/onnx* +%{_bindir}/backend-test-tools +%{_bindir}/check-model +%{_bindir}/check-node + +%changelog +* Fri Jul 4 2025 zhihang - 1.18.0-1 +- Init package diff --git a/sources b/sources new file mode 100644 index 0000000..9065a18 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +3bfdd4b6e905f07b72af981f9a7811d9 onnx-1.18.0.tar.gz -- cgit v1.2.3