2018-12-07 21:58:41 +00:00
|
|
|
# Since cargo 1.31, install only uses $CARGO_HOME/config, ignoring $PWD.
|
|
|
|
# https://github.com/rust-lang/cargo/issues/6397
|
|
|
|
# But we can set CARGO_HOME locally, which is a good idea anyway to make sure
|
|
|
|
# it never writes to ~/.cargo during rpmbuild.
|
2019-03-09 21:04:49 +00:00
|
|
|
# We also need RUSTC_BOOTSTRAP since we use -Z avoid-dev-deps
|
|
|
|
# until it gets stabilized: https://github.com/rust-lang/cargo/issues/5133
|
|
|
|
%__cargo %{_bindir}/env CARGO_HOME=.cargo RUSTC_BOOTSTRAP=1 %{_bindir}/cargo
|
|
|
|
%__cargo_common_opts %{?_smp_mflags} -Z avoid-dev-deps
|
2017-02-12 10:28:51 +00:00
|
|
|
%__cargo_inspector %{_bindir}/cargo-inspector
|
2017-01-30 17:46:23 +00:00
|
|
|
|
2017-06-20 21:10:28 +00:00
|
|
|
%cargo_registry %{_datadir}/cargo/registry
|
2017-01-30 17:46:23 +00:00
|
|
|
|
2018-01-08 18:09:54 +00:00
|
|
|
%__cargo_is_lib() %__cargo_inspector --target-kinds Cargo.toml | grep -q -F -x "$(printf 'lib\\\nrlib\\\nproc-macro')"
|
2018-01-08 18:09:10 +00:00
|
|
|
%__cargo_is_bin() %__cargo_inspector --target-kinds Cargo.toml | grep -q -F -x bin
|
2017-02-10 21:10:12 +00:00
|
|
|
|
2017-02-18 15:10:50 +00:00
|
|
|
%cargo_prep (\
|
|
|
|
set -eu \
|
|
|
|
%{__mkdir} -p .cargo \
|
|
|
|
cat > .cargo/config << EOF \
|
2017-01-30 17:46:23 +00:00
|
|
|
[build]\
|
|
|
|
rustc = "%{__rustc}"\
|
2017-06-23 11:35:18 +00:00
|
|
|
rustdoc = "%{__rustdoc}"\
|
2017-01-30 17:46:23 +00:00
|
|
|
rustflags = %{__global_rustflags_toml}\
|
|
|
|
\
|
2018-12-07 21:59:03 +00:00
|
|
|
[install]\
|
|
|
|
root = "%{buildroot}%{_prefix}"\
|
|
|
|
\
|
2017-01-30 17:46:23 +00:00
|
|
|
[term]\
|
|
|
|
verbose = true\
|
|
|
|
\
|
|
|
|
[source]\
|
|
|
|
\
|
|
|
|
[source.local-registry]\
|
|
|
|
directory = "%{cargo_registry}"\
|
|
|
|
\
|
|
|
|
[source.crates-io]\
|
|
|
|
registry = "https://crates.io"\
|
|
|
|
replace-with = "local-registry"\
|
2018-01-09 05:52:36 +00:00
|
|
|
EOF\
|
2018-01-08 22:57:03 +00:00
|
|
|
%{__rm} -f Cargo.lock \
|
2017-02-18 15:10:50 +00:00
|
|
|
)
|
2017-01-30 17:46:23 +00:00
|
|
|
|
2018-06-22 19:53:09 +00:00
|
|
|
%__cargo_parse_opts(naf:) %{shrink:\
|
2018-06-22 19:04:59 +00:00
|
|
|
%{-f:%{-a:%{error:Can't specify both -f(%{-f*}) and -a}}} \
|
|
|
|
%{-n:--no-default-features} \
|
|
|
|
%{-a:--all-features} \
|
|
|
|
%{-f:--features %{-f*}} \
|
|
|
|
%{nil}
|
|
|
|
}
|
2017-01-30 17:46:23 +00:00
|
|
|
|
2019-04-07 10:22:17 +00:00
|
|
|
%cargo_generate_buildrequires(af:) \
|
|
|
|
%{__cargo_inspector} -BR %{__cargo_parse_opts %{-a} %{-f:-f%{-f*}}} Cargo.toml \
|
|
|
|
%if %{with check} \
|
|
|
|
%{__cargo_inspector} -TR Cargo.toml \
|
|
|
|
%endif
|
|
|
|
|
2018-06-22 19:53:09 +00:00
|
|
|
%cargo_build(naf:) %{shrink:\
|
|
|
|
%{__cargo} build \
|
|
|
|
%{__cargo_common_opts} \
|
|
|
|
--release \
|
|
|
|
%{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
|
|
|
|
%* \
|
2018-06-22 19:04:59 +00:00
|
|
|
}
|
2017-01-30 17:46:23 +00:00
|
|
|
|
2018-06-22 19:53:09 +00:00
|
|
|
%cargo_test(naf:) %{shrink:\
|
|
|
|
%{__cargo} test \
|
|
|
|
%{__cargo_common_opts} \
|
|
|
|
--release \
|
|
|
|
--no-fail-fast \
|
|
|
|
%{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
|
|
|
|
%* \
|
2018-06-22 19:04:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
%cargo_install(t:naf:) (\
|
|
|
|
set -eu \
|
|
|
|
if %__cargo_is_lib; then \
|
|
|
|
CRATE_NAME=$(%__cargo_inspector --name Cargo.toml) \
|
|
|
|
CRATE_VERSION=$(%__cargo_inspector --version Cargo.toml) \
|
|
|
|
REG_DIR=%{buildroot}%{cargo_registry}/$CRATE_NAME-$CRATE_VERSION \
|
|
|
|
%{__mkdir} -p $REG_DIR \
|
2019-03-09 21:04:49 +00:00
|
|
|
# Drop all dependency/features information \
|
|
|
|
# so that cargo doesn't fail resolving dependencies: \
|
|
|
|
# https://github.com/rust-lang/cargo/pull/6729 \
|
|
|
|
%{__awk} -i inplace -v INPLACE_SUFFIX=.deps '/^\\\[((.+\\\.)?((dev|build)-)?dependencies|features)/{f=1;next} /^\\\[/{f=0}; !f' Cargo.toml \
|
2019-03-10 09:14:28 +00:00
|
|
|
%{__cargo} package -l | xargs -d '\\\n' %{__cp} --parents -a -t $REG_DIR \
|
2019-03-09 21:04:49 +00:00
|
|
|
%{__mv} Cargo.toml{.deps,} \
|
|
|
|
%{__cp} -a Cargo.toml $REG_DIR/Cargo.toml \
|
2019-04-28 05:47:06 +00:00
|
|
|
%{__rm} -f $REG_DIR/Cargo.toml.{orig,deps} \
|
2018-06-22 19:04:59 +00:00
|
|
|
echo '{"files":{},"package":""}' > $REG_DIR/.cargo-checksum.json \
|
2017-02-10 21:10:12 +00:00
|
|
|
fi \
|
2018-06-22 19:04:59 +00:00
|
|
|
if %__cargo_is_bin; then \
|
2018-06-22 19:53:09 +00:00
|
|
|
%{shrink:%{__cargo} install \
|
2018-06-22 19:04:59 +00:00
|
|
|
%{__cargo_common_opts} \
|
|
|
|
--path . \
|
|
|
|
%{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
|
|
|
|
%* \
|
|
|
|
}\
|
|
|
|
%{__rm} %{buildroot}%{_prefix}/.crates.toml \
|
2017-02-10 21:10:12 +00:00
|
|
|
fi \
|
2017-02-18 15:10:50 +00:00
|
|
|
)
|
2018-10-26 09:20:13 +00:00
|
|
|
|
|
|
|
%__cargo_feature_from_name(n:) %{lua:
|
|
|
|
local name = rpm.expand("%{-n*}")
|
|
|
|
local feature = string.match(name, "^.+%+(.+)-devel$")
|
|
|
|
if feature == nil then
|
|
|
|
print()
|
|
|
|
else
|
|
|
|
print(feature)
|
|
|
|
end
|
|
|
|
}
|