#needsrootforbuild
%global __cargo_skip_build 0
%global _debugsource_packages 1
%global _debuginfo_subpackages 1
%define _unpackaged_files_terminate_build 0

Name:           stratovirt
Version:        2.0.0
Release:        1
Summary:        StratoVirt is an opensource VMM(Virtual Machine Manager) which aims to perform next generation virtualization.

License:        Mulan PSL v2
URL:            https://gitee.com/openeuler/StratoVirt
Source0:        %{name}-%{version}.tar.gz

ExclusiveArch:  x86_64 aarch64

%ifarch aarch64
Requires:      dtc
BuildRequires: dtc-devel
%endif

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

%description
Based on Rust programming language, StratoVirt is lightweight, efficient and safe. StratoVirt reduces memory resource consumption and improves VM startup speed while retains isolation capability and security capability of traditional virtualization. StratoVirt works with iSulad and Kata container, and can be integrated in Kubernetes ecosystem perfectly. The current version can be applied to microservices or serverless scenarios. StratoVirt reserves interface and design for importing more features, even standard virtualization.

Summary:        %{summary}

%files       -n stratovirt
%{_bindir}/stratovirt

%prep
%autosetup -p1

%cargo_prep

%cargo_generate_buildrequires

%build

%ifarch aarch64
sed -i '/\[build\]/a target="aarch64-unknown-linux-musl"' ./.cargo/config
%endif

%ifarch x86_64
sed -i '/\[build\]/a target="x86_64-unknown-linux-musl"' ./.cargo/config
%endif

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", /g' ./.cargo/config
%endif

%cargo_build -a

%install
%cargo_install -a
chmod 550 ${RPM_BUILD_ROOT}/usr/bin/stratovirt

%changelog
* Fri Aug 13 2021 Jie Yang <yangjieyj.yang@huawei.com> - 2.0.0-1
- add ACPI support
- add PCIe/PCI support
- add support for UEFI boot
- add virtio pci support
- provide standard type machine on x86_64 and aarch64
- add hot boot feature
- add VFIO support
- add initial support for being managed by libvirt

* Tue Jul 27 2021 XuFei <xufei30@huawei.com> - 0.3.0-5
- add fdt patches for musl compilation

* Wed Jun 16 2021 XuFei <xufei30@huawei.com> - 0.3.0-4
- add gcc dependency package

* Sun May 28 2021 XuFei <xufei30@huawei.com> - 0.3.0-3
- modify docs
- modify testcases
- clear clippy warnings for updating rust 1.51.0

* Sun Apr 25 2021 LiangZhang <zhangliang5@huawei.com> - 0.3.0-2
- add hydropper to package

* Sun Apr 25 2021 LiangZhang <zhangliang5@huawei.com> - 0.3.0-1
- update package to 0.3.0

* Wed Jan 13 2021 LiangZhang <zhangliang5@huawei.com> - 0.1.0-3
- update package to latest source

* Wed Jan 13 2021 XuFei <xufei30@huawei.com> - 0.1.0-2
- modify summary and description for spec

* Thu Jul 16 2020 Xu Yandong <xuyandong2@huawei.com> - 0.1.0-1
- initial package
