-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmacros.cargo
61 lines (52 loc) · 2.24 KB
/
macros.cargo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# SPDX-License-Identifier: MIT
%__cargo %{_bindir}/cargo
%__cargo_common_opts %{?_smp_mflags}
%_cargometadir %{_datadir}/cargo-metadata
%cargo_prep (\
set -eu \
%{__mkdir} -p .registry \
REGISTRY="$(realpath .registry)" \
%{__mkdir} -p .cargo \
cat > .cargo/config << EOF \
[build]\
rustc = "%{__rustc}"\
rustdoc = "%{__rustdoc}"\
rustflags = %{__global_rustflags_toml}\
\
[term]\
verbose = true\
\
[source]\
\
[source.local-registry]\
directory = "$REGISTRY"\
\
[source.crates-io]\
registry = "https://crates.io"\
replace-with = "local-registry"\
EOF\
do_cargo_build_registry() { \
%__cargo_build_registry \
} \
do_cargo_build_registry $REGISTRY \
)
%cargo_build %{__cargo} build %{__cargo_common_opts} --release %{?cargo_args}
%cargo_test %{__cargo} test %{__cargo_common_opts} --release --no-fail-fast %{?cargo_args}
%cargo_install \
%{__cargo} install %{__cargo_common_opts} --path . --root %{buildroot}%{_prefix} %{?cargo_args} \
%{__rm} %{buildroot}%{_prefix}/.crates.toml \
%{__mkdir_p} %{buildroot}%{_cargometadir} \
%{__cargo} metadata --format-version 1 %{?cargo_args} > %{buildroot}%{_cargometadir}/%{name}.json
%__cargo_crate_source_url() https://crates.io/api/v1/crates/%1/%2/download#/%1-%2.crate
%__cargo_crate_source_urls grep '^"checksum' | awk '{ print "Source" NR+9999 ": %%{__cargo_crate_source_url " $2 " " $3 "}" } END { print "%%global __cargo_first_crate 10000\\n%%global __cargo_last_crate " NR+9999 }'
%__cargo_build_registry %{lua:for i = rpm.expand("%__cargo_first_crate"),rpm.expand("%__cargo_last_crate") do \
uncompress = rpm.expand("%{uncompress:%{S:" .. i .. "}}") \
print(uncompress .. " | tar -x -C $1\\n") \
template = '{"files":{},"package":"%s"}' \
print("printf '" .. template .. "' $(sha256sum " .. rpm.expand("%{S:" .. i .. "}") .. " | awk '{ print $1 }') > $1/$(" .. uncompress .. " | tar -t | head -n 1 | cut -d / -f 1)/.cargo-checksum.json\\n") \
end}
%cargo_bundle_crates(n:t:l:) \
%{-t:%{-l:%{error:cargo_bundle_crates: Can't specify both -t and -l}}} \
%{!-t:%{!-l:%{error:cargo_bundle_crates: Must specify one of -t or -l}}} \
%{-t:%{expand:%(%{uncompress:%{S:%{-t*}}} | tar -xO %{-n:%{-n*}}%{!-n:%{name}-%{version}}/Cargo.lock | %__cargo_crate_source_urls)}} \
%{-l:%{expand:%(cat %{S:%{-l*}} | %__cargo_crate_source_urls)}}