#87 %__cargo_skip_build
Merged 4 years ago by ignatenkobrain. Opened 4 years ago by ignatenkobrain.
fedora-rust/ ignatenkobrain/rust2rpm skip-build  into  master

file modified
+38 -27
@@ -49,27 +49,35 @@ 

  }

  

  %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 +96,18 @@ 

    %{__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:

file modified
+16
@@ -37,3 +37,19 @@ 

  \

      print(url .. crate .. '/' .. version .. '/download#/' .. crate .. '-' .. version .. '.crate')

  }

+ 

+ # 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}

file modified
+37 -15
@@ -1,8 +1,12 @@ 

  {% include target ~ "-header.spec.inc" ignore missing %}

  # Generated by rust2rpm {{ generator_version }}

  %bcond_without check

+ {% set only_main = False %}

  {% if not include_main %}

  %global debug_package %{nil}

+ {% elif not include_devel %}

+   {% set only_main = True %}

+ %global __cargo_skip_build 0

  {% endif %}

  

  %global crate {{ md.name }}
@@ -39,29 +43,41 @@ 

  {% endif %}

  

  ExclusiveArch:  %{rust_arches}

+ {% if not only_main %}

+ %if %{__cargo_skip_build}

+ BuildArch:      noarch

+ %endif

+ {% endif %}

  

  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 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 %}

+   {% set testrequires = normalize_deps(md.dev_dependencies)|sort %}

+   {% set has_buildrequires = (buildrequires + testrequires)|length > 0 %}

+   {% if has_buildrequires and not only_main %}

+ %if ! %{__cargo_skip_build}

+   {% endif %}

+   {% for req in buildrequires %}

  BuildRequires:  {{ req }}

- {% endfor %}

- {% set testrequires = normalize_deps(md.dev_dependencies)|sort %}

- {% if testrequires|length > 0 %}

+   {% endfor %}

+   {% 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 %}

+   {% if has_buildrequires and not only_main %}

+ %endif

+   {% endif %}

  {% endif %}

  

  %global _description %{expand:
@@ -75,6 +91,9 @@ 

  %description %{_description}

  

  {% if include_main %}

+   {% if not only_main %}

+ %if ! %{__cargo_skip_build}

+   {% endif %}

  %package     -n %{crate}

  Summary:        %{summary}

    {% if rust_group is defined %}
@@ -96,6 +115,9 @@ 

    {% for bin in bins %}

  %{_bindir}/{{ bin.name }}

    {% endfor %}

+   {% if not only_main %}

+ %endif

+   {% endif %}

  

  {% endif -%}

  

With this, we should be able to build modules with Rust apps within 10 minutes or so.

rebased onto 7b06496a5c1ded5e3cf59d6af0e757974c6ff704

4 years ago

2 new commits added

  • Set BuildArch: noarch with %__cargo_skip_build
  • Implement %__cargo_skip_build
4 years ago

rebased onto 37cf4d78df2f3805f1f230252e1c0030a2f08877

4 years ago

rebased onto 1de62182fbc42d812dd2afb0b7439c509c537faf

4 years ago

rebased onto 40e6a336d7c0bd4d0d4533414a3d42d8031a5799

4 years ago

rebased onto 4c89185

4 years ago

Pull-Request has been merged by ignatenkobrain

4 years ago