1 # Only x86_64 and i686 are Tier 1 platforms at this time.
2 # https://forge.rust-lang.org/platform-support.html
3 %define rust_arches x86_64 i686 armv7hl aarch64 ppc64 ppc64le s390x
5 # Only the specified arches will use bootstrap binaries.
6 #define bootstrap_arches %%{rust_arches}
8 %define cargo_version %{version}
9 %define cargo_bootstrap 0.18.0
11 Summary: Rust's package manager and build tool
15 License: ASL 2.0 or MIT
16 Source0: https://github.com/rust-lang/cargo/archive/%{cargo_version}/%{name}-%{cargo_version}.tar.gz
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
21 # Use vendored crate dependencies so we can build offline.
22 # Created using https://github.com/alexcrichton/cargo-vendor/ 0.1.7
23 # It's so big because some of the -sys crates include the C library source they
24 # want to link to. With our -devel buildreqs in place, they'll be used instead.
25 # FIXME: These should all eventually be packaged on their own!
26 Source100: %{name}-%{version}-vendor.tar.xz
28 URL: https://crates.io/
29 %ifarch %{bootstrap_arches}
30 %define bootstrap_root cargo-%{cargo_bootstrap}-%{rust_triple}
31 %define local_cargo %{_builddir}/%{bootstrap_root}/cargo/bin/cargo
33 BuildRequires: %{name} >= 0.13.0
34 %define local_cargo %{_bindir}/%{name}
40 # Indirect dependencies for vendored -sys crates above
41 BuildRequires: curl-devel
42 BuildRequires: libgit2-devel >= 0.24
43 BuildRequires: libssh2-devel
44 BuildRequires: openssl-devel
45 BuildRequires: pkgconfig
46 BuildRequires: zlib-devel
48 ExclusiveArch: %{rust_arches}
50 %define rust_triple %{_target_cpu}-unknown-linux-gnu
53 Cargo is a tool that allows Rust projects to declare their various
54 dependencies and ensure that you'll always get a repeatable build.
57 %ifarch %{bootstrap_arches}
58 %setup -q -n %{bootstrap_root} -T -b %{bootstrap_source}
59 test -f '%{local_cargo}'
63 %setup -q -n %{name}-%{version}-vendor -T -b 100
66 %setup -q -n %{name}-%{cargo_version}
69 %setup -q -n %{name}-%{cargo_version} -T -D -a 1
70 rmdir src/rust-installer
71 mv rust-installer-%{rust_installer} src/rust-installer
73 # define the offline registry
74 %define cargo_home $PWD/.cargo
75 mkdir -p %{cargo_home}
76 cat >.cargo/config <<EOF
78 registry = 'https://github.com/rust-lang/crates.io-index'
79 replace-with = 'vendored-sources'
81 [source.vendored-sources]
82 directory = '$PWD/../%{name}-%{version}-vendor'
85 # This should eventually migrate to distro policy
86 # Enable optimization, debuginfo, and link hardening.
87 %define rustflags -Copt-level=3 -Cdebuginfo=2 -Clink-arg=-Wl,-z,relro,-z,now
90 # convince libgit2-sys to use the distro libgit2
91 export LIBGIT2_SYS_USE_PKG_CONFIG=1
93 # use our offline registry and custom rustc flags
94 export CARGO_HOME="%{cargo_home}"
95 export RUSTFLAGS="%{rustflags}"
98 --disable-option-checking \
99 --build=%{rust_triple} --host=%{rust_triple} --target=%{rust_triple} \
100 --rustc=%{_bindir}/rustc --rustdoc=%{_bindir}/rustdoc \
101 --cargo=%{local_cargo} \
102 --release-channel=stable \
103 --disable-cross-tests
108 rm -rf $RPM_BUILD_ROOT
109 export CARGO_HOME="%{cargo_home}"
110 export RUSTFLAGS="%{rustflags}"
113 DESTDIR=$RPM_BUILD_ROOT
115 # Remove installer artifacts (manifests, uninstall scripts, etc.)
116 rm -rv $RPM_BUILD_ROOT%{_prefix}/lib/
118 # Fix the etc/ location
119 mv -v $RPM_BUILD_ROOT%{_prefix}/%{_sysconfdir} $RPM_BUILD_ROOT%{_sysconfdir}
121 # Remove unwanted documentation files (we already package them)
122 rm -rf $RPM_BUILD_ROOT%{_docdir}/%{name}/
124 # Create the path for crate-devel packages
125 install -d $RPM_BUILD_ROOT%{_datadir}/cargo/registry
128 rm -rf $RPM_BUILD_ROOT
131 %defattr(644,root,root,755)
132 %doc LICENSE-APACHE LICENSE-MIT LICENSE-THIRD-PARTY
134 %attr(755,root,root) %{_bindir}/cargo
135 %{_mandir}/man1/cargo*.1*
136 %{_sysconfdir}/bash_completion.d/cargo
137 %{zsh_compdir}/_cargo
138 %dir %{_datadir}/cargo
139 %dir %{_datadir}/cargo/registry