* [PATCH v3] classes/cargo-update-recipe-crates: support multiple Cargo.lock search directories
@ 2026-11-26 8:37 Marco Felsch
2026-11-26 9:17 ` Paul Barker
2026-11-27 12:25 ` [OE-core] " Antoine Lubineau
0 siblings, 2 replies; 5+ messages in thread
From: Marco Felsch @ 2026-11-26 8:37 UTC (permalink / raw)
To: openembedded-core; +Cc: peter.kjellerstedt, yocto, Marco Felsch
Recipes using cargo's -Z build-std must also vendor the standard
library's dependencies. The std sources staged by rust-native
(.../rustlib/src/rust/library) ship a Cargo.lock but no vendor
directory, so those crates need crate:// entries in SRC_URI as well.
Until now only a single directory could be scanned (CARGO_LOCK_SRC_DIR),
which forced the std crate list to be maintained by hand and go stale on
toolchain upgrades, breaking do_compile with:
error: failed to select a version for the requirement
`cfg-if = "^1.0"` (locked to 1.0.4)
Keep the existing CARGO_LOCK_SRC_DIR and extend it to support a
space-separated list of directories, to allow:
CARGO_LOCK_SRC_DIR = "${S} ${STAGING_LIBDIR_NATIVE}/rustlib/src/rust/library"
This way the behavior can be backported.
Crates found in multiple lockfiles are listed only once, in the section
of the first Cargo.lock containing them; conflicting checksums for the
same crate version now fail the task. The crates.io warning now names the
lockfile it came from. Output for recipes with a single lockfile is
unchanged.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
Hi,
this patch adds the support to reference multiple Cargo.lock files which
is handy once a recipe want to rebuild the std-crate for minimized
special purpose builds.
---
Changes in v3:
- Link to v2: https://lore.kernel.org/r/20261124-mfe-multi-cargo-lock-files-v2-1-8fd15cf316aa@pengutronix.de
- Convert to space-separated list to simplify :remove handling and align
with standard bitbake behavior
Changes in v2:
- Link to v1: https://lore.kernel.org/r/20261021-mfe-multi-cargo-lock-files-v1-0-d3510d4ad963@pengutronix.de
- Drop mainlined fixes patch
- Re-use CARGO_LOCK_SRC_DIR to make it backportable
- Add support for v1 Cargo.lock file format
---
.../cargo-update-recipe-crates.bbclass | 87 ++++++++++++++++------
1 file changed, 65 insertions(+), 22 deletions(-)
diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
index 0767b566ee287d11dc2e1e6d0aeea0a0d3b225b8..092dce21fe27bd1c693e8e68c4d6405ad2f03c71 100644
--- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass
+++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
@@ -9,6 +9,10 @@
## This class is used to update the list of crates in SRC_URI
## by reading Cargo.lock in the source tree.
##
+## Both the current Cargo.lock format (checksum stored per [[package]])
+## and the old v1 format (checksums stored in the [metadata] table as
+## "checksum <name> <version> (<source>)" checksum-val) are supported.
+##
## See meta/recipes-devtools/python/python3-bcrypt_*.bb for an example
##
## To perform the update: bitbake -c update_crates recipe-name
@@ -19,38 +23,75 @@ do_update_crates[doc] = "Update the recipe by reading Cargo.lock and write in ${
RECIPE_UPGRADE_EXTRA_TASKS += "do_update_crates"
-# The directory where to search for Cargo.lock files
+# Space-separated list of directories where to search for Cargo.lock files.
+# Crates found in multiple Cargo.lock files are listed only once, in the
+# section of the first Cargo.lock file that contains them.
CARGO_LOCK_SRC_DIR ??= "${S}"
python do_update_crates() {
- cargo_lock_src_dir = d.getVar("CARGO_LOCK_SRC_DIR")
-
- def get_crates(filename):
+ def get_legacy_checksums(crates, filename):
+ # Old (v1) Cargo.lock files do not carry a 'checksum' field per
+ # [[package]]; instead they are collected in the [metadata] table:
+ # "checksum <name> <version> (<source>)" = "<sha256>"
+ # Packages without a checksum (e.g. git sources) use "<none>".
+ checksums = {}
+ for key, value in crates.get('metadata', {}).items():
+ if not key.startswith('checksum '):
+ continue
+ parts = key.split(' ', 3)
+ if len(parts) != 4 or not (parts[3].startswith('(') and parts[3].endswith(')')):
+ print("WARNING: Unable to parse metadata entry '%s' in %s" % (key, filename))
+ continue
+ name, version, source = parts[1], parts[2], parts[3][1:-1]
+ if value == '<none>':
+ continue
+ checksums[(name, version, source)] = value
+ return checksums
+
+ def get_crates(filename, src_dir, seen):
try:
import tomllib
except ImportError:
import bb._vendor.tomli as tomllib
- c_list = '# from %s' % os.path.relpath(filename, cargo_lock_src_dir)
+ c_list = '# from %s' % os.path.relpath(filename, src_dir)
c_list += '\nSRC_URI += " \\'
with open(filename, 'rb') as fp:
crates = tomllib.load(fp)
+ legacy_checksums = get_legacy_checksums(crates, filename)
+
# Build a list with crates info that have crates.io in the source
crates_candidates = list(filter(lambda c: 'crates.io' in c.get('source', ''), crates['package']))
if not crates_candidates:
- print("WARNING: Unable to find any candidate crates that use crates.io")
+ print("WARNING: Unable to find any candidate crates that use crates.io in %s" % filename)
return None
# Update crates uri and their checksum, to avoid name clashing on the checksum
# we need to rename crates with name and version to have a unique key
+ # Crates already emitted for a previous Cargo.lock are skipped.
cksum_list = ''
+ ncrates = 0
for c in crates_candidates:
rename = "%s-%s" % (c['name'], c['version'])
+ checksum = c.get('checksum')
+ if checksum is None:
+ checksum = legacy_checksums.get((c['name'], c['version'], c['source']))
+ if rename in seen:
+ if seen[rename] != checksum:
+ raise ValueError(f"Conflicting checksums for crate {rename}")
+ continue
+ seen[rename] = checksum
c_list += '\n crate://crates.io/%s/%s \\' % (c['name'], c['version'])
- if 'checksum' in c:
- cksum_list += '\nSRC_URI[%s.sha256sum] = "%s"' % (rename, c['checksum'])
+ if checksum is not None:
+ cksum_list += '\nSRC_URI[%s.sha256sum] = "%s"' % (rename, checksum)
+ else:
+ print("WARNING: No checksum found for crate %s in %s" % (rename, filename))
+ ncrates += 1
+
+ if not ncrates:
+ return None
c_list += '\n"\n'
c_list += cksum_list
@@ -62,23 +103,25 @@ python do_update_crates() {
pn = d.getVar("PN")
crates = f"# Autogenerated with 'bitbake -c update_crates {pn}'\n\n"
+ seen = {}
found = False
- for root, dirs, files in os.walk(cargo_lock_src_dir):
- # ignore git and patches directories
- if root.startswith(os.path.join(cargo_lock_src_dir, '.pc')):
- continue
- if root.startswith(os.path.join(cargo_lock_src_dir, '.git')):
- continue
- for file in files:
- if file == 'Cargo.lock':
- cargo_lock_path = os.path.join(root, file)
- c = get_crates(cargo_lock_path)
- if c is not None:
- crates += c
- found = True
+ for cargo_lock_src_dir in d.getVar("CARGO_LOCK_SRC_DIR").split():
+ for root, dirs, files in os.walk(cargo_lock_src_dir):
+ # ignore git and patches directories
+ if root.startswith(os.path.join(cargo_lock_src_dir, '.pc')):
+ continue
+ if root.startswith(os.path.join(cargo_lock_src_dir, '.git')):
+ continue
+ for file in files:
+ if file == 'Cargo.lock':
+ cargo_lock_path = os.path.join(root, file)
+ c = get_crates(cargo_lock_path, cargo_lock_src_dir, seen)
+ if c is not None:
+ crates += c
+ found = True
if not found:
- raise ValueError(f"Unable to find any Cargo.lock in {cargo_lock_src_dir}")
+ raise ValueError(f"Unable to find any Cargo.lock in '{d.getVar('CARGO_LOCK_SRC_DIR')}'")
target_file = d.expand("${THISDIR}/${BPN}-crates.inc")
with open(target_file, 'w') as f:
---
base-commit: 7412d08ab2ee94354a93f3765b94479d84c6b034
change-id: 20261021-mfe-multi-cargo-lock-files-41f9aea21595
Best regards,
--
Marco Felsch <m.felsch@pengutronix.de>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3] classes/cargo-update-recipe-crates: support multiple Cargo.lock search directories
2026-11-26 8:37 [PATCH v3] classes/cargo-update-recipe-crates: support multiple Cargo.lock search directories Marco Felsch
@ 2026-11-26 9:17 ` Paul Barker
2026-11-26 9:51 ` Marco Felsch
2026-11-27 12:25 ` [OE-core] " Antoine Lubineau
1 sibling, 1 reply; 5+ messages in thread
From: Paul Barker @ 2026-11-26 9:17 UTC (permalink / raw)
To: Marco Felsch, openembedded-core; +Cc: peter.kjellerstedt, yocto
On Thu Nov 26, 2026 at 8:37 AM GMT, Marco Felsch wrote:
> Recipes using cargo's -Z build-std must also vendor the standard
> library's dependencies. The std sources staged by rust-native
> (.../rustlib/src/rust/library) ship a Cargo.lock but no vendor
> directory, so those crates need crate:// entries in SRC_URI as well.
> Until now only a single directory could be scanned (CARGO_LOCK_SRC_DIR),
> which forced the std crate list to be maintained by hand and go stale on
> toolchain upgrades, breaking do_compile with:
>
> error: failed to select a version for the requirement
> `cfg-if = "^1.0"` (locked to 1.0.4)
>
> Keep the existing CARGO_LOCK_SRC_DIR and extend it to support a
> space-separated list of directories, to allow:
>
> CARGO_LOCK_SRC_DIR = "${S} ${STAGING_LIBDIR_NATIVE}/rustlib/src/rust/library"
>
> This way the behavior can be backported.
>
> Crates found in multiple lockfiles are listed only once, in the section
> of the first Cargo.lock containing them; conflicting checksums for the
> same crate version now fail the task. The crates.io warning now names the
> lockfile it came from. Output for recipes with a single lockfile is
> unchanged.
>
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
> Hi,
>
> this patch adds the support to reference multiple Cargo.lock files which
> is handy once a recipe want to rebuild the std-crate for minimized
> special purpose builds.
> ---
> Changes in v3:
> - Link to v2: https://lore.kernel.org/r/20261124-mfe-multi-cargo-lock-files-v2-1-8fd15cf316aa@pengutronix.de
> - Convert to space-separated list to simplify :remove handling and align
> with standard bitbake behavior
>
> Changes in v2:
> - Link to v1: https://lore.kernel.org/r/20261021-mfe-multi-cargo-lock-files-v1-0-d3510d4ad963@pengutronix.de
> - Drop mainlined fixes patch
> - Re-use CARGO_LOCK_SRC_DIR to make it backportable
> - Add support for v1 Cargo.lock file format
> ---
> .../cargo-update-recipe-crates.bbclass | 87 ++++++++++++++++------
> 1 file changed, 65 insertions(+), 22 deletions(-)
>
> diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
> index 0767b566ee287d11dc2e1e6d0aeea0a0d3b225b8..092dce21fe27bd1c693e8e68c4d6405ad2f03c71 100644
> --- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass
> +++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
> @@ -9,6 +9,10 @@
> ## This class is used to update the list of crates in SRC_URI
> ## by reading Cargo.lock in the source tree.
> ##
> +## Both the current Cargo.lock format (checksum stored per [[package]])
> +## and the old v1 format (checksums stored in the [metadata] table as
> +## "checksum <name> <version> (<source>)" checksum-val) are supported.
Hi,
It looks like this patch is making two changes at once: Adding support
for multiple Cargo.lock dirs and adding support for multiple Cargo.lock
format versions. There's no mention of the second change in the commit
message.
This would be better as two separate patches.
Best regards,
--
Paul Barker
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] classes/cargo-update-recipe-crates: support multiple Cargo.lock search directories
2026-11-26 9:17 ` Paul Barker
@ 2026-11-26 9:51 ` Marco Felsch
0 siblings, 0 replies; 5+ messages in thread
From: Marco Felsch @ 2026-11-26 9:51 UTC (permalink / raw)
To: Paul Barker; +Cc: openembedded-core, peter.kjellerstedt, yocto
On 26-11-26 09:17, Paul Barker wrote:
> On Thu Nov 26, 2026 at 8:37 AM GMT, Marco Felsch wrote:
> > Recipes using cargo's -Z build-std must also vendor the standard
> > library's dependencies. The std sources staged by rust-native
> > (.../rustlib/src/rust/library) ship a Cargo.lock but no vendor
> > directory, so those crates need crate:// entries in SRC_URI as well.
> > Until now only a single directory could be scanned (CARGO_LOCK_SRC_DIR),
> > which forced the std crate list to be maintained by hand and go stale on
> > toolchain upgrades, breaking do_compile with:
> >
> > error: failed to select a version for the requirement
> > `cfg-if = "^1.0"` (locked to 1.0.4)
> >
> > Keep the existing CARGO_LOCK_SRC_DIR and extend it to support a
> > space-separated list of directories, to allow:
> >
> > CARGO_LOCK_SRC_DIR = "${S} ${STAGING_LIBDIR_NATIVE}/rustlib/src/rust/library"
> >
> > This way the behavior can be backported.
> >
> > Crates found in multiple lockfiles are listed only once, in the section
> > of the first Cargo.lock containing them; conflicting checksums for the
> > same crate version now fail the task. The crates.io warning now names the
> > lockfile it came from. Output for recipes with a single lockfile is
> > unchanged.
> >
> > Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> > ---
> > Hi,
> >
> > this patch adds the support to reference multiple Cargo.lock files which
> > is handy once a recipe want to rebuild the std-crate for minimized
> > special purpose builds.
> > ---
> > Changes in v3:
> > - Link to v2: https://lore.kernel.org/r/20261124-mfe-multi-cargo-lock-files-v2-1-8fd15cf316aa@pengutronix.de
> > - Convert to space-separated list to simplify :remove handling and align
> > with standard bitbake behavior
> >
> > Changes in v2:
> > - Link to v1: https://lore.kernel.org/r/20261021-mfe-multi-cargo-lock-files-v1-0-d3510d4ad963@pengutronix.de
> > - Drop mainlined fixes patch
> > - Re-use CARGO_LOCK_SRC_DIR to make it backportable
> > - Add support for v1 Cargo.lock file format
> > ---
> > .../cargo-update-recipe-crates.bbclass | 87 ++++++++++++++++------
> > 1 file changed, 65 insertions(+), 22 deletions(-)
> >
> > diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
> > index 0767b566ee287d11dc2e1e6d0aeea0a0d3b225b8..092dce21fe27bd1c693e8e68c4d6405ad2f03c71 100644
> > --- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass
> > +++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
> > @@ -9,6 +9,10 @@
> > ## This class is used to update the list of crates in SRC_URI
> > ## by reading Cargo.lock in the source tree.
> > ##
> > +## Both the current Cargo.lock format (checksum stored per [[package]])
> > +## and the old v1 format (checksums stored in the [metadata] table as
> > +## "checksum <name> <version> (<source>)" checksum-val) are supported.
>
> Hi,
>
> It looks like this patch is making two changes at once: Adding support
> for multiple Cargo.lock dirs and adding support for multiple Cargo.lock
> format versions. There's no mention of the second change in the commit
> message.
>
> This would be better as two separate patches.
Sure, I hoped that it can go in one patch since it's only a minor
addition. However, I get your point.
Regards,
Marco
> Best regards,
>
> --
> Paul Barker
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [OE-core] [PATCH v3] classes/cargo-update-recipe-crates: support multiple Cargo.lock search directories
2026-11-26 8:37 [PATCH v3] classes/cargo-update-recipe-crates: support multiple Cargo.lock search directories Marco Felsch
2026-11-26 9:17 ` Paul Barker
@ 2026-11-27 12:25 ` Antoine Lubineau
2026-11-28 13:58 ` Marco Felsch
1 sibling, 1 reply; 5+ messages in thread
From: Antoine Lubineau @ 2026-11-27 12:25 UTC (permalink / raw)
To: m.felsch; +Cc: openembedded-core, peter.kjellerstedt, yocto
[-- Attachment #1: Type: text/plain, Size: 2003 bytes --]
Hi,
On Thu, 26 Nov 2026 at 09:37, Marco Felsch via openembedded-core <m.felsch=
pengutronix.de@lists.openembedded.org> wrote:
> ../..
> + for cargo_lock_src_dir in d.getVar("CARGO_LOCK_SRC_DIR").split():
> + for root, dirs, files in os.walk(cargo_lock_src_dir):
>
May I suggest adding 'dirs.sort()' here? The order of the lists is
dependent on the filesystem, so the operation may not be stable between
runs. That’s not a new issue when having multiple Cargo.lock files in the
same source tree but I never submitted the patch.
Regards,
Antoine
--
*This email and any attachment contains EasyMile’s confidential
information, and must not be modified or circulated without EasyMile’s
prior written consent. It is intended exclusively for their recipient.s. If
you received this message by mistake, please notify us promptly and
immediately delete this email and any of its attachments.*
*As data
controller, EasyMile processes personal data, in compliance with the
European GDPR (EU) 2016/679 of 27 April 2016. To exercise your rights, you
can contact EasyMile at privacy@easymile.com, and if necessary, you may
contact the local competent supervisory authority.”*
*Cet e-mail et toute
pièce jointe contiennent des informations confidentielles d'EasyMile et ne
doivent pas être modifiés ou diffusés sans le consentement écrit préalable
d'EasyMile. Ils sont destinés exclusivement à leur destinataire.s. Si vous
avez reçu ce message par erreur, veuillez nous en informer rapidement et
supprimer immédiatement cet e-mail et toutes ses pièces jointes. *
*En
tant que responsable de traitement, EasyMile traite des données
personnelles, conformément au RGPD européen (UE) 2016/679 du 27 avril 2016.
Pour exercer vos droits, vous pouvez contacter EasyMile à
privacy@easymile.com <mailto:privacy@easymile.com>, et si nécessaire, vous
pouvez contacter l'autorité de contrôle locale compétente.*
[-- Attachment #2: Type: text/html, Size: 3315 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [OE-core] [PATCH v3] classes/cargo-update-recipe-crates: support multiple Cargo.lock search directories
2026-11-27 12:25 ` [OE-core] " Antoine Lubineau
@ 2026-11-28 13:58 ` Marco Felsch
0 siblings, 0 replies; 5+ messages in thread
From: Marco Felsch @ 2026-11-28 13:58 UTC (permalink / raw)
To: Antoine Lubineau; +Cc: openembedded-core, peter.kjellerstedt, yocto
On 26-11-27 13:25, Antoine Lubineau wrote:
> Hi,
>
> On Thu, 26 Nov 2026 at 09:37, Marco Felsch via openembedded-core <m.felsch=
> pengutronix.de@lists.openembedded.org> wrote:
>
> > ../..
> > + for cargo_lock_src_dir in d.getVar("CARGO_LOCK_SRC_DIR").split():
> > + for root, dirs, files in os.walk(cargo_lock_src_dir):
> >
>
> May I suggest adding 'dirs.sort()' here? The order of the lists is
> dependent on the filesystem, so the operation may not be stable between
> runs. That’s not a new issue when having multiple Cargo.lock files in the
> same source tree but I never submitted the patch.
I would like to keep the same behavior as before. Can you send a fixes
patch please?
Regards,
Marco
>
> Regards,
> Antoine
>
> --
>
>
> *This email and any attachment contains EasyMile’s confidential
> information, and must not be modified or circulated without EasyMile’s
> prior written consent. It is intended exclusively for their recipient.s. If
> you received this message by mistake, please notify us promptly and
> immediately delete this email and any of its attachments.*
>
> *As data
> controller, EasyMile processes personal data, in compliance with the
> European GDPR (EU) 2016/679 of 27 April 2016. To exercise your rights, you
> can contact EasyMile at privacy@easymile.com, and if necessary, you may
> contact the local competent supervisory authority.”*
>
> *Cet e-mail et toute
> pièce jointe contiennent des informations confidentielles d'EasyMile et ne
> doivent pas être modifiés ou diffusés sans le consentement écrit préalable
> d'EasyMile. Ils sont destinés exclusivement à leur destinataire.s. Si vous
> avez reçu ce message par erreur, veuillez nous en informer rapidement et
> supprimer immédiatement cet e-mail et toutes ses pièces jointes. *
>
> *En
> tant que responsable de traitement, EasyMile traite des données
> personnelles, conformément au RGPD européen (UE) 2016/679 du 27 avril 2016.
> Pour exercer vos droits, vous pouvez contacter EasyMile à
> privacy@easymile.com <mailto:privacy@easymile.com>, et si nécessaire, vous
> pouvez contacter l'autorité de contrôle locale compétente.*
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-28 13:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 8:37 [PATCH v3] classes/cargo-update-recipe-crates: support multiple Cargo.lock search directories Marco Felsch
2026-11-26 9:17 ` Paul Barker
2026-11-26 9:51 ` Marco Felsch
2026-11-27 12:25 ` [OE-core] " Antoine Lubineau
2026-11-28 13:58 ` Marco Felsch
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.