Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] sanity.bbclass: warn on .cargo/config.toml outside the build tree
@ 2026-06-24  6:42 Hemanth.KumarMD
  2026-06-24  7:41 ` [OE-core] " Paul Barker
  0 siblings, 1 reply; 3+ messages in thread
From: Hemanth.KumarMD @ 2026-06-24  6:42 UTC (permalink / raw)
  To: openembedded-core; +Cc: Randy.MacLeod, Sundeep.Kokkonda, Hemanth.KumarMD

From: Hemanth Kumar M D <Hemanth.KumarMD@windriver.com>

Cargo walks from CWD up to the filesystem root merging every
.cargo/config.toml it finds. Any such file above TOPDIR is silently
picked up and can override Yocto's linker, registry or compiler
settings, leading to build failures.

Until cargo provides a proper fix upstream, add a warning so users
get a clear diagnostic instead of a build error.

Upstream meta-issue: https://github.com/rust-lang/cargo/issues/9769

[YOCTO #15637]

Signed-off-by: Hemanth Kumar M D <Hemanth.KumarMD@windriver.com>
---
 meta/classes-global/sanity.bbclass | 33 ++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/meta/classes-global/sanity.bbclass b/meta/classes-global/sanity.bbclass
index bdfa7f059d..c67c7b8f03 100644
--- a/meta/classes-global/sanity.bbclass
+++ b/meta/classes-global/sanity.bbclass
@@ -854,6 +854,38 @@ def sanity_check_locale(d):
     except locale.Error:
         raise_sanity_error("Your system needs to support the en_US.UTF-8 locale.", d)
 
+def check_cargo_config(d):
+    # Cargo merges .cargo/config.toml from every directory between CWD and
+    # the filesystem root. Warn for anything found in ancestor directories
+    # above TOPDIR that Cargo would pick up silently.
+    import os
+
+    topdir = d.getVar('TOPDIR')
+    ancestor = os.path.dirname(topdir)
+    found = []
+    last_ancestor = None
+    while True:
+        for name in ('config.toml', 'config'):
+            cfg = os.path.join(ancestor, '.cargo', name)
+            if os.path.exists(cfg):
+                found.append(cfg)
+                last_ancestor = ancestor
+                break
+        parent = os.path.dirname(ancestor)
+        if parent == ancestor:
+            break
+        ancestor = parent
+
+    if found:
+        bb.warn("Cargo config file(s) found at %s which is/are outside the build "
+                "directory. Cargo will silently apply their settings during the "
+                "rust/cargo build and can override Yocto's settings like linker, "
+                "registry or compiler settings causing build failures. You can "
+                "either remove these file(s) or move your build directory outside "
+                "of %s to fix this. "
+                "See https://bugzilla.yoctoproject.org/show_bug.cgi?id=15637 for more details."
+                % (', '.join(found), last_ancestor))
+
 def check_sanity_everybuild(status, d):
     import os, stat
     # Sanity tests which test the users environment so need to run at each build (or are so cheap
@@ -873,6 +905,7 @@ def check_sanity_everybuild(status, d):
         status.addresult('Bitbake version %s is required and version %s was found\n' % (minversion, bb.__version__))
 
     sanity_check_locale(d)
+    check_cargo_config(d)
 
     paths = d.getVar('PATH').split(":")
     if "." in paths or "./" in paths or "" in paths:
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-25  7:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-24  6:42 [PATCH] sanity.bbclass: warn on .cargo/config.toml outside the build tree Hemanth.KumarMD
2026-06-24  7:41 ` [OE-core] " Paul Barker
2026-06-25  7:01   ` Hemanth Kumar M D

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox