5737f7
# Explicitly use bindir tools, in case others are in the PATH,
5737f7
# like the rustup shims in a user's ~/.cargo/bin/.
5737f7
#
5737f7
# Since cargo 1.31, install only uses $CARGO_HOME/config, ignoring $PWD.
5737f7
#   https://github.com/rust-lang/cargo/issues/6397
5737f7
# But we can set CARGO_HOME locally, which is a good idea anyway to make sure
5737f7
# it never writes to ~/.cargo during rpmbuild.
5737f7
%__cargo %{_bindir}/env CARGO_HOME=.cargo %{_bindir}/cargo
5737f7
%__rustc %{_bindir}/rustc
5737f7
%__rustdoc %{_bindir}/rustdoc
5737f7
5737f7
# Enable optimization, debuginfo, and link hardening.
5737f7
%__global_rustflags -Copt-level=3 -Cdebuginfo=2 -Clink-arg=-Wl,-z,relro,-z,now
5737f7
5737f7
%__global_rustflags_toml [%{lua:
5737f7
    for arg in string.gmatch(rpm.expand("%{__global_rustflags}"), "%S+") do
5737f7
        print('"' .. arg .. '", ')
5737f7
    end}]
5737f7
5737f7
%cargo_prep(V:) (\
5737f7
%{__mkdir} -p .cargo \
5737f7
cat > .cargo/config << EOF \
5737f7
[build]\
5737f7
rustc = "%{__rustc}"\
5737f7
rustdoc = "%{__rustdoc}"\
5737f7
rustflags = %{__global_rustflags_toml}\
5737f7
\
5737f7
[install]\
5737f7
root = "%{buildroot}%{_prefix}"\
5737f7
\
5737f7
[term]\
5737f7
verbose = true\
5737f7
EOF\
5737f7
%if 0%{-V:1}\
5737f7
%{__tar} -xoaf %{S:%{-V*}}\
5737f7
cat >> .cargo/config << EOF \
5737f7
\
5737f7
[source.crates-io]\
5737f7
replace-with = "vendored-sources"\
5737f7
\
5737f7
[source.vendored-sources]\
5737f7
directory = "./vendor"\
5737f7
EOF\
5737f7
%endif\
5737f7
)
5737f7
5737f7
%cargo_build %__cargo build --release %{?_smp_mflags}
5737f7
5737f7
%cargo_test %__cargo test --release %{?_smp_mflags} --no-fail-fast
5737f7
5737f7
%cargo_install %__cargo install --no-track --path .