From f82754c040f3ccb71dfb823928e199f544cf5794 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sep 22 2023 17:53:13 +0000 Subject: [PATCH 1/2] %cargo_prep: add -v and -N flags to support vendoring This refactors the %cargo_prep macro to support vendoring. --- diff --git a/macros.d/macros.cargo b/macros.d/macros.cargo index c283647..18a3360 100644 --- a/macros.d/macros.cargo +++ b/macros.d/macros.cargo @@ -48,7 +48,12 @@ # - dump custom cargo configuration into ".cargo/config" # - remove "Cargo.lock" if it exists (it breaks builds with custom cargo config) # - remove "Cargo.toml.orig" if it exists (it breaks running "cargo package") -%cargo_prep (\ +# +# Options: +# -v - use vendored sources from instead of +# %%cargo_registry +# -N - Don't set up any registry. Only set up the build configuration. +%cargo_prep(v:N) %{-v:%{-N:%{error:-v and -N are mutually exclusive!}}}(\ set -eu \ %{__mkdir} -p .cargo \ cat > .cargo/config << EOF \ @@ -66,9 +71,10 @@ root = "%{buildroot}%{_prefix}"\ \ [term]\ verbose = true\ -\ -[source]\ -\ +EOF\ +%{!?-N:\ +%{!?-v:\ +cat >> .cargo/config << EOF\ [source.local-registry]\ directory = "%{cargo_registry}"\ \ @@ -76,9 +82,18 @@ directory = "%{cargo_registry}"\ registry = "https://crates.io"\ replace-with = "local-registry"\ EOF\ -%{__rm} -f Cargo.lock \ -%{__rm} -f Cargo.toml.orig \ -) +%{__rm} -f Cargo.lock\ +%{__rm} -f Cargo.toml.orig\ +}\ +%{-v:\ +cat >> .cargo/config << EOF\ +[source.vendored-sources]\ +directory = "%{-v*}"\ +\ +[source.crates-io]\ +replace-with = "vendored-sources"\ +EOF\ +}}) # __cargo_parse_opts: function-like macro which parses common flags into the # equivalent command-line flags for cargo From c9ad7b163e482eb79b6a7960af72f3d82260a0ca Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sep 22 2023 23:48:43 +0000 Subject: [PATCH 2/2] %cargo_prep: remove Cargo.toml.orig unconditionally Cargo.lock should only be removed when using unbundled sources, but it's a good idea to remove Cargo.toml.orig all the time to prevent spurious errors. --- diff --git a/macros.d/macros.cargo b/macros.d/macros.cargo index 18a3360..2a23efc 100644 --- a/macros.d/macros.cargo +++ b/macros.d/macros.cargo @@ -83,7 +83,6 @@ registry = "https://crates.io"\ replace-with = "local-registry"\ EOF\ %{__rm} -f Cargo.lock\ -%{__rm} -f Cargo.toml.orig\ }\ %{-v:\ cat >> .cargo/config << EOF\ @@ -92,8 +91,9 @@ directory = "%{-v*}"\ \ [source.crates-io]\ replace-with = "vendored-sources"\ -EOF\ -}}) +EOF}}\ +%{__rm} -f Cargo.toml.orig\ +) # __cargo_parse_opts: function-like macro which parses common flags into the # equivalent command-line flags for cargo