File google-or-tools.spec of Package google-or-tools

#
# spec file for package google-or-tools
#
# Copyright (c) 2025 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/
#


%define sonum 9
%bcond_without tests

Name:           google-or-tools
Version:        9.11
Release:        0
License:        Apache-2.0
Summary:        Suite for solving combinatorial optimization problems
URL:            https://developers.google.com/optimization/
Group:          Development/Languages/C++
Source:         https://github.com/google/or-tools/archive/refs/tags/v%{version}.tar.gz#/google-or-tools-%{version}.tar.gz
# PATCH-FIX-UPSTREAM
Patch1:         0001-Do-not-try-to-copy-pybind11_abseil-status-extension-.patch
# PATCH-FIX-UPSTREAM
Patch2:         0001-Revert-python-Fix-python-install-on-windows-breaks-L.patch
Patch3:         0001-Fix-up-broken-CMake-rules-for-bundled-pybind-stuff.patch
BuildRequires:  abseil-cpp-devel >= 20240116.1
BuildRequires:  cmake >= 3.18
BuildRequires:  fdupes
BuildRequires:  gcc-c++ >= 7
BuildRequires:  gtest >= 1.14
BuildRequires:  pybind11-abseil-devel
BuildRequires:  pybind11_protobuf-devel
BuildRequires:  python3-absl-py >= 2.0
BuildRequires:  python3-devel
BuildRequires:  python3-immutabledict
BuildRequires:  python3-matplotlib
BuildRequires:  python3-mypy
BuildRequires:  python3-mypy-protobuf
BuildRequires:  python3-numpy >= 1.13.1
BuildRequires:  python3-pandas
BuildRequires:  python3-pybind11-devel >= 2.11.1
BuildRequires:  python3-pybind11_abseil
BuildRequires:  python3-pytest
BuildRequires:  python3-scipy >= 1.10.0
BuildRequires:  python3-setuptools
BuildRequires:  python3-svgwrite
BuildRequires:  python3-virtualenv
BuildRequires:  python3-wheel
BuildRequires:  swig >= 4.1.1
BuildRequires:  pkgconfig(eigen3)
BuildRequires:  pkgconfig(protobuf) >= 3.25
BuildRequires:  pkgconfig(re2) >= 11.0
BuildRequires:  pkgconfig(zlib)

%description
OR-Tools is an open source software suite for optimization, tuned for
tackling the world's toughest problems in vehicle routing, flows,
integer and linear programming, and constraint programming.

%package -n python3-ortools
Summary:        Suite for solving combinatorial optimization problems
Group:          Development/Languages/Python
Requires:       python3-absl-py
Requires:       python3-numpy

%description -n python3-ortools
Python3 bindings for the OR-Tools suite, for solving combinatorial
optimization problems.

%package minizinc
Summary:        OR-Tools minizinc solver
Group:          Productivity/Scientific/Math
Requires:       minizinc

%description minizinc
Minizinc solver using the OR-Tools suite.

%package -n libortools%{sonum}
Summary:        Suite for solving combinatorial optimization problems
Group:          System/Libraries

%description -n libortools%{sonum}
OR-Tools is an open source software suite for optimization.

%package -n libortools_flatzinc%{sonum}
Summary:        Suite for solving combinatorial optimization problems
Group:          System/Libraries

%description -n libortools_flatzinc%{sonum}
OR-Tools is an open source software suite for optimization.

%package devel
Summary:        Suite for solving combinatorial optimization problems
Group:          Development/Languages/C++
Requires:       libortools%{sonum} = %{version}
Requires:       libortools_flatzinc%{sonum} = %{version}

%description devel
Development files (C/C++) for the OR-Tools suite.

%prep
%autosetup -p1 -n or-tools-%{version}
# Allow doc install
sed -i -e '/CMAKE_DEPENDENT_OPTION(INSTALL_DOC/ s/BUILD_CXX AND BUILD_DOC/BUILD_CXX/' CMakeLists.txt
find . -iname \*CMakeLists.txt -exec sed -i -e 's/pybind11_native_proto_caster/pybind11_protobuf::pybind11_native_proto_caster/' '{}' \;
sed -i -e 's/TARGET pybind11_native_proto_caster/TARGET pybind11_protobuf::pybind11_native_proto_caster/' cmake/check_deps.cmake
# Relax versions, current protobuf works fine unless you link to it multiple times using a mix of static and shared libraries
sed -i -e "/protobuf/ { s/.*,/'protobuf >= 5.26',/ }" ortools/python/setup.py.in

%build
export PIP_NO_INDEX=1
%global optflags %{optflags} -Wno-error=return-type
%cmake \
  -DCMAKE_INSTALL_DOCDIR=%{_docdir}/%{name}/ \
  -DINSTALL_DOC:BOOL=ON \
  -DBUILD_DEPS:BOOL=OFF \
  -DBUILD_pybind11:BOOL=OFF \
  -DBUILD_PYTHON:BOOL=ON \
  -DVENV_USE_SYSTEM_SITE_PACKAGES:BOOL=ON \
  -DUSE_COINOR:BOOL=OFF \
  -DUSE_HIGHS:BOOL=OFF \
  -DUSE_SCIP:BOOL=OFF \
  %{nil}
%cmake_build

%install
%cmake_install
rm %{buildroot}/%{_docdir}/%{name}/LICENSE
# Remove duplicate library
rm %{buildroot}/%{python3_sitearch}/ortools/.libs/libortools.so.9
rmdir %{buildroot}/%{python3_sitearch}/ortools/.libs

%post -n libortools%{sonum} -p /sbin/ldconfig
%postun -n libortools%{sonum} -p /sbin/ldconfig
%post -n libortools_flatzinc%{sonum} -p /sbin/ldconfig
%postun -n libortools_flatzinc%{sonum} -p /sbin/ldconfig

%check
%if %{with tests}
# Some tests using e.g. SCIP are not skipped, exclude
# https://github.com/google/or-tools/issues/3261
%define known_fail 'python_linear_solver_model_builder_test'
%define known_timeout 'python_contrib_school_scheduling_sat'
%if %{__isa_bits} == 32
%ctest --exclude-regex %{known_fail} || true
%else
echo "Run tests known to fail"
%ctest --tests-regex %{known_fail} || true
echo "Run good tests"
%ctest --exclude-regex %{known_fail} --exclude-regex %{known_timeout}
%endif
%endif

%files
%doc CONTRIBUTING.md README.md
%license LICENSE
%{_bindir}/*
%{_docdir}/%{name}/{sat,constraint_solver}
%exclude %{_bindir}/fzn-*

%files -n python3-ortools
%{python3_sitearch}/ortools
%{python3_sitearch}/ortools-%{version}*info

%files minizinc
%{_bindir}/fzn-*
%{_datadir}/minizinc

%files -n libortools%{sonum}
%{_libdir}/libor*.so.%{sonum}*
%exclude %{_libdir}/libortools_flatzinc*.so.%{sonum}*

%files -n libortools_flatzinc%{sonum}
%{_libdir}/libortools_flatzinc*.so.%{sonum}*

%files devel
%{_libdir}/lib*.so
%{_libdir}/cmake/ortools
%{_includedir}/ortools
%{_includedir}/ortools_export.h

%changelog
openSUSE Build Service is sponsored by