rpm: Introduce using_rustup definition

`using_rustup` is needed as distros (such as Fedora or RHEL) don't
provide the users a way to install`rustup` without conflicting with the
distro provided `rust` package.

In order to minimize the troubles for those who want to build
cloud-hypervisor using the distros packages, let's allow the users to
change that variable and then simply rely on their system packages.

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
Fabiano Fidêncio 2021-11-08 17:41:15 +01:00 committed by Rob Bradford
parent 7618cd2c2d
commit a628854d9c

View File

@ -4,6 +4,8 @@
# * You have both x86_64-unknown-linux-gnu and x86_64-unknown-linux-musl # * You have both x86_64-unknown-linux-gnu and x86_64-unknown-linux-musl
# targets installed. # targets installed.
%define using_rustup 1
Name: cloud-hypervisor Name: cloud-hypervisor
Summary: Cloud Hypervisor is an open source Virtual Machine Monitor (VMM) that runs on top of KVM. Summary: Cloud Hypervisor is an open source Virtual Machine Monitor (VMM) that runs on top of KVM.
Version: 19.0 Version: 19.0
@ -18,7 +20,7 @@ BuildRequires: glibc-devel
BuildRequires: binutils BuildRequires: binutils
BuildRequires: git BuildRequires: git
%if 0%{?fedora} || 0%{?rhel} %if ! 0%{?using_rustup}
BuildRequires: rust BuildRequires: rust
BuildRequires: cargo BuildRequires: cargo
%endif %endif
@ -58,11 +60,17 @@ if [[ $? -ne 0 ]]; then
echo "Cargo not found, please install cargo. exiting" echo "Cargo not found, please install cargo. exiting"
exit 0 exit 0
fi fi
%if 0%{?using_rustup}
which rustup which rustup
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "Rustup not found please install rustup #curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" echo "Rustup not found please install rustup #curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
fi fi
%endif
echo ${cargo_version} echo ${cargo_version}
%if 0%{?using_rustup}
rustup target list --installed | grep x86_64-unknown-linux-gnu rustup target list --installed | grep x86_64-unknown-linux-gnu
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "Target x86_64-unknown-linux-gnu not found, please install(#rustup target add x86_64-unknown-linux-gnu). exiting" echo "Target x86_64-unknown-linux-gnu not found, please install(#rustup target add x86_64-unknown-linux-gnu). exiting"
@ -71,6 +79,7 @@ rustup target list --installed | grep x86_64-unknown-linux-musl
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "Target x86_64-unknown-linux-musl not found, please install(#rustup target add x86_64-unknown-linux-musl). exiting" echo "Target x86_64-unknown-linux-musl not found, please install(#rustup target add x86_64-unknown-linux-musl). exiting"
fi fi
%endif
cargo build --release --target=x86_64-unknown-linux-gnu --all cargo build --release --target=x86_64-unknown-linux-gnu --all
cargo build --release --target=x86_64-unknown-linux-musl --all cargo build --release --target=x86_64-unknown-linux-musl --all