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