#needsrootforbuild
%global __cargo_skip_build 0
%global _debugsource_packages 1
%global _debuginfo_subpackages 1
%define _unpackaged_files_terminate_build 0
%define debug_package %{nil}

Name:           isula-rust-extensions
Version:        0.0.1
Release:        1
URL:            https://gitee.com/openeuler/isula-rust-extensions
Source:         %{name}-%{version}.tar.gz
Summary:        isula-rust-extensions is a rust-extension library for iSulad.
Group:          Application/System
License:        Mulan PSL v2

ExclusiveArch:  x86_64 aarch64

Patch0001:      0001-add-some-missing-c-rust-struct-transfer.patch

BuildRequires:  rust
BuildRequires:  cargo
BuildRequires:  rust-packaging
BuildRequires:  gcc

%description
Based on Rust programming language, rust-extension library for iSulad.

%package devel
Summary: Rust extensions for iSulad
Group:   Libraries
ExclusiveArch:  x86_64 aarch64
Requires: %{name} = %{version}-%{release}

%description devel
the %{name}-libs package contains rust-extension library for iSulad

%prep
%autosetup -p1
pushd nri
%cargo_prep
%cargo_generate_buildrequires
popd

%build
cd nri
sed -i '/\[source.crates-io\]/{n;d}' ./.cargo/config
sed -i '/\[source.local-registry\]/{n;d}' ./.cargo/config
sed -i '/\[source.local-registry\]/a directory = "vendor"' ./.cargo/config
%ifarch aarch64
sed -i 's/rustflags = \[/rustflags = \["-Clink-arg=-lgcc", "-Clink-arg=-lfdt", /g' ./.cargo/config
%endif
%cargo_build -a

%install
mkdir -p ${RPM_BUILD_ROOT}/{%{_libdir},%{_includedir}}
install -m 0644 nri/nri_plugin.h ${RPM_BUILD_ROOT}/%{_includedir}/nri_plugin.h
strip nri/target/release/libisula_nri.so
install -m 0755 nri/target/release/libisula_nri.so ${RPM_BUILD_ROOT}/%{_libdir}/libisula_nri.so

%files
%defattr(-,root, root,-)
%{_libdir}/*

%files devel
%defattr(-,root, root,-)
%{_includedir}/nri_plugin.h

%changelog
* Fri Aug 09 2024 jikai <jikai11@huawei.com> - 0.0.1-1
- Initial RPM release
