File python-sentencepiece.spec of Package python-sentencepiece
#
# spec file for package python-sentencepiece
#
# Copyright (c) 2024 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 srcname sentencepiece
%{?sle15_python_module_pythons}
Name: python-sentencepiece
Version: 0.2.0
Release: 0
Summary: SentencePiece python wrapper
License: Apache-2.0
URL: https://github.com/google/sentencepiece
Source: %{url}/archive/v%{version}.tar.gz#/%{srcname}-%{version}.tar.gz
Patch0: sentencepiece-fix-build.patch
BuildRequires: python-rpm-macros
BuildRequires: %{python_module pip}
BuildRequires: %{python_module setuptools}
BuildRequires: %{python_module wheel}
BuildRequires: %{python_module devel}
BuildRequires: cmake >= 3.5
BuildRequires: ninja
%if 0%{?sle_version} == 150600
BuildRequires: gcc12-c++
BuildRequires: libstdc++6-gcc12
BuildRequires: abseil-cpp-devel-gcc12
BuildRequires: libprotobuf-c-devel-gcc12
BuildRequires: protobuf-devel-gcc12
%else
BuildRequires: gcc-c++ >= 11.4.0
BuildRequires: abseil-cpp-devel
BuildRequires: protobuf-c
BuildRequires: protobuf-devel
%endif
BuildRequires: pkgconfig(libtcmalloc)
BuildRequires: fdupes
%python_subpackages
%description
SentencePiece is an unsupervised text tokenizer and detokenizer mainly for
Neural Network-based text generation systems where the vocabulary size is
predetermined prior to the neural model training.
SentencePiece python wrapper
%package -n libsentencepiece0
Summary: SentencePiece Library
Group: Development/Libraries/C and C++
%description -n libsentencepiece0
SentencePiece is an unsupervised text tokenizer and detokenizer mainly for
Neural Network-based text generation systems where the vocabulary size is
predetermined prior to the neural model training.
This package contains the shared library.
%package -n sentencepiece-devel
Summary: SentencePiece development files
Group: Development/Libraries/C and C++
Requires: libsentencepiece0 = %{version}-%{release}
Provides: pkgconfig(libsentencepiece0) = %{version}
%description -n sentencepiece-devel
SentencePiece development files.
%package -n sentencepiece-devel-static
Summary: SentencePiece development files (staic libraries)
Group: Development/Libraries/C and C++
Requires: sentencepiece-devel = %{version}-%{release}
%description -n sentencepiece-devel-static
SentencePiece development files (staic libraries).
%prep
%autosetup -p1 -n %{srcname}-%{version}
%build
%if 0%{?sle_version} == 150600
export CXX=g++-12
export CC=gcc-12
# System libs were compiled using previous c++ standard, this breaks c++17 build
%define cmake_opts -DSPM_PROTOBUF_PROVIDER="internal" -DSPM_ABSL_PROVIDER="internal"
%else
%define cmake_opts -DSPM_PROTOBUF_PROVIDER="package" -DSPM_ABSL_PROVIDER="package"
%endif
export CFLAGS="%{optflags} -ffat-lto-objects"
export CXXFLAGS="%{optflags} -ffat-lto-objects"
# build the sentencepiece library
%define __builder ninja
%define __sourcedir sentencepiece
%define __builddir build-libs
%cmake %cmake_opts
%cmake_build
mkdir root
env DESTDIR=root %cmake_build install
cd -
%pyproject_wheel
%install
%cmake_install
%pyproject_install
%python_expand %fdupes %{buildroot}%{$python_sitearch}
%check
export LD_LIBRARY_PATH=$PWD/build-libs/root/usr/%{_lib}/
%pyunittest_arch discover -v -p '*test.py'
%end
%ldconfig_scriptlets -n libsentencepiece0
%files %{python_files}
%doc README.md
%{python_sitearch}/sentencepiece
%{python_sitearch}/sentencepiece-%{version}.dist-info
%files -n libsentencepiece0
%{_libdir}/libsentencepiece.so.0
%{_libdir}/libsentencepiece.so.0.0.0
%{_libdir}/libsentencepiece_train.so.0
%{_libdir}/libsentencepiece_train.so.0.0.0
%files -n sentencepiece-devel
%{_bindir}/spm_*
%{_includedir}/sentencepiece*.h
%{_libdir}/libsentencepiece.so
%{_libdir}/libsentencepiece_train.so
%{_libdir}/pkgconfig/sentencepiece.pc
%files -n sentencepiece-devel-static
%{_libdir}/libsentencepiece.a
%{_libdir}/libsentencepiece_train.a
%changelog