File cargo.spec of Package cargo

#
# spec file for package cargo
#
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2016 Michal Vyskocil, michal.vyskocil@opensuse.org
# Copyright (c) 2016 Kristoffer Gronlund, kgronlund@suse.com
# Copyright (c) 2017 Luke Jones, luke.nukem.jones@gmail.com
#
# 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 http://bugs.opensuse.org/
#


%global bootstrap_version 0.26.0
%global bootstrap_rustc_version 1.25.0
%global current_rustc_version 1.25.0
%global rust_arch %{_arch}
%global abi gnu
%ifarch armv7hl
%global rust_arch armv7
%global abi gnueabihf
%endif
%ifarch armv6hl
%global rust_arch arm
%global abi gnueabihf
%endif
%ifarch ppc64
%global rust_arch powerpc64
%endif
%ifarch ppc64le
%global rust_arch powerpc64le
%endif
# Must restrict the x86 build to i686 since i586 is currently unsupported
%ifarch %ix86
%global rust_arch i686
%endif
%global rust_triple %{rust_arch}-unknown-linux-%{abi}
%bcond_with cargo_bootstrap
Name:           cargo
Version:        0.26.0
Release:        0
Summary:        The Rust package manager
License:        MIT OR Apache-2.0
Group:          Development/Languages/Other
Url:            https://github.com/rust-lang/cargo
Source0:        cargo-%{version}.tar.gz
Source1:        vendor.tar.xz
Patch0:         update-config-guess.patch
BuildRequires:  cmake
BuildRequires:  curl
BuildRequires:  git
BuildRequires:  pkgconfig
BuildRequires:  pkgconfig(libcrypto)
BuildRequires:  pkgconfig(libcurl)
BuildRequires:  pkgconfig(libgit2) >= 0.23
BuildRequires:  pkgconfig(libssh)
BuildRequires:  pkgconfig(libssh_threads)
BuildRequires:  pkgconfig(libssl)
BuildRequires:  pkgconfig(openssl)
BuildRequires:  pkgconfig(zlib)
Requires:       rust
Conflicts:      cargo
Conflicts:      cargo-bootstrap
ExclusiveArch:  x86_64 %{arm} aarch64 ppc64 ppc64le s390x
%ifarch %ix86
BuildArch:      i686
ExclusiveArch:  i586 i686
%endif
# There are no successful builds for less than TW or Leap 42.2, so bootstrap
# until such time that there is.
%if %{with cargo_bootstrap}
BuildRequires:  cargo-bootstrap = %{bootstrap_version}
BuildRequires:  rust-std-bootstrap = %{bootstrap_rustc_version}
BuildRequires:  rustc-bootstrap = %{bootstrap_rustc_version}
%else
BuildRequires:  cargo <= %{version}
BuildRequires:  rust <= %{current_rustc_version}
BuildRequires:  rust-std <= %{current_rustc_version}
%endif

%description
Cargo downloads your Rust project’s dependencies and compiles your project.

%prep
%setup -q -n cargo-%{version}
%setup -q -D -T -a 1 -n cargo-%{version}
#patch0 -p1
mkdir cargo-home
cat >cargo-home/config <<EOF
[source.crates-io]
registry = 'https://github.com/rust-lang/crates.io-index'
replace-with = 'vendored-sources'
[source.vendored-sources]
directory = './vendor'
EOF

%build
# This should eventually migrate to distro policy
# Enable optimization, debuginfo, and link hardening.
export RUSTFLAGS="-Copt-level=3 -Cdebuginfo=2 -Clink-arg=-Wl,-z,relro,-z,now"

export LIBGIT2_SYS_USE_PKG_CONFIG=1
export CARGO_HOME=`pwd`/cargo-home/
cargo build --target=%{rust_triple} --release %{?_smp_mflags}

%install
mkdir build
export CARGO_HOME=`pwd`/cargo-home/

cargo install --root %{buildroot}%{_prefix}
rm %{buildroot}%{_prefix}/.crates.toml

mkdir -p %{buildroot}%{_mandir}/man1
install -Dm0644 src%{_sysconfdir}/man/cargo*.1 %{buildroot}%{_mandir}/man1/
install -Dm0644 src%{_sysconfdir}/cargo.bashcomp.sh %{buildroot}%{_sysconfdir}/bash_completion.d/cargo.sh
install -Dm0644 src%{_sysconfdir}/_cargo %{buildroot}%{_sysconfdir}/zsh/site-functions/_cargo

%files
%defattr(-,root,root)
%doc LICENSE-APACHE LICENSE-MIT README.md
%{_bindir}/cargo
%{_mandir}/man1/*
%config %{_sysconfdir}/bash_completion.d/cargo.sh
%dir %{_sysconfdir}/zsh
%dir %{_sysconfdir}/zsh/site-functions
%config %{_sysconfdir}/zsh/site-functions/_cargo

%changelog
openSUSE Build Service is sponsored by