diff mbox series

[1/3] cargo.bbclass: Allow using --offline instead of --frozen

Message ID 20250129080902.1863054-1-zboszor@gmail.com
State New
Headers show
Series [1/3] cargo.bbclass: Allow using --offline instead of --frozen | expand

Commit Message

Böszörményi Zoltán Jan. 29, 2025, 8:09 a.m. UTC
Some rust packages complain about the --frozen flag:

| error: the lock file .../Cargo.lock needs to be updated but --frozen was passed to prevent this
| If you want to try to generate the lock file without accessing the network, remove the --frozen flag and use --offline instead.

Add a CARGO_USE_OFFLINE_FLAG = 0/1 flag to allow using --offline
instead of --frozen for such cases.

Use 0 by default to keep using --frozen as the default flag.

Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
---
 meta/classes-recipe/cargo.bbclass | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Alexander Kanavin Jan. 29, 2025, 8:49 a.m. UTC | #1
On Wed, 29 Jan 2025 at 09:09, Zoltán Böszörményi <zboszor@gmail.com> wrote:
> | error: the lock file .../Cargo.lock needs to be updated but --frozen was passed to prevent this
> | If you want to try to generate the lock file without accessing the network, remove the --frozen flag and use --offline instead.
>
> Add a CARGO_USE_OFFLINE_FLAG = 0/1 flag to allow using --offline
> instead of --frozen for such cases.

If you add custom patches, you indeed need to re-generate and update
Cargo.lock. There is code to do that in cargo_common_do_patch_paths()
in cargo_common.bbclass, so please check why that isn't working for
you.

Alex
Böszörményi Zoltán Jan. 29, 2025, 9 a.m. UTC | #2
2025. 01. 29. 9:49 keltezéssel, Alexander Kanavin írta:
> On Wed, 29 Jan 2025 at 09:09, Zoltán Böszörményi <zboszor@gmail.com> wrote:
>> | error: the lock file .../Cargo.lock needs to be updated but --frozen was passed to prevent this
>> | If you want to try to generate the lock file without accessing the network, remove the --frozen flag and use --offline instead.
>>
>> Add a CARGO_USE_OFFLINE_FLAG = 0/1 flag to allow using --offline
>> instead of --frozen for such cases.
> If you add custom patches, you indeed need to re-generate and update
> Cargo.lock. There is code to do that in cargo_common_do_patch_paths()
> in cargo_common.bbclass, so please check why that isn't working for
> you.

But patch 2 in the rpm-sequoia recipe is what "cargo update" created
in devshell after patch 1. "cargo build" still complained.

I will look at cargo_common, though, thanks.
Alexander Kanavin Jan. 29, 2025, 9:08 a.m. UTC | #3
On Wed, 29 Jan 2025 at 10:00, Böszörményi Zoltán <zboszor@gmail.com> wrote:
> But patch 2 in the rpm-sequoia recipe is what "cargo update" created
> in devshell after patch 1. "cargo build" still complained.

You did not patch any of the crates, just a couple of the top level
build files, so updating Cargo.lock should not be necessary at all. We
should be able to reuse upstream's supplied Cargo.lock.

Alex
Yoann Congal Jan. 29, 2025, 9:36 a.m. UTC | #4
Le 29/01/2025 à 09:09, Zoltan Boszormenyi via lists.openembedded.org a
écrit :
> Some rust packages complain about the --frozen flag:
> 
> | error: the lock file .../Cargo.lock needs to be updated but --frozen was passed to prevent this
> | If you want to try to generate the lock file without accessing the network, remove the --frozen flag and use --offline instead.
> 
> Add a CARGO_USE_OFFLINE_FLAG = 0/1 flag to allow using --offline
> instead of --frozen for such cases.
> 
> Use 0 by default to keep using --frozen as the default flag.
> 
> Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
> ---
>  meta/classes-recipe/cargo.bbclass | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/meta/classes-recipe/cargo.bbclass b/meta/classes-recipe/cargo.bbclass
> index b583f84bdf..fe5ce9b023 100644
> --- a/meta/classes-recipe/cargo.bbclass
> +++ b/meta/classes-recipe/cargo.bbclass
> @@ -37,7 +37,10 @@ BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}"
>  # and will require an up to date Cargo.lock file.
>  # This force the package being built to already ship a Cargo.lock, in the end
>  # this is what we want, at least, for reproducibility of the build.
> -CARGO_BUILD_FLAGS = "-v --frozen --target ${RUST_HOST_SYS} ${BUILD_MODE} --manifest-path=${CARGO_MANIFEST_PATH}"
> +# Sometimes --freeze fails because Cargo.lock needs to be modified
> +# without version changes. --offline can be used instead.
> +CARGO_USE_OFFLINE_FLAG ??= "0"
> +CARGO_BUILD_FLAGS = "-v ${@ '--frozen' if d.getVar('CARGO_USE_OFFLINE_FLAG') == '0' else '--offline'} --target ${RUST_HOST_SYS} ${BUILD_MODE} --manifest-path=${CARGO_MANIFEST_PATH}"

Maybe use
bb.utils.to_boolean(d.getVar("CARGO_USE_OFFLINE_FLAG"))
instead of
d.getVar('CARGO_USE_OFFLINE_FLAG') == '0'
?

  >  # This is based on the content of CARGO_BUILD_FLAGS and generally
will need to
>  # change if CARGO_BUILD_FLAGS changes.
> 
> 
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#210347): https://lists.openembedded.org/g/openembedded-core/message/210347
> Mute This Topic: https://lists.openembedded.org/mt/110874793/4316185
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [yoann.congal@smile.fr]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/meta/classes-recipe/cargo.bbclass b/meta/classes-recipe/cargo.bbclass
index b583f84bdf..fe5ce9b023 100644
--- a/meta/classes-recipe/cargo.bbclass
+++ b/meta/classes-recipe/cargo.bbclass
@@ -37,7 +37,10 @@  BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}"
 # and will require an up to date Cargo.lock file.
 # This force the package being built to already ship a Cargo.lock, in the end
 # this is what we want, at least, for reproducibility of the build.
-CARGO_BUILD_FLAGS = "-v --frozen --target ${RUST_HOST_SYS} ${BUILD_MODE} --manifest-path=${CARGO_MANIFEST_PATH}"
+# Sometimes --freeze fails because Cargo.lock needs to be modified
+# without version changes. --offline can be used instead.
+CARGO_USE_OFFLINE_FLAG ??= "0"
+CARGO_BUILD_FLAGS = "-v ${@ '--frozen' if d.getVar('CARGO_USE_OFFLINE_FLAG') == '0' else '--offline'} --target ${RUST_HOST_SYS} ${BUILD_MODE} --manifest-path=${CARGO_MANIFEST_PATH}"
 
 # This is based on the content of CARGO_BUILD_FLAGS and generally will need to
 # change if CARGO_BUILD_FLAGS changes.