Skip to contentSkip to conversation

scripts: generate_rust_analyzer: Add message to sysroot assertion

PATCH In review Maurice Hieronymus 2 participants 3 messages Dec 1, 2025 – Jan 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 scripts: generate_rust_analyzer: Add message to sysroot assertion

The assertion that checks whether sysroot lies within sysroot_src currently fails without explaining why. Add an error message that prints both paths to make diagnosing toolchain issues easier.

---
 scripts/generate_rust_analyzer.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
scripts/generate_rust_analyzer.py +7 -2
index 147d0cc94068..446d405ef68a 100755
@@ -213,8 +213,13 @@ def main():
         level=logging.INFO if args.verbose else logging.WARNING
     )
 
-    # Making sure that the `sysroot` and `sysroot_src` belong to the same toolchain.
-    assert args.sysroot in args.sysroot_src.parents
+    assert args.sysroot in args.sysroot_src.parents, \
+        f"""
+        It seems like your sysroot and sysroot_src do not belong to the same toolchain.
+        The sysroot folder must be inside sysroot_src.
+        sysroot={args.sysroot}
+        sysroot_src={args.sysroot_src}
+        """
 
     rust_project = {
         "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.core_edition),

base-commit: 54e3eae855629702c566bd2e130d9f40e7f35bde

Signature · 1 line
2.50.1
#1 lore raw
Quoted 5 lines · Maurice Hieronymus

The assertion that checks whether sysroot lies within sysroot_src currently fails without explaining why. Add an error message that prints both paths to make diagnosing toolchain issues easier.

Changes since v2: - Rebased on rust/rust-next - Remove redundant comment above assertion

Quoted 22 lines

scripts/generate_rust_analyzer.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)

(quoted diff) +0 -0

b/scripts/generate_rust_analyzer.py index 147d0cc94068..446d405ef68a 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -213,8 +213,13 @@ def main():
level=logging.INFO if args.verbose else logging.WARNING )

- # Making sure that the sysroot and sysroot_src belong to the same toolchain. - assert args.sysroot in args.sysroot_src.parents
+ assert args.sysroot in args.sysroot_src.parents, \ + f""" + It seems like your sysroot and sysroot_src do not belong to the same toolchain. + The sysroot folder must be inside sysroot_src. + sysroot={args.sysroot} + sysroot_src={args.sysroot_src} + """

rust_project = { "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.core_edition),

base-commit: 54e3eae855629702c566bd2e130d9f40e7f35bde -- 2.50.1

#2 lore raw
In reply to Maurice Hieronymus
Quoted 6 lines · Maurice Hieronymus

The assertion that checks whether sysroot lies within sysroot_src currently fails without explaining why. Add an error message that prints both paths to make diagnosing toolchain issues easier.

It looks like we are removing the assertion, since there are cases where it does not hold true, like NixOS:

    https://lore.kernel.org/rust-for-linux/[email protected]/

I will take that one as a fix, which will mean it will land earlier than things in rust-next (where this one would have been), so this one here will then not be applicable anymore since there will be no assertion anymore -- I am sorry Maurice, since I know it was one of your first patches...

I guess it could still be nice to somehow check that the sysroot_src belongs to the same toolchain as the sysroot even if it is in a different path, but I don't know if that is possible in the general case, and it is likely not worth the complexity even if there is an elegant way.

Cc'ing Tamir, Jesung and Onur.

Cheers,
Miguel