4 %bcond_without tests # build without tests
6 %define cargo_version %{version}
7 %define cargo_bootstrap 0.18.0
9 Summary: Rust's package manager and build tool
13 License: ASL 2.0 or MIT
14 Group: Development/Libraries
15 Source0: https://github.com/rust-lang/cargo/archive/%{cargo_version}/%{name}-%{cargo_version}.tar.gz
16 # Source0-md5: e46e9f565df765b63f641c0d933297d7
17 # submodule, bundled for local installation only, not distributed
18 %define rust_installer 4f994850808a572e2cc8d43f968893c8e942e9bf
19 Source1: https://github.com/rust-lang/rust-installer/archive/%{rust_installer}/rust-installer-%{rust_installer}.tar.gz
20 # Source1-md5: a222edd3ab08779f527aafe862207027
21 Source2: https://static.rust-lang.org/dist/cargo-%{cargo_bootstrap}-x86_64-unknown-linux-gnu.tar.gz
22 # Source2-md5: d2cbab6378c1f60b483efa0f076a8f81
23 Source3: https://static.rust-lang.org/dist/cargo-%{cargo_bootstrap}-i686-unknown-linux-gnu.tar.gz
24 # Source3-md5: 1ad24c241a2f5e3c4bf83855766fab35
25 # Use vendored crate dependencies so we can build offline.
26 # Created using https://github.com/alexcrichton/cargo-vendor/ 0.1.7
27 # It's so big because some of the -sys crates include the C library source they
28 # want to link to. With our -devel buildreqs in place, they'll be used instead.
29 # FIXME: These should all eventually be packaged on their own!
30 Source4: %{name}-%{version}-vendor.tar.xz
31 # Source4-md5: c8025d6ba2aa668c0bafc468ec354630
32 Patch0: use-system-libgit2.patch
33 URL: https://crates.io/
34 %{!?with_bootstrap:BuildRequires: %{name} >= 0.13.0}
38 # Indirect dependencies for vendored -sys crates above
39 BuildRequires: curl-devel
40 BuildRequires: libgit2-devel >= 0.24
41 BuildRequires: libssh2-devel
42 BuildRequires: openssl-devel
43 BuildRequires: pkgconfig
44 BuildRequires: zlib-devel
46 ExclusiveArch: %{x8664} %{ix86}
48 %define rust_triple %{_target_cpu}-unknown-linux-gnu
51 %define bootstrap_root cargo-%{cargo_bootstrap}-%{rust_triple}
52 %define local_cargo %{_builddir}/%{name}-%{version}/%{bootstrap_root}/cargo/bin/cargo
54 %define local_cargo %{_bindir}/%{name}
57 # This should eventually migrate to distro policy
58 # Enable optimization, debuginfo, and link hardening.
59 %define rustflags -Copt-level=3 -Cdebuginfo=2 -Clink-arg=-Wl,-z,relro,-z,now
62 Cargo is a tool that allows Rust projects to declare their various
63 dependencies and ensure that you'll always get a repeatable build.
66 %setup -q -n %{name}-%{cargo_version} -a1 -a4
74 test -f '%{local_cargo}'
78 rmdir src/rust-installer
79 mv rust-installer-%{rust_installer} src/rust-installer
81 # use our offline registry and custom rustc flags
82 export CARGO_HOME="`pwd`/.cargo"
83 export RUSTFLAGS="%{rustflags}"
85 mkdir -p "$CARGO_HOME"
86 cat >.cargo/config <<EOF
88 registry = 'https://github.com/rust-lang/crates.io-index'
89 replace-with = 'vendored-sources'
91 [source.vendored-sources]
92 directory = '$PWD/vendor'
96 # convince libgit2-sys to use the distro libgit2
97 export LIBGIT2_SYS_USE_PKG_CONFIG=1
100 --disable-option-checking \
101 --build=%{rust_triple} --host=%{rust_triple} --target=%{rust_triple} \
102 --rustc=%{_bindir}/rustc --rustdoc=%{_bindir}/rustdoc \
103 --cargo=%{local_cargo} \
104 --release-channel=stable \
105 --disable-cross-tests
110 rm -rf $RPM_BUILD_ROOT
111 export CARGO_HOME="`pwd`/.cargo"
112 export RUSTFLAGS="%{rustflags}"
115 DESTDIR=$RPM_BUILD_ROOT
117 # Remove installer artifacts (manifests, uninstall scripts, etc.)
118 rm -rv $RPM_BUILD_ROOT%{_prefix}/lib/
120 # Fix the etc/ location
121 mv -v $RPM_BUILD_ROOT%{_prefix}/%{_sysconfdir} $RPM_BUILD_ROOT%{_sysconfdir}
123 # Remove unwanted documentation files (we already package them)
124 rm -r $RPM_BUILD_ROOT%{_docdir}/%{name}/
126 # Create the path for crate-devel packages
127 install -d $RPM_BUILD_ROOT%{_datadir}/cargo/registry
130 rm -rf $RPM_BUILD_ROOT
133 %defattr(644,root,root,755)
134 %doc LICENSE-APACHE LICENSE-MIT LICENSE-THIRD-PARTY
136 %attr(755,root,root) %{_bindir}/cargo
137 %{_mandir}/man1/cargo*.1*
138 %{_sysconfdir}/bash_completion.d/cargo
139 #%{zsh_compdir}/_cargo
140 %dir %{_datadir}/cargo
141 %dir %{_datadir}/cargo/registry