You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rust-packaging/0013-Implement-__cargo_skip...

190 lines
6.5 KiB

From 7b06496a5c1ded5e3cf59d6af0e757974c6ff704 Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
Date: Sat, 8 Jun 2019 19:35:38 +0200
Subject: [PATCH 13/14] Implement %__cargo_skip_build
We need to have an easy way how to skip doing 'cargo build' to speedup a
module builds.
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
---
data/macros.cargo | 80 ++++++++++++++++++++++++------------
rust2rpm/templates/main.spec | 34 ++++++++-------
2 files changed, 72 insertions(+), 42 deletions(-)
diff --git a/data/macros.cargo b/data/macros.cargo
index a60289a..961732d 100644
--- a/data/macros.cargo
+++ b/data/macros.cargo
@@ -10,6 +10,21 @@
%cargo_registry %{_datadir}/cargo/registry
+# If crate not in _build_crates and _module_build is set, we should skip the build
+%__cargo_skip_build %{lua:
+local crate = rpm.expand('%{crate}')
+local build_crate = false
+for w in rpm.expand('%{?_build_crates}'):gmatch('%S+') do
+ if w == crate then
+ build_crate = true
+ break
+ end
+end
+if (rpm.expand('%{defined _module_build}') ~= '0' and not build_crate) then
+ print(1)
+else
+ print(0)
+end}
%__cargo_is_lib() %__cargo_inspector --target-kinds Cargo.toml | grep -q -F -x "$(printf 'lib\\\nrlib\\\nproc-macro')"
%__cargo_is_bin() %__cargo_inspector --target-kinds Cargo.toml | grep -q -F -x bin
@@ -49,27 +64,35 @@ EOF\
}
%cargo_generate_buildrequires(af:) \
-%{__cargo_inspector} -BR %{__cargo_parse_opts %{-a} %{-f:-f%{-f*}}} Cargo.toml \
-%if %{with check} \
-%{__cargo_inspector} -TR Cargo.toml \
+%if ! 0%{?__cargo_skip_build} \
+ %{__cargo_inspector} -BR %{__cargo_parse_opts %{-a} %{-f:-f%{-f*}}} Cargo.toml \
+ %if %{with check} \
+ %{__cargo_inspector} -TR Cargo.toml \
+ %endif \
%endif
-%cargo_build(naf:) %{shrink:\
-%{__cargo} build \
- %{__cargo_common_opts} \
- --release \
- %{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
- %* \
-}
+%cargo_build(naf:) \
+%if ! 0%{?__cargo_skip_build} \
+ %{shrink:\
+ %{__cargo} build \
+ %{__cargo_common_opts} \
+ --release \
+ %{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
+ %* \
+ } \
+%endif
-%cargo_test(naf:) %{shrink:\
-%{__cargo} test \
- %{__cargo_common_opts} \
- --release \
- --no-fail-fast \
- %{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
- %* \
-}
+%cargo_test(naf:) \
+%if ! 0%{?__cargo_skip_build} \
+ %{shrink:\
+ %{__cargo} test \
+ %{__cargo_common_opts} \
+ --release \
+ --no-fail-fast \
+ %{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
+ %* \
+ } \
+%endif
%cargo_install(t:naf:) (\
set -eu \
@@ -88,15 +111,18 @@ if %__cargo_is_lib; then \
%{__rm} -f $REG_DIR/Cargo.toml.{orig,deps} \
echo '{"files":{},"package":""}' > $REG_DIR/.cargo-checksum.json \
fi \
-if %__cargo_is_bin; then \
- %{shrink:%{__cargo} install \
- %{__cargo_common_opts} \
- --path . \
- %{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
- %* \
- }\
- %{__rm} %{buildroot}%{_prefix}/.crates.toml \
-fi \
+%if ! %__cargo_skip_build \
+ if %__cargo_is_bin; then \
+ %{shrink:\
+ %{__cargo} install \
+ %{__cargo_common_opts} \
+ --path . \
+ %{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
+ %* \
+ } \
+ %{__rm} %{buildroot}%{_prefix}/.crates.toml \
+ fi \
+%endif \
)
%__cargo_feature_from_name(n:) %{lua:
diff --git a/rust2rpm/templates/main.spec b/rust2rpm/templates/main.spec
index 660bb60..69d23d7 100644
--- a/rust2rpm/templates/main.spec
+++ b/rust2rpm/templates/main.spec
@@ -42,26 +42,28 @@ ExclusiveArch: %{rust_arches}
BuildRequires: rust-packaging
{% if not generate_buildrequires %}
-{% if not all_features %}
-{% set buildrequires = normalize_deps(md.requires("default", resolve=True))|sort %}
-{% else %}
-{% set buildrequires = normalize_deps(md.all_dependencies)|sort %}
-{% set cargo_args = " -a" %}
-{% endif %}
-{% for req in buildrequires %}
+%if ! %{__cargo_skip_build}
+ {% if not all_features %}
+ {% set buildrequires = normalize_deps(md.requires("default", resolve=True))|sort %}
+ {% else %}
+ {% set buildrequires = normalize_deps(md.all_dependencies)|sort %}
+ {% set cargo_args = " -a" %}
+ {% endif %}
+ {% for req in buildrequires %}
BuildRequires: {{ req }}
-{% endfor %}
-{% set testrequires = normalize_deps(md.dev_dependencies)|sort %}
-{% if testrequires|length > 0 %}
+ {% endfor %}
+ {% set testrequires = normalize_deps(md.dev_dependencies)|sort %}
+ {% if testrequires|length > 0 %}
%if %{with check}
- {% for req in testrequires %}
+ {% for req in testrequires %}
BuildRequires: {{ req }}
- {% endfor %}
+ {% endfor %}
%endif
-{% endif %}
-{% for req in to_list(distconf.get("buildrequires"))|sort %}
+ {% endif %}
+ {% for req in to_list(distconf.get("buildrequires"))|sort %}
BuildRequires: {{ req }}
-{% endfor %}
+ {% endfor %}
+%endif
{% endif %}
%global _description %{expand:
@@ -75,6 +77,7 @@ BuildRequires: {{ req }}
%description %{_description}
{% if include_main %}
+%if ! %{__cargo_skip_build}
%package -n %{crate}
Summary: %{summary}
{% if rust_group is defined %}
@@ -96,6 +99,7 @@ Requires: {{ req }}
{% for bin in bins %}
%{_bindir}/{{ bin.name }}
{% endfor %}
+%endif
{% endif -%}
--
2.22.0.rc3