File python-onnxruntime.spec of Package python-onnxruntime
#
# spec file for package python-onnxruntime
#
# Copyright (c) 2020 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define skip_python2 1
%define skip_python36 1
Name: python-onnxruntime
Version: 1.15.1
Release: 0
Summary: ONNX Runtime Python bindings
License: MIT AND Apache-2.0 AND MPL-2.0
URL: https://github.com/microsoft/onnxruntime/
Source0: onnxruntime-%{version}.tar.xz
Source1: https://github.com/dcleblanc/SafeInt/blob/925235c06de490865f871218fa2bd8ac38241a95/SafeInt.hpp
# Add an option to not install the tests
Patch0: dont-install-tests.patch
# Use the system flatbuffers
Patch1: system-flatbuffers.patch
# Use the system protobuf
Patch2: system-protobuf.patch
# Use the system onnx
Patch3: system-onnx.patch
# Fedora targets power8 or higher
Patch4: disable-power10.patch
# Do not use nsync
Patch5: no-nsync.patch
# Do not link against WIL
Patch6: remove-wil.patch
# Use the system safeint
Patch7: system-safeint.patch
# Versioned libonnxruntime_providers_shared.so
Patch8: versioned-onnxruntime_providers_shared.patch
# Disable gcc -Werrors with false positives
Patch9: gcc-false-positive.patch
# Test data not available
Patch10: disable-pytorch-tests.patch
# Use the system date and boost
Patch11: system-date-and-mp11.patch
# Remove broken forward declarations and include flatbuffers instead
Patch12: fix_forward_decl_flatbuffers.patch
# Use the system cpuinfo
Patch13: system-cpuinfo.patch
# Trigger onnx fix for onnxruntime_providers_shared
Patch14: onnx_onnxruntime_fix.patch
# Use the system python version
Patch15: system-python.patch
BuildRequires: %{python_module devel}
BuildRequires: %{python_module numpy-devel >= 1.15.0}
BuildRequires: %{python_module numpy}
BuildRequires: %{python_module onnx}
BuildRequires: %{python_module packaging}
BuildRequires: %{python_module pip}
BuildRequires: %{python_module pybind11-devel}
BuildRequires: %{python_module pytest}
BuildRequires: %{python_module setuptools}
BuildRequires: %{python_module sympy}
BuildRequires: %{python_module wheel}
BuildRequires: abseil-cpp-devel
BuildRequires: boost-devel
BuildRequires: flatbuffers-devel
BuildRequires: hhdate-devel
BuildRequires: cmake
BuildRequires: eigen3-devel
BuildRequires: fdupes
BuildRequires: gcc-c++
BuildRequires: gmock
BuildRequires: gsl-devel
BuildRequires: gtest
BuildRequires: libnsync-devel
BuildRequires: libtool
BuildRequires: ms-gsl-devel
BuildRequires: nlohmann_json-devel
BuildRequires: onnx-devel
BuildRequires: openblas-devel
BuildRequires: pkgconfig
BuildRequires: protobuf21-devel
BuildRequires: python-rpm-macros
BuildRequires: re2-devel
BuildRequires: pkgconfig(libpng)
BuildRequires: pkgconfig(zlib)
Requires: python-numpy >= 1.15.0
Requires: python-onnx >= 1.2.3
%python_subpackages
%description
ONNX Runtime is a performance-focused scoring engine for Open Neural Network
Exchange (ONNX) models. For more information on ONNX Runtime, please see
<https://aka.ms/onnxruntime/> or <https://github.com/microsoft/onnxruntime/>.
%prep
%setup -q -n onnxruntime-%{version}
%autopatch -p1
mkdir -p cmake/external/safeint/
cp %{S:1} cmake/external/safeint/
%build
# The build is done with cmake, but some of its standard flags make the build
# fail. The flags which break compilation are explained below. Also some
# additional flags to onnxruntime so that as much system libraries as possible
# are used.
#
# NOTE: The unit tests have to build in order to enable the python bindings, there
# is no way to avoid the tests during build and getting the python bindings
python3 onnxruntime/core/flatbuffers/schema/compile_schema.py --flatc /usr/bin/flatc
pushd cmake
%global _lto_cflags %{_lto_cflags} -ffat-lto-objects
%cmake \
-Donnxruntime_BUILD_UNIT_TESTS=ON \
-Donnxruntime_BUILD_SHARED_LIB=ON \
-Donnxruntime_INSTALL_UNIT_TESTS=OFF \
-Donnxruntime_BUILD_BENCHMARKS=OFF \
-Donnxruntime_USE_FULL_PROTOBUF=ON \
-Donnxruntime_ENABLE_PYTHON=ON \
-Donnxruntime_PREFER_SYSTEM_LIB=ON \
-Donnxruntime_DISABLE_ABSEIL=ON \
-Donnxruntime_ENABLE_CPUINFO=OFF \
-Donnxruntime_USE_PREINSTALLED_EIGEN=ON \
-Deigen_SOURCE_PATH=/usr/include/eigen3 \
-DCMAKE_SKIP_RPATH:BOOL=OFF \
-DBUILD_SHARED_LIBS:BOOL=OFF \
%{nil}
%cmake_build
popd
# must be called in this subdirectory
pushd cmake/build
%python_exec ../../setup.py build
popd
%install
# must be called in this subdirectory
pushd cmake/build
%python_exec ../../setup.py install -O1 --skip-build --force --root %{buildroot} --prefix %{_prefix}
%if "%{_lib}" == "lib64"
# rename the folder from sitelib to sitearch
%python_expand mkdir -p %{buildroot}%{$python_sitearch}
%python_expand mv %{buildroot}%{$python_sitelib}/* %{buildroot}%{$python_sitearch}
%endif
popd
%python_expand %fdupes %{buildroot}%{$python_sitearch}
%check
pushd cmake
%ctest
popd
%files %{python_files}
%doc README.md
%license LICENSE
%{python_sitearch}/onnxruntime*
%python3_only %{_bindir}/onnxruntime_test
%changelog