* [PATCH 1/6] scripts: generate_rust_analyzer: rename cfg to generated_cfg
2026-01-20 8:52 [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Eliot Courtney
@ 2026-01-20 8:52 ` Eliot Courtney
2026-01-20 15:28 ` Tamir Duberstein
2026-01-20 8:52 ` [PATCH 2/6] scripts: generate_rust_analyzer: plumb editions via command line Eliot Courtney
` (5 subsequent siblings)
6 siblings, 1 reply; 23+ messages in thread
From: Eliot Courtney @ 2026-01-20 8:52 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier
Cc: rust-for-linux, linux-kernel, linux-kbuild, Eliot Courtney
This variable is for the cfg from generated files. It's also easy to
confuse with the `cfg` parameter in append_crate(), so rename it.
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
scripts/generate_rust_analyzer.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 3b645da90092..c188d1f1fd5b 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -21,12 +21,12 @@ def args_crates_cfgs(cfgs):
def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edition):
# Generate the configuration list.
- cfg = []
+ generated_cfg = []
with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
for line in fd:
line = line.replace("--cfg=", "")
line = line.replace("\n", "")
- cfg.append(line)
+ generated_cfg.append(line)
# Now fill the crates list -- dependencies need to come first.
#
@@ -173,7 +173,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
display_name,
srctree / "rust"/ display_name / "lib.rs",
deps,
- cfg=cfg,
+ cfg=generated_cfg,
)
crates[-1]["env"]["OBJTREE"] = str(objtree.resolve(True))
crates[-1]["source"] = {
@@ -215,7 +215,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
name,
path,
["core", "kernel"],
- cfg=cfg,
+ cfg=generated_cfg,
)
return crates
--
2.52.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 1/6] scripts: generate_rust_analyzer: rename cfg to generated_cfg
2026-01-20 8:52 ` [PATCH 1/6] scripts: generate_rust_analyzer: rename cfg to generated_cfg Eliot Courtney
@ 2026-01-20 15:28 ` Tamir Duberstein
2026-03-02 17:09 ` Tamir Duberstein
0 siblings, 1 reply; 23+ messages in thread
From: Tamir Duberstein @ 2026-01-20 15:28 UTC (permalink / raw)
To: Eliot Courtney
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Tue, Jan 20, 2026 at 3:54 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>
> This variable is for the cfg from generated files. It's also easy to
> confuse with the `cfg` parameter in append_crate(), so rename it.
>
> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
I have the same change sitting around locally.
Reviewed-by: Tamir Duberstein <tamird@kernel.org>
> ---
> scripts/generate_rust_analyzer.py | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index 3b645da90092..c188d1f1fd5b 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -21,12 +21,12 @@ def args_crates_cfgs(cfgs):
>
> def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edition):
> # Generate the configuration list.
> - cfg = []
> + generated_cfg = []
> with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
> for line in fd:
> line = line.replace("--cfg=", "")
> line = line.replace("\n", "")
> - cfg.append(line)
> + generated_cfg.append(line)
>
> # Now fill the crates list -- dependencies need to come first.
> #
> @@ -173,7 +173,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> display_name,
> srctree / "rust"/ display_name / "lib.rs",
> deps,
> - cfg=cfg,
> + cfg=generated_cfg,
> )
> crates[-1]["env"]["OBJTREE"] = str(objtree.resolve(True))
> crates[-1]["source"] = {
> @@ -215,7 +215,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> name,
> path,
> ["core", "kernel"],
> - cfg=cfg,
> + cfg=generated_cfg,
> )
>
> return crates
>
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 23+ messages in thread* Re: [PATCH 1/6] scripts: generate_rust_analyzer: rename cfg to generated_cfg
2026-01-20 15:28 ` Tamir Duberstein
@ 2026-03-02 17:09 ` Tamir Duberstein
0 siblings, 0 replies; 23+ messages in thread
From: Tamir Duberstein @ 2026-03-02 17:09 UTC (permalink / raw)
To: Eliot Courtney
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Tue, Jan 20, 2026 at 10:28 AM Tamir Duberstein <tamird@kernel.org> wrote:
>
> On Tue, Jan 20, 2026 at 3:54 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
> >
> > This variable is for the cfg from generated files. It's also easy to
> > confuse with the `cfg` parameter in append_crate(), so rename it.
> >
> > Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
>
> I have the same change sitting around locally.
>
> Reviewed-by: Tamir Duberstein <tamird@kernel.org>
>
>
> > ---
> > scripts/generate_rust_analyzer.py | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> > index 3b645da90092..c188d1f1fd5b 100755
> > --- a/scripts/generate_rust_analyzer.py
> > +++ b/scripts/generate_rust_analyzer.py
> > @@ -21,12 +21,12 @@ def args_crates_cfgs(cfgs):
> >
> > def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edition):
> > # Generate the configuration list.
> > - cfg = []
> > + generated_cfg = []
> > with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
> > for line in fd:
> > line = line.replace("--cfg=", "")
> > line = line.replace("\n", "")
> > - cfg.append(line)
> > + generated_cfg.append(line)
> >
> > # Now fill the crates list -- dependencies need to come first.
> > #
> > @@ -173,7 +173,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> > display_name,
> > srctree / "rust"/ display_name / "lib.rs",
> > deps,
> > - cfg=cfg,
> > + cfg=generated_cfg,
> > )
> > crates[-1]["env"]["OBJTREE"] = str(objtree.resolve(True))
> > crates[-1]["source"] = {
> > @@ -215,7 +215,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> > name,
> > path,
> > ["core", "kernel"],
> > - cfg=cfg,
> > + cfg=generated_cfg,
> > )
> >
> > return crates
> >
> > --
> > 2.52.0
> >
> >
Applied to `rust-analyzer-next` (just this patch). Thanks!
[ Changed title to include script extension. - Tamir ]
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 2/6] scripts: generate_rust_analyzer: plumb editions via command line
2026-01-20 8:52 [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Eliot Courtney
2026-01-20 8:52 ` [PATCH 1/6] scripts: generate_rust_analyzer: rename cfg to generated_cfg Eliot Courtney
@ 2026-01-20 8:52 ` Eliot Courtney
2026-01-20 13:57 ` Miguel Ojeda
2026-01-20 15:28 ` Tamir Duberstein
2026-01-20 8:52 ` [PATCH 3/6] scripts: generate_rust_analyzer: plumb crate-attrs Eliot Courtney
` (4 subsequent siblings)
6 siblings, 2 replies; 23+ messages in thread
From: Eliot Courtney @ 2026-01-20 8:52 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier
Cc: rust-for-linux, linux-kernel, linux-kbuild, Eliot Courtney
Add --editions argument to pass crate editions in a similar way to the
existing --cfgs mechanism.
It sets editions as follows:
- core: 2024 for rustc >= 1.87 otherwise 2021
- quote: 2018
- all others: 2021
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
rust/Makefile | 8 +++--
scripts/generate_rust_analyzer.py | 70 ++++++++++++++++++++++-----------------
2 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/rust/Makefile b/rust/Makefile
index 4dcc2eff51cb..2238b0b69197 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -95,8 +95,10 @@ quote-cfgs := \
quote-skip_flags := \
--edition=2021
+quote-edition := 2018
+
quote-flags := \
- --edition=2018 \
+ --edition=$(quote-edition) \
--cap-lints=allow \
--extern proc_macro2 \
$(call cfgs-to-flags,$(quote-cfgs))
@@ -567,10 +569,12 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
rust-analyzer:
$(Q)MAKEFLAGS= $(srctree)/scripts/generate_rust_analyzer.py \
- --cfgs='core=$(core-cfgs)' $(core-edition) \
+ --cfgs='core=$(core-cfgs)' \
--cfgs='proc_macro2=$(proc_macro2-cfgs)' \
--cfgs='quote=$(quote-cfgs)' \
--cfgs='syn=$(syn-cfgs)' \
+ --editions='core=$(core-edition)' \
+ --editions='quote=$(quote-edition)' \
$(realpath $(srctree)) $(realpath $(objtree)) \
$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
> rust-project.json
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index c188d1f1fd5b..17ed5546504b 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -11,6 +11,13 @@ import pathlib
import subprocess
import sys
+def args_single(args):
+ result = {}
+ for arg in args:
+ crate, val = arg.split("=", 1)
+ result[crate] = val
+ return result
+
def args_crates_cfgs(cfgs):
crates_cfgs = {}
for cfg in cfgs:
@@ -19,7 +26,7 @@ def args_crates_cfgs(cfgs):
return crates_cfgs
-def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edition):
+def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions):
# Generate the configuration list.
generated_cfg = []
with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
@@ -34,8 +41,35 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
crates = []
crates_indexes = {}
crates_cfgs = args_crates_cfgs(cfgs)
+ crates_editions = args_single(editions)
+
+ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
+ # Miguel Ojeda writes:
+ #
+ # > ... in principle even the sysroot crates may have different
+ # > editions.
+ # >
+ # > For instance, in the move to 2024, it seems all happened at once
+ # > in 1.87.0 in these upstream commits:
+ # >
+ # > 0e071c2c6a58 ("Migrate core to Rust 2024")
+ # > f505d4e8e380 ("Migrate alloc to Rust 2024")
+ # > 0b2489c226c3 ("Migrate proc_macro to Rust 2024")
+ # > 993359e70112 ("Migrate std to Rust 2024")
+ # >
+ # > But in the previous move to 2021, `std` moved in 1.59.0, while
+ # > the others in 1.60.0:
+ # >
+ # > b656384d8398 ("Update stdlib to the 2021 edition")
+ # > 06a1c14d52a8 ("Switch all libraries to the 2021 edition")
+ #
+ # Link: https://lore.kernel.org/all/CANiq72kd9bHdKaAm=8xCUhSHMy2csyVed69bOc4dXyFAW4sfuw@mail.gmail.com/
+ #
+ # At the time of writing all rust versions we support build the
+ # sysroot crates with the same edition. We may need to relax this
+ # assumption if future edition moves span multiple rust versions.
+ edition = crates_editions.get(display_name, "2021")
- def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
crate = {
"display_name": display_name,
"root_module": str(root_module),
@@ -68,31 +102,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
deps,
cfg,
is_workspace_member=False,
- # Miguel Ojeda writes:
- #
- # > ... in principle even the sysroot crates may have different
- # > editions.
- # >
- # > For instance, in the move to 2024, it seems all happened at once
- # > in 1.87.0 in these upstream commits:
- # >
- # > 0e071c2c6a58 ("Migrate core to Rust 2024")
- # > f505d4e8e380 ("Migrate alloc to Rust 2024")
- # > 0b2489c226c3 ("Migrate proc_macro to Rust 2024")
- # > 993359e70112 ("Migrate std to Rust 2024")
- # >
- # > But in the previous move to 2021, `std` moved in 1.59.0, while
- # > the others in 1.60.0:
- # >
- # > b656384d8398 ("Update stdlib to the 2021 edition")
- # > 06a1c14d52a8 ("Switch all libraries to the 2021 edition")
- #
- # Link: https://lore.kernel.org/all/CANiq72kd9bHdKaAm=8xCUhSHMy2csyVed69bOc4dXyFAW4sfuw@mail.gmail.com/
- #
- # At the time of writing all rust versions we support build the
- # sysroot crates with the same edition. We may need to relax this
- # assumption if future edition moves span multiple rust versions.
- edition=core_edition,
)
# NB: sysroot crates reexport items from one another so setting up our transitive dependencies
@@ -120,8 +129,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
"quote",
srctree / "rust" / "quote" / "lib.rs",
["core", "alloc", "std", "proc_macro", "proc_macro2"],
- cfg=crates_cfgs["quote"],
- edition="2018",
+ cfg=crates_cfgs["quote"]
)
append_crate(
@@ -224,7 +232,7 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', '-v', action='store_true')
parser.add_argument('--cfgs', action='append', default=[])
- parser.add_argument("core_edition")
+ parser.add_argument('--editions', action='append', default=[])
parser.add_argument("srctree", type=pathlib.Path)
parser.add_argument("objtree", type=pathlib.Path)
parser.add_argument("sysroot", type=pathlib.Path)
@@ -238,7 +246,7 @@ def main():
)
rust_project = {
- "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.core_edition),
+ "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions),
"sysroot": str(args.sysroot),
}
--
2.52.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 2/6] scripts: generate_rust_analyzer: plumb editions via command line
2026-01-20 8:52 ` [PATCH 2/6] scripts: generate_rust_analyzer: plumb editions via command line Eliot Courtney
@ 2026-01-20 13:57 ` Miguel Ojeda
2026-01-20 15:28 ` Tamir Duberstein
1 sibling, 0 replies; 23+ messages in thread
From: Miguel Ojeda @ 2026-01-20 13:57 UTC (permalink / raw)
To: Eliot Courtney
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Tue, Jan 20, 2026 at 9:54 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>
> Add --editions argument to pass crate editions in a similar way to the
> existing --cfgs mechanism.
>
> It sets editions as follows:
> - core: 2024 for rustc >= 1.87 otherwise 2021
> - quote: 2018
> - all others: 2021
Could you please explain in the commit message the reasons behind the
change? i.e. commit messages should explain the "why" (advantages
etc.), not just the "what".
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/6] scripts: generate_rust_analyzer: plumb editions via command line
2026-01-20 8:52 ` [PATCH 2/6] scripts: generate_rust_analyzer: plumb editions via command line Eliot Courtney
2026-01-20 13:57 ` Miguel Ojeda
@ 2026-01-20 15:28 ` Tamir Duberstein
1 sibling, 0 replies; 23+ messages in thread
From: Tamir Duberstein @ 2026-01-20 15:28 UTC (permalink / raw)
To: Eliot Courtney
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Tue, Jan 20, 2026 at 3:54 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>
> Add --editions argument to pass crate editions in a similar way to the
> existing --cfgs mechanism.
>
> It sets editions as follows:
> - core: 2024 for rustc >= 1.87 otherwise 2021
> - quote: 2018
> - all others: 2021
>
> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
> ---
> rust/Makefile | 8 +++--
> scripts/generate_rust_analyzer.py | 70 ++++++++++++++++++++++-----------------
> 2 files changed, 45 insertions(+), 33 deletions(-)
>
> diff --git a/rust/Makefile b/rust/Makefile
> index 4dcc2eff51cb..2238b0b69197 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -95,8 +95,10 @@ quote-cfgs := \
> quote-skip_flags := \
> --edition=2021
>
> +quote-edition := 2018
> +
> quote-flags := \
> - --edition=2018 \
> + --edition=$(quote-edition) \
> --cap-lints=allow \
> --extern proc_macro2 \
> $(call cfgs-to-flags,$(quote-cfgs))
> @@ -567,10 +569,12 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
>
> rust-analyzer:
> $(Q)MAKEFLAGS= $(srctree)/scripts/generate_rust_analyzer.py \
> - --cfgs='core=$(core-cfgs)' $(core-edition) \
> + --cfgs='core=$(core-cfgs)' \
> --cfgs='proc_macro2=$(proc_macro2-cfgs)' \
> --cfgs='quote=$(quote-cfgs)' \
> --cfgs='syn=$(syn-cfgs)' \
> + --editions='core=$(core-edition)' \
> + --editions='quote=$(quote-edition)' \
> $(realpath $(srctree)) $(realpath $(objtree)) \
> $(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
> > rust-project.json
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index c188d1f1fd5b..17ed5546504b 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -11,6 +11,13 @@ import pathlib
> import subprocess
> import sys
>
> +def args_single(args):
> + result = {}
> + for arg in args:
> + crate, val = arg.split("=", 1)
> + result[crate] = val
> + return result
This is a bit sloppy. If we expect exactly one edition per crate, we
should error when we find that is not the case.
Separately this is almost identical to `args_crates_cfgs`; it would be
better to unify the implementation.
> +
> def args_crates_cfgs(cfgs):
> crates_cfgs = {}
> for cfg in cfgs:
> @@ -19,7 +26,7 @@ def args_crates_cfgs(cfgs):
>
> return crates_cfgs
>
> -def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edition):
> +def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions):
> # Generate the configuration list.
> generated_cfg = []
> with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
> @@ -34,8 +41,35 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> crates = []
> crates_indexes = {}
> crates_cfgs = args_crates_cfgs(cfgs)
> + crates_editions = args_single(editions)
> +
> + def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
> + # Miguel Ojeda writes:
> + #
> + # > ... in principle even the sysroot crates may have different
> + # > editions.
> + # >
> + # > For instance, in the move to 2024, it seems all happened at once
> + # > in 1.87.0 in these upstream commits:
> + # >
> + # > 0e071c2c6a58 ("Migrate core to Rust 2024")
> + # > f505d4e8e380 ("Migrate alloc to Rust 2024")
> + # > 0b2489c226c3 ("Migrate proc_macro to Rust 2024")
> + # > 993359e70112 ("Migrate std to Rust 2024")
> + # >
> + # > But in the previous move to 2021, `std` moved in 1.59.0, while
> + # > the others in 1.60.0:
> + # >
> + # > b656384d8398 ("Update stdlib to the 2021 edition")
> + # > 06a1c14d52a8 ("Switch all libraries to the 2021 edition")
> + #
> + # Link: https://lore.kernel.org/all/CANiq72kd9bHdKaAm=8xCUhSHMy2csyVed69bOc4dXyFAW4sfuw@mail.gmail.com/
> + #
> + # At the time of writing all rust versions we support build the
> + # sysroot crates with the same edition. We may need to relax this
> + # assumption if future edition moves span multiple rust versions.
> + edition = crates_editions.get(display_name, "2021")
This logic is incorrect, and the relocation of this comment is also
incorrect. The sysroot crates std, alloc, and proc_macro should also
be compiled with core's edition (this comment explains why). Your
patch changes that to edition 2021, which is incorrect.
>
> - def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
> crate = {
> "display_name": display_name,
> "root_module": str(root_module),
> @@ -68,31 +102,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> deps,
> cfg,
> is_workspace_member=False,
> - # Miguel Ojeda writes:
> - #
> - # > ... in principle even the sysroot crates may have different
> - # > editions.
> - # >
> - # > For instance, in the move to 2024, it seems all happened at once
> - # > in 1.87.0 in these upstream commits:
> - # >
> - # > 0e071c2c6a58 ("Migrate core to Rust 2024")
> - # > f505d4e8e380 ("Migrate alloc to Rust 2024")
> - # > 0b2489c226c3 ("Migrate proc_macro to Rust 2024")
> - # > 993359e70112 ("Migrate std to Rust 2024")
> - # >
> - # > But in the previous move to 2021, `std` moved in 1.59.0, while
> - # > the others in 1.60.0:
> - # >
> - # > b656384d8398 ("Update stdlib to the 2021 edition")
> - # > 06a1c14d52a8 ("Switch all libraries to the 2021 edition")
> - #
> - # Link: https://lore.kernel.org/all/CANiq72kd9bHdKaAm=8xCUhSHMy2csyVed69bOc4dXyFAW4sfuw@mail.gmail.com/
> - #
> - # At the time of writing all rust versions we support build the
> - # sysroot crates with the same edition. We may need to relax this
> - # assumption if future edition moves span multiple rust versions.
> - edition=core_edition,
> )
>
> # NB: sysroot crates reexport items from one another so setting up our transitive dependencies
> @@ -120,8 +129,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> "quote",
> srctree / "rust" / "quote" / "lib.rs",
> ["core", "alloc", "std", "proc_macro", "proc_macro2"],
> - cfg=crates_cfgs["quote"],
> - edition="2018",
> + cfg=crates_cfgs["quote"]
> )
>
> append_crate(
> @@ -224,7 +232,7 @@ def main():
> parser = argparse.ArgumentParser()
> parser.add_argument('--verbose', '-v', action='store_true')
> parser.add_argument('--cfgs', action='append', default=[])
> - parser.add_argument("core_edition")
> + parser.add_argument('--editions', action='append', default=[])
> parser.add_argument("srctree", type=pathlib.Path)
> parser.add_argument("objtree", type=pathlib.Path)
> parser.add_argument("sysroot", type=pathlib.Path)
> @@ -238,7 +246,7 @@ def main():
> )
>
> rust_project = {
> - "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.core_edition),
> + "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions),
> "sysroot": str(args.sysroot),
> }
>
>
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 3/6] scripts: generate_rust_analyzer: plumb crate-attrs
2026-01-20 8:52 [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Eliot Courtney
2026-01-20 8:52 ` [PATCH 1/6] scripts: generate_rust_analyzer: rename cfg to generated_cfg Eliot Courtney
2026-01-20 8:52 ` [PATCH 2/6] scripts: generate_rust_analyzer: plumb editions via command line Eliot Courtney
@ 2026-01-20 8:52 ` Eliot Courtney
2026-01-20 15:28 ` Tamir Duberstein
2026-01-20 8:52 ` [PATCH 4/6] scripts: generate_rust_analyzer: plumb common crate-attrs for non-host crates Eliot Courtney
` (3 subsequent siblings)
6 siblings, 1 reply; 23+ messages in thread
From: Eliot Courtney @ 2026-01-20 8:52 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier
Cc: rust-for-linux, linux-kernel, linux-kbuild, Eliot Courtney
Add --crate-attrs argument to pass per-crate attributes.
The crate_attrs field was added to rust-analyzer in v0.3.2727 (~1.94.0)
and is silently ignored by older versions, so it's safe to add it.
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
rust/Makefile | 5 ++++-
scripts/generate_rust_analyzer.py | 9 +++++++--
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/rust/Makefile b/rust/Makefile
index 2238b0b69197..e6c5108ab625 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -84,9 +84,11 @@ proc_macro2-cfgs := \
$(if $(call rustc-min-version,108800),proc_macro_span_file proc_macro_span_location)
# Stable since Rust 1.79.0: `feature(proc_macro_byte_character,proc_macro_c_str_literals)`.
+proc_macro2-crate-attrs := feature(proc_macro_byte_character,proc_macro_c_str_literals)
+
proc_macro2-flags := \
--cap-lints=allow \
- -Zcrate-attr='feature(proc_macro_byte_character,proc_macro_c_str_literals)' \
+ -Zcrate-attr='$(proc_macro2-crate-attrs)' \
$(call cfgs-to-flags,$(proc_macro2-cfgs))
quote-cfgs := \
@@ -575,6 +577,7 @@ rust-analyzer:
--cfgs='syn=$(syn-cfgs)' \
--editions='core=$(core-edition)' \
--editions='quote=$(quote-edition)' \
+ --crate-attrs='proc_macro2=$(proc_macro2-crate-attrs)' \
$(realpath $(srctree)) $(realpath $(objtree)) \
$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
> rust-project.json
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 17ed5546504b..e8c50812fb9f 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -11,6 +11,7 @@ import pathlib
import subprocess
import sys
+
def args_single(args):
result = {}
for arg in args:
@@ -26,7 +27,7 @@ def args_crates_cfgs(cfgs):
return crates_cfgs
-def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions):
+def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions, crate_attrs):
# Generate the configuration list.
generated_cfg = []
with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
@@ -42,6 +43,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions)
crates_indexes = {}
crates_cfgs = args_crates_cfgs(cfgs)
crates_editions = args_single(editions)
+ crates_crate_attrs = args_crates_cfgs(crate_attrs)
def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
# Miguel Ojeda writes:
@@ -78,6 +80,8 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions)
"deps": [{"crate": crates_indexes[dep], "name": dep} for dep in deps],
"cfg": cfg,
"edition": edition,
+ # Crate attributes were introduced in 1.94.0 but older versions will silently ignore this.
+ "crate_attrs": crates_crate_attrs.get(display_name, []),
"env": {
"RUST_MODFILE": "This is only for rust-analyzer"
}
@@ -233,6 +237,7 @@ def main():
parser.add_argument('--verbose', '-v', action='store_true')
parser.add_argument('--cfgs', action='append', default=[])
parser.add_argument('--editions', action='append', default=[])
+ parser.add_argument('--crate-attrs', action='append', default=[])
parser.add_argument("srctree", type=pathlib.Path)
parser.add_argument("objtree", type=pathlib.Path)
parser.add_argument("sysroot", type=pathlib.Path)
@@ -246,7 +251,7 @@ def main():
)
rust_project = {
- "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions),
+ "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions, args.crate_attrs),
"sysroot": str(args.sysroot),
}
--
2.52.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 3/6] scripts: generate_rust_analyzer: plumb crate-attrs
2026-01-20 8:52 ` [PATCH 3/6] scripts: generate_rust_analyzer: plumb crate-attrs Eliot Courtney
@ 2026-01-20 15:28 ` Tamir Duberstein
0 siblings, 0 replies; 23+ messages in thread
From: Tamir Duberstein @ 2026-01-20 15:28 UTC (permalink / raw)
To: Eliot Courtney
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Tue, Jan 20, 2026 at 3:54 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>
> Add --crate-attrs argument to pass per-crate attributes.
>
> The crate_attrs field was added to rust-analyzer in v0.3.2727 (~1.94.0)
> and is silently ignored by older versions, so it's safe to add it.
Please add citations for both claims made here.
>
> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
> ---
> rust/Makefile | 5 ++++-
> scripts/generate_rust_analyzer.py | 9 +++++++--
> 2 files changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/rust/Makefile b/rust/Makefile
> index 2238b0b69197..e6c5108ab625 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -84,9 +84,11 @@ proc_macro2-cfgs := \
> $(if $(call rustc-min-version,108800),proc_macro_span_file proc_macro_span_location)
>
> # Stable since Rust 1.79.0: `feature(proc_macro_byte_character,proc_macro_c_str_literals)`.
> +proc_macro2-crate-attrs := feature(proc_macro_byte_character,proc_macro_c_str_literals)
> +
> proc_macro2-flags := \
> --cap-lints=allow \
> - -Zcrate-attr='feature(proc_macro_byte_character,proc_macro_c_str_literals)' \
> + -Zcrate-attr='$(proc_macro2-crate-attrs)' \
> $(call cfgs-to-flags,$(proc_macro2-cfgs))
>
> quote-cfgs := \
> @@ -575,6 +577,7 @@ rust-analyzer:
> --cfgs='syn=$(syn-cfgs)' \
> --editions='core=$(core-edition)' \
> --editions='quote=$(quote-edition)' \
> + --crate-attrs='proc_macro2=$(proc_macro2-crate-attrs)' \
> $(realpath $(srctree)) $(realpath $(objtree)) \
> $(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
> > rust-project.json
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index 17ed5546504b..e8c50812fb9f 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -11,6 +11,7 @@ import pathlib
> import subprocess
> import sys
>
> +
> def args_single(args):
> result = {}
> for arg in args:
> @@ -26,7 +27,7 @@ def args_crates_cfgs(cfgs):
>
> return crates_cfgs
>
> -def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions):
> +def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions, crate_attrs):
> # Generate the configuration list.
> generated_cfg = []
> with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
> @@ -42,6 +43,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions)
> crates_indexes = {}
> crates_cfgs = args_crates_cfgs(cfgs)
> crates_editions = args_single(editions)
> + crates_crate_attrs = args_crates_cfgs(crate_attrs)
>
> def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
> # Miguel Ojeda writes:
> @@ -78,6 +80,8 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions)
> "deps": [{"crate": crates_indexes[dep], "name": dep} for dep in deps],
> "cfg": cfg,
> "edition": edition,
> + # Crate attributes were introduced in 1.94.0 but older versions will silently ignore this.
Citations needed.
> + "crate_attrs": crates_crate_attrs.get(display_name, []),
> "env": {
> "RUST_MODFILE": "This is only for rust-analyzer"
> }
> @@ -233,6 +237,7 @@ def main():
> parser.add_argument('--verbose', '-v', action='store_true')
> parser.add_argument('--cfgs', action='append', default=[])
> parser.add_argument('--editions', action='append', default=[])
> + parser.add_argument('--crate-attrs', action='append', default=[])
> parser.add_argument("srctree", type=pathlib.Path)
> parser.add_argument("objtree", type=pathlib.Path)
> parser.add_argument("sysroot", type=pathlib.Path)
> @@ -246,7 +251,7 @@ def main():
> )
>
> rust_project = {
> - "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions),
> + "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions, args.crate_attrs),
> "sysroot": str(args.sysroot),
> }
>
>
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 4/6] scripts: generate_rust_analyzer: plumb common crate-attrs for non-host crates
2026-01-20 8:52 [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Eliot Courtney
` (2 preceding siblings ...)
2026-01-20 8:52 ` [PATCH 3/6] scripts: generate_rust_analyzer: plumb crate-attrs Eliot Courtney
@ 2026-01-20 8:52 ` Eliot Courtney
2026-01-20 15:28 ` Tamir Duberstein
2026-01-20 8:52 ` [PATCH 5/6] scripts: generate_rust_analyzer: add pin_init to driver crate deps Eliot Courtney
` (2 subsequent siblings)
6 siblings, 1 reply; 23+ messages in thread
From: Eliot Courtney @ 2026-01-20 8:52 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier
Cc: rust-for-linux, linux-kernel, linux-kbuild, Eliot Courtney
Add --common-crate-attrs argument to specify crate attributes that
apply to all non-host crates. This means no_std will be specified where it
should be, for example.
Proc macro and libraries used by proc macro crates run on the host and
do not get this set of common crate-attrs. This mirrors
rust_procmacrolibrary in the build system.
Create scripts/Makefile.rust to hold shared Rust definitions.
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
rust/Makefile | 3 +++
scripts/Makefile.build | 14 +-------------
scripts/Makefile.rust | 20 ++++++++++++++++++++
scripts/generate_rust_analyzer.py | 20 +++++++++++++++-----
4 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/rust/Makefile b/rust/Makefile
index e6c5108ab625..750db2885ba2 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
+include $(srctree)/scripts/Makefile.rust
+
# Where to place rustdoc generated documentation
rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
@@ -578,6 +580,7 @@ rust-analyzer:
--editions='core=$(core-edition)' \
--editions='quote=$(quote-edition)' \
--crate-attrs='proc_macro2=$(proc_macro2-crate-attrs)' \
+ --common-crate-attrs='$(rust_common_crate_attrs)' \
$(realpath $(srctree)) $(realpath $(objtree)) \
$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
> rust-project.json
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 0c838c467c76..e9af8a11f2dc 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -34,6 +34,7 @@ subdir-ccflags-y :=
include $(srctree)/scripts/Kbuild.include
include $(srctree)/scripts/Makefile.compiler
+include $(srctree)/scripts/Makefile.rust
include $(kbuild-file)
include $(srctree)/scripts/Makefile.lib
@@ -306,19 +307,6 @@ $(obj)/%.lst: $(obj)/%.c FORCE
# Compile Rust sources (.rs)
# ---------------------------------------------------------------------------
-# The features in this list are the ones allowed for non-`rust/` code.
-#
-# - Stable since Rust 1.81.0: `feature(lint_reasons)`.
-# - Stable since Rust 1.82.0: `feature(asm_const)`,
-# `feature(offset_of_nested)`, `feature(raw_ref_op)`.
-# - Stable since Rust 1.87.0: `feature(asm_goto)`.
-# - Expected to become stable: `feature(arbitrary_self_types)`.
-# - To be determined: `feature(used_with_arg)`.
-#
-# Please see https://github.com/Rust-for-Linux/linux/issues/2 for details on
-# the unstable features in use.
-rust_allowed_features := asm_const,asm_goto,arbitrary_self_types,lint_reasons,offset_of_nested,raw_ref_op,used_with_arg
-
# `--out-dir` is required to avoid temporaries being created by `rustc` in the
# current working directory, which may be not accessible in the out-of-tree
# modules case.
diff --git a/scripts/Makefile.rust b/scripts/Makefile.rust
new file mode 100644
index 000000000000..d96662d1ac17
--- /dev/null
+++ b/scripts/Makefile.rust
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0
+# ==========================================================================
+# Rust shared definitions
+# ==========================================================================
+
+# The features in this list are the ones allowed for non-`rust/` code.
+#
+# - Stable since Rust 1.81.0: `feature(lint_reasons)`.
+# - Stable since Rust 1.82.0: `feature(asm_const)`,
+# `feature(offset_of_nested)`, `feature(raw_ref_op)`.
+# - Stable since Rust 1.87.0: `feature(asm_goto)`.
+# - Expected to become stable: `feature(arbitrary_self_types)`.
+# - To be determined: `feature(used_with_arg)`.
+#
+# Please see https://github.com/Rust-for-Linux/linux/issues/2 for details on
+# the unstable features in use.
+rust_allowed_features := asm_const,asm_goto,arbitrary_self_types,lint_reasons,offset_of_nested,raw_ref_op,used_with_arg
+
+# Common crate attrs for non-host, non-sysroot crates.
+rust_common_crate_attrs := no_std feature($(rust_allowed_features))
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index e8c50812fb9f..0d93e8a8e4bd 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -27,7 +27,7 @@ def args_crates_cfgs(cfgs):
return crates_cfgs
-def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions, crate_attrs):
+def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions, crate_attrs, common_crate_attrs):
# Generate the configuration list.
generated_cfg = []
with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
@@ -45,7 +45,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
crates_editions = args_single(editions)
crates_crate_attrs = args_crates_cfgs(crate_attrs)
- def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
+ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, is_proc_macro_library=False):
# Miguel Ojeda writes:
#
# > ... in principle even the sysroot crates may have different
@@ -72,6 +72,11 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
# assumption if future edition moves span multiple rust versions.
edition = crates_editions.get(display_name, "2021")
+ crate_attrs = crates_crate_attrs.get(display_name, [])
+ # Apply common crate attrs to non-host crates.
+ if not is_proc_macro_library and not is_proc_macro:
+ crate_attrs = common_crate_attrs + crate_attrs
+
crate = {
"display_name": display_name,
"root_module": str(root_module),
@@ -81,7 +86,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
"cfg": cfg,
"edition": edition,
# Crate attributes were introduced in 1.94.0 but older versions will silently ignore this.
- "crate_attrs": crates_crate_attrs.get(display_name, []),
+ "crate_attrs": crate_attrs,
"env": {
"RUST_MODFILE": "This is only for rust-analyzer"
}
@@ -127,13 +132,15 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
srctree / "rust" / "proc-macro2" / "lib.rs",
["core", "alloc", "std", "proc_macro"],
cfg=crates_cfgs["proc_macro2"],
+ is_proc_macro_library=True,
)
append_crate(
"quote",
srctree / "rust" / "quote" / "lib.rs",
["core", "alloc", "std", "proc_macro", "proc_macro2"],
- cfg=crates_cfgs["quote"]
+ cfg=crates_cfgs["quote"],
+ is_proc_macro_library=True,
)
append_crate(
@@ -141,6 +148,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
srctree / "rust" / "syn" / "lib.rs",
["std", "proc_macro", "proc_macro2", "quote"],
cfg=crates_cfgs["syn"],
+ is_proc_macro_library=True,
)
append_crate(
@@ -238,6 +246,7 @@ def main():
parser.add_argument('--cfgs', action='append', default=[])
parser.add_argument('--editions', action='append', default=[])
parser.add_argument('--crate-attrs', action='append', default=[])
+ parser.add_argument('--common-crate-attrs', default='')
parser.add_argument("srctree", type=pathlib.Path)
parser.add_argument("objtree", type=pathlib.Path)
parser.add_argument("sysroot", type=pathlib.Path)
@@ -250,8 +259,9 @@ def main():
level=logging.INFO if args.verbose else logging.WARNING
)
+ common_crate_attrs = args.common_crate_attrs.split() if args.common_crate_attrs else []
rust_project = {
- "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions, args.crate_attrs),
+ "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions, args.crate_attrs, common_crate_attrs),
"sysroot": str(args.sysroot),
}
--
2.52.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 4/6] scripts: generate_rust_analyzer: plumb common crate-attrs for non-host crates
2026-01-20 8:52 ` [PATCH 4/6] scripts: generate_rust_analyzer: plumb common crate-attrs for non-host crates Eliot Courtney
@ 2026-01-20 15:28 ` Tamir Duberstein
0 siblings, 0 replies; 23+ messages in thread
From: Tamir Duberstein @ 2026-01-20 15:28 UTC (permalink / raw)
To: Eliot Courtney
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Tue, Jan 20, 2026 at 3:54 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>
> Add --common-crate-attrs argument to specify crate attributes that
> apply to all non-host crates. This means no_std will be specified where it
> should be, for example.
>
> Proc macro and libraries used by proc macro crates run on the host and
> do not get this set of common crate-attrs. This mirrors
> rust_procmacrolibrary in the build system.
>
> Create scripts/Makefile.rust to hold shared Rust definitions.
>
> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
This looks ok to me, but I would prefer to land type annotations
(https://lore.kernel.org/all/20250424-rust-analyzer-host-v6-0-40e67fe5c38a@gmail.com/)
first.
> ---
> rust/Makefile | 3 +++
> scripts/Makefile.build | 14 +-------------
> scripts/Makefile.rust | 20 ++++++++++++++++++++
> scripts/generate_rust_analyzer.py | 20 +++++++++++++++-----
> 4 files changed, 39 insertions(+), 18 deletions(-)
>
> diff --git a/rust/Makefile b/rust/Makefile
> index e6c5108ab625..750db2885ba2 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -1,5 +1,7 @@
> # SPDX-License-Identifier: GPL-2.0
>
> +include $(srctree)/scripts/Makefile.rust
> +
> # Where to place rustdoc generated documentation
> rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
>
> @@ -578,6 +580,7 @@ rust-analyzer:
> --editions='core=$(core-edition)' \
> --editions='quote=$(quote-edition)' \
> --crate-attrs='proc_macro2=$(proc_macro2-crate-attrs)' \
> + --common-crate-attrs='$(rust_common_crate_attrs)' \
> $(realpath $(srctree)) $(realpath $(objtree)) \
> $(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
> > rust-project.json
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 0c838c467c76..e9af8a11f2dc 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -34,6 +34,7 @@ subdir-ccflags-y :=
>
> include $(srctree)/scripts/Kbuild.include
> include $(srctree)/scripts/Makefile.compiler
> +include $(srctree)/scripts/Makefile.rust
> include $(kbuild-file)
> include $(srctree)/scripts/Makefile.lib
>
> @@ -306,19 +307,6 @@ $(obj)/%.lst: $(obj)/%.c FORCE
> # Compile Rust sources (.rs)
> # ---------------------------------------------------------------------------
>
> -# The features in this list are the ones allowed for non-`rust/` code.
> -#
> -# - Stable since Rust 1.81.0: `feature(lint_reasons)`.
> -# - Stable since Rust 1.82.0: `feature(asm_const)`,
> -# `feature(offset_of_nested)`, `feature(raw_ref_op)`.
> -# - Stable since Rust 1.87.0: `feature(asm_goto)`.
> -# - Expected to become stable: `feature(arbitrary_self_types)`.
> -# - To be determined: `feature(used_with_arg)`.
> -#
> -# Please see https://github.com/Rust-for-Linux/linux/issues/2 for details on
> -# the unstable features in use.
> -rust_allowed_features := asm_const,asm_goto,arbitrary_self_types,lint_reasons,offset_of_nested,raw_ref_op,used_with_arg
> -
> # `--out-dir` is required to avoid temporaries being created by `rustc` in the
> # current working directory, which may be not accessible in the out-of-tree
> # modules case.
> diff --git a/scripts/Makefile.rust b/scripts/Makefile.rust
> new file mode 100644
> index 000000000000..d96662d1ac17
> --- /dev/null
> +++ b/scripts/Makefile.rust
> @@ -0,0 +1,20 @@
> +# SPDX-License-Identifier: GPL-2.0
> +# ==========================================================================
> +# Rust shared definitions
> +# ==========================================================================
> +
> +# The features in this list are the ones allowed for non-`rust/` code.
> +#
> +# - Stable since Rust 1.81.0: `feature(lint_reasons)`.
> +# - Stable since Rust 1.82.0: `feature(asm_const)`,
> +# `feature(offset_of_nested)`, `feature(raw_ref_op)`.
> +# - Stable since Rust 1.87.0: `feature(asm_goto)`.
> +# - Expected to become stable: `feature(arbitrary_self_types)`.
> +# - To be determined: `feature(used_with_arg)`.
> +#
> +# Please see https://github.com/Rust-for-Linux/linux/issues/2 for details on
> +# the unstable features in use.
> +rust_allowed_features := asm_const,asm_goto,arbitrary_self_types,lint_reasons,offset_of_nested,raw_ref_op,used_with_arg
> +
> +# Common crate attrs for non-host, non-sysroot crates.
> +rust_common_crate_attrs := no_std feature($(rust_allowed_features))
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index e8c50812fb9f..0d93e8a8e4bd 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -27,7 +27,7 @@ def args_crates_cfgs(cfgs):
>
> return crates_cfgs
>
> -def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions, crate_attrs):
> +def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions, crate_attrs, common_crate_attrs):
> # Generate the configuration list.
> generated_cfg = []
> with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
> @@ -45,7 +45,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> crates_editions = args_single(editions)
> crates_crate_attrs = args_crates_cfgs(crate_attrs)
>
> - def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
> + def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, is_proc_macro_library=False):
> # Miguel Ojeda writes:
> #
> # > ... in principle even the sysroot crates may have different
> @@ -72,6 +72,11 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> # assumption if future edition moves span multiple rust versions.
> edition = crates_editions.get(display_name, "2021")
>
> + crate_attrs = crates_crate_attrs.get(display_name, [])
> + # Apply common crate attrs to non-host crates.
> + if not is_proc_macro_library and not is_proc_macro:
> + crate_attrs = common_crate_attrs + crate_attrs
> +
> crate = {
> "display_name": display_name,
> "root_module": str(root_module),
> @@ -81,7 +86,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> "cfg": cfg,
> "edition": edition,
> # Crate attributes were introduced in 1.94.0 but older versions will silently ignore this.
> - "crate_attrs": crates_crate_attrs.get(display_name, []),
> + "crate_attrs": crate_attrs,
> "env": {
> "RUST_MODFILE": "This is only for rust-analyzer"
> }
> @@ -127,13 +132,15 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> srctree / "rust" / "proc-macro2" / "lib.rs",
> ["core", "alloc", "std", "proc_macro"],
> cfg=crates_cfgs["proc_macro2"],
> + is_proc_macro_library=True,
> )
>
> append_crate(
> "quote",
> srctree / "rust" / "quote" / "lib.rs",
> ["core", "alloc", "std", "proc_macro", "proc_macro2"],
> - cfg=crates_cfgs["quote"]
> + cfg=crates_cfgs["quote"],
> + is_proc_macro_library=True,
> )
>
> append_crate(
> @@ -141,6 +148,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> srctree / "rust" / "syn" / "lib.rs",
> ["std", "proc_macro", "proc_macro2", "quote"],
> cfg=crates_cfgs["syn"],
> + is_proc_macro_library=True,
> )
>
> append_crate(
> @@ -238,6 +246,7 @@ def main():
> parser.add_argument('--cfgs', action='append', default=[])
> parser.add_argument('--editions', action='append', default=[])
> parser.add_argument('--crate-attrs', action='append', default=[])
> + parser.add_argument('--common-crate-attrs', default='')
> parser.add_argument("srctree", type=pathlib.Path)
> parser.add_argument("objtree", type=pathlib.Path)
> parser.add_argument("sysroot", type=pathlib.Path)
> @@ -250,8 +259,9 @@ def main():
> level=logging.INFO if args.verbose else logging.WARNING
> )
>
> + common_crate_attrs = args.common_crate_attrs.split() if args.common_crate_attrs else []
> rust_project = {
> - "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions, args.crate_attrs),
> + "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions, args.crate_attrs, common_crate_attrs),
> "sysroot": str(args.sysroot),
> }
>
>
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 5/6] scripts: generate_rust_analyzer: add pin_init to driver crate deps
2026-01-20 8:52 [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Eliot Courtney
` (3 preceding siblings ...)
2026-01-20 8:52 ` [PATCH 4/6] scripts: generate_rust_analyzer: plumb common crate-attrs for non-host crates Eliot Courtney
@ 2026-01-20 8:52 ` Eliot Courtney
2026-01-20 15:28 ` Tamir Duberstein
2026-01-20 8:52 ` [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project Eliot Courtney
2026-01-20 13:38 ` [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Miguel Ojeda
6 siblings, 1 reply; 23+ messages in thread
From: Eliot Courtney @ 2026-01-20 8:52 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier
Cc: rust-for-linux, linux-kernel, linux-kbuild, Eliot Courtney
This adds the missing pin_init dep to driver crates.
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
scripts/generate_rust_analyzer.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 0d93e8a8e4bd..ba2f6b0fb99b 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -234,7 +234,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
append_crate(
name,
path,
- ["core", "kernel"],
+ ["core", "kernel", "pin_init"],
cfg=generated_cfg,
)
--
2.52.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 5/6] scripts: generate_rust_analyzer: add pin_init to driver crate deps
2026-01-20 8:52 ` [PATCH 5/6] scripts: generate_rust_analyzer: add pin_init to driver crate deps Eliot Courtney
@ 2026-01-20 15:28 ` Tamir Duberstein
0 siblings, 0 replies; 23+ messages in thread
From: Tamir Duberstein @ 2026-01-20 15:28 UTC (permalink / raw)
To: Eliot Courtney
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Tue, Jan 20, 2026 at 3:54 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>
> This adds the missing pin_init dep to driver crates.
This needs citations, and perhaps a Fixes tag.
>
> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
> ---
> scripts/generate_rust_analyzer.py | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index 0d93e8a8e4bd..ba2f6b0fb99b 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -234,7 +234,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> append_crate(
> name,
> path,
> - ["core", "kernel"],
> + ["core", "kernel", "pin_init"],
> cfg=generated_cfg,
> )
>
>
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project
2026-01-20 8:52 [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Eliot Courtney
` (4 preceding siblings ...)
2026-01-20 8:52 ` [PATCH 5/6] scripts: generate_rust_analyzer: add pin_init to driver crate deps Eliot Courtney
@ 2026-01-20 8:52 ` Eliot Courtney
2026-01-20 15:34 ` Tamir Duberstein
2026-01-20 13:38 ` [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Miguel Ojeda
6 siblings, 1 reply; 23+ messages in thread
From: Eliot Courtney @ 2026-01-20 8:52 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier
Cc: rust-for-linux, linux-kernel, linux-kbuild, Eliot Courtney
Use rust-analyzer's sysroot_project feature to properly configure
sysroot crates (core, alloc, std, proc_macro). This allows
rust-analyzer to correctly resolve items from the sysroot and
automatically add sysroot crate dependencies to all project crates.
Some sysroot crates use #[path] directives to load files outside of
their directory but still in the sysroot. This is disallowed by
rust-analyzer, so the sysroot crate are not properly loaded. Loading them
using sysroot_project tells rust-analyzer to let them load anything inside
sysroot_src.
The sysroot_project field was added to rust-analyzer in v0.3.2328
(~1.87.0) and is silently ignored by older versions. In that case,
rust-analyzer falls back to loading the sysroot via sysroot_src.
This basically works, but the advantage of using sysroot_project is
that we can make the set of features/cfgs more similar to what the
actual build uses.
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
scripts/generate_rust_analyzer.py | 118 ++++++++++++++++++++++----------------
1 file changed, 70 insertions(+), 48 deletions(-)
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index ba2f6b0fb99b..f8666050a997 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -27,25 +27,14 @@ def args_crates_cfgs(cfgs):
return crates_cfgs
-def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions, crate_attrs, common_crate_attrs):
- # Generate the configuration list.
- generated_cfg = []
- with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
- for line in fd:
- line = line.replace("--cfg=", "")
- line = line.replace("\n", "")
- generated_cfg.append(line)
-
- # Now fill the crates list -- dependencies need to come first.
- #
- # Avoid O(n^2) iterations by keeping a map of indexes.
+def generate_sysroot_crates(cfgs, editions, crate_attrs):
crates = []
crates_indexes = {}
crates_cfgs = args_crates_cfgs(cfgs)
crates_editions = args_single(editions)
crates_crate_attrs = args_crates_cfgs(crate_attrs)
- def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, is_proc_macro_library=False):
+ def append_sysroot_crate(display_name, deps):
# Miguel Ojeda writes:
#
# > ... in principle even the sysroot crates may have different
@@ -72,6 +61,52 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
# assumption if future edition moves span multiple rust versions.
edition = crates_editions.get(display_name, "2021")
+ cfg = crates_cfgs.get(display_name, [])
+ crates_indexes[display_name] = len(crates)
+ crates.append({
+ "display_name": display_name,
+ # Paths in sysroot_project are relative to sysroot_src.
+ "root_module": f"{display_name}/src/lib.rs",
+ "is_workspace_member": False,
+ "is_proc_macro": False,
+ "deps": [{"crate": crates_indexes[dep], "name": dep} for dep in deps],
+ "cfg": cfg,
+ "edition": edition,
+ # Crate attributes were introduced in 1.94.0 but older versions will silently ignore this.
+ "crate_attrs": crates_crate_attrs.get(display_name, []),
+ "env": {
+ "RUST_MODFILE": "This is only for rust-analyzer"
+ }
+ })
+
+ append_sysroot_crate("core", [])
+ append_sysroot_crate("alloc", ["core"])
+ append_sysroot_crate("std", ["alloc", "core"])
+ append_sysroot_crate("proc_macro", ["core", "std"])
+
+ return crates
+
+def generate_crates(srctree, objtree, external_src, cfgs, editions, crate_attrs, common_crate_attrs):
+ # Generate the configuration list.
+ generated_cfg = []
+ with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
+ for line in fd:
+ line = line.replace("--cfg=", "")
+ line = line.replace("\n", "")
+ generated_cfg.append(line)
+
+ # Now fill the crates list -- dependencies need to come first.
+ #
+ # Avoid O(n^2) iterations by keeping a map of indexes.
+ crates = []
+ crates_indexes = {}
+ crates_cfgs = args_crates_cfgs(cfgs)
+ crates_editions = args_single(editions)
+ crates_crate_attrs = args_crates_cfgs(crate_attrs)
+
+ def append_crate(display_name, root_module, deps, cfg=[], is_proc_macro=False, is_proc_macro_library=False):
+ edition = crates_editions.get(display_name, "2021")
+
crate_attrs = crates_crate_attrs.get(display_name, [])
# Apply common crate attrs to non-host crates.
if not is_proc_macro_library and not is_proc_macro:
@@ -80,7 +115,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
crate = {
"display_name": display_name,
"root_module": str(root_module),
- "is_workspace_member": is_workspace_member,
+ "is_workspace_member": True,
"is_proc_macro": is_proc_macro,
"deps": [{"crate": crates_indexes[dep], "name": dep} for dep in deps],
"cfg": cfg,
@@ -100,37 +135,20 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
crates_indexes[display_name] = len(crates)
crates.append(crate)
- def append_sysroot_crate(
- display_name,
- deps,
- cfg=[],
- ):
- append_crate(
- display_name,
- sysroot_src / display_name / "src" / "lib.rs",
- deps,
- cfg,
- is_workspace_member=False,
- )
-
- # NB: sysroot crates reexport items from one another so setting up our transitive dependencies
- # here is important for ensuring that rust-analyzer can resolve symbols. The sources of truth
- # for this dependency graph are `(sysroot_src / crate / "Cargo.toml" for crate in crates)`.
- append_sysroot_crate("core", [], cfg=crates_cfgs.get("core", []))
- append_sysroot_crate("alloc", ["core"])
- append_sysroot_crate("std", ["alloc", "core"])
- append_sysroot_crate("proc_macro", ["core", "std"])
+ # Sysroot crates (core, alloc, std, proc_macro) are in sysroot_project,
+ # and their deps are automatically added to all crates by rust-analyzer.
+ # We only need to define deps between our own crates here.
append_crate(
"compiler_builtins",
srctree / "rust" / "compiler_builtins.rs",
- ["core"],
+ [],
)
append_crate(
"proc_macro2",
srctree / "rust" / "proc-macro2" / "lib.rs",
- ["core", "alloc", "std", "proc_macro"],
+ [],
cfg=crates_cfgs["proc_macro2"],
is_proc_macro_library=True,
)
@@ -138,7 +156,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
append_crate(
"quote",
srctree / "rust" / "quote" / "lib.rs",
- ["core", "alloc", "std", "proc_macro", "proc_macro2"],
+ ["proc_macro2"],
cfg=crates_cfgs["quote"],
is_proc_macro_library=True,
)
@@ -146,7 +164,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
append_crate(
"syn",
srctree / "rust" / "syn" / "lib.rs",
- ["std", "proc_macro", "proc_macro2", "quote"],
+ ["proc_macro2", "quote"],
cfg=crates_cfgs["syn"],
is_proc_macro_library=True,
)
@@ -154,20 +172,20 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
append_crate(
"macros",
srctree / "rust" / "macros" / "lib.rs",
- ["std", "proc_macro", "proc_macro2", "quote", "syn"],
+ ["proc_macro2", "quote", "syn"],
is_proc_macro=True,
)
append_crate(
"build_error",
srctree / "rust" / "build_error.rs",
- ["core", "compiler_builtins"],
+ ["compiler_builtins"],
)
append_crate(
"pin_init_internal",
srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs",
- ["std", "proc_macro"],
+ [],
cfg=["kernel"],
is_proc_macro=True,
)
@@ -175,14 +193,14 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
append_crate(
"pin_init",
srctree / "rust" / "pin-init" / "src" / "lib.rs",
- ["core", "compiler_builtins", "pin_init_internal", "macros"],
+ ["pin_init_internal", "macros"],
cfg=["kernel"],
)
append_crate(
"ffi",
srctree / "rust" / "ffi.rs",
- ["core", "compiler_builtins"],
+ ["compiler_builtins"],
)
def append_crate_with_generated(
@@ -204,9 +222,9 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
"exclude_dirs": [],
}
- append_crate_with_generated("bindings", ["core", "ffi", "pin_init"])
- append_crate_with_generated("uapi", ["core", "ffi", "pin_init"])
- append_crate_with_generated("kernel", ["core", "macros", "build_error", "pin_init", "ffi", "bindings", "uapi"])
+ append_crate_with_generated("bindings", ["ffi", "pin_init"])
+ append_crate_with_generated("uapi", ["ffi", "pin_init"])
+ append_crate_with_generated("kernel", ["macros", "build_error", "pin_init", "ffi", "bindings", "uapi"])
def is_root_crate(build_file, target):
try:
@@ -234,7 +252,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
append_crate(
name,
path,
- ["core", "kernel", "pin_init"],
+ ["kernel", "pin_init"],
cfg=generated_cfg,
)
@@ -261,7 +279,11 @@ def main():
common_crate_attrs = args.common_crate_attrs.split() if args.common_crate_attrs else []
rust_project = {
- "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions, args.crate_attrs, common_crate_attrs),
+ "sysroot_src": str(args.sysroot_src),
+ "sysroot_project": {
+ "crates": generate_sysroot_crates(args.cfgs, args.editions, args.crate_attrs),
+ },
+ "crates": generate_crates(args.srctree, args.objtree, args.exttree, args.cfgs, args.editions, args.crate_attrs, common_crate_attrs),
"sysroot": str(args.sysroot),
}
--
2.52.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project
2026-01-20 8:52 ` [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project Eliot Courtney
@ 2026-01-20 15:34 ` Tamir Duberstein
2026-01-21 0:01 ` Jesung Yang
0 siblings, 1 reply; 23+ messages in thread
From: Tamir Duberstein @ 2026-01-20 15:34 UTC (permalink / raw)
To: Eliot Courtney, Jesung Yang
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Tue, Jan 20, 2026 at 3:55 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>
> Use rust-analyzer's sysroot_project feature to properly configure
> sysroot crates (core, alloc, std, proc_macro). This allows
> rust-analyzer to correctly resolve items from the sysroot and
> automatically add sysroot crate dependencies to all project crates.
>
> Some sysroot crates use #[path] directives to load files outside of
> their directory but still in the sysroot. This is disallowed by
> rust-analyzer, so the sysroot crate are not properly loaded. Loading them
> using sysroot_project tells rust-analyzer to let them load anything inside
> sysroot_src.
>
> The sysroot_project field was added to rust-analyzer in v0.3.2328
> (~1.87.0) and is silently ignored by older versions. In that case,
> rust-analyzer falls back to loading the sysroot via sysroot_src.
> This basically works, but the advantage of using sysroot_project is
> that we can make the set of features/cfgs more similar to what the
> actual build uses.
This is a very nice patch, and perhaps obviates the need for the
versioning infrastructure in
https://lore.kernel.org/all/20260109-ra-fix-primitive-v2-0-249852a4145a@gmail.com/.
As with the other commits in this series, we need citations of the
claims that these newer fields are properly ignored by older versions
of RA.
>
> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
> ---
> scripts/generate_rust_analyzer.py | 118 ++++++++++++++++++++++----------------
> 1 file changed, 70 insertions(+), 48 deletions(-)
>
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index ba2f6b0fb99b..f8666050a997 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -27,25 +27,14 @@ def args_crates_cfgs(cfgs):
>
> return crates_cfgs
>
> -def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions, crate_attrs, common_crate_attrs):
> - # Generate the configuration list.
> - generated_cfg = []
> - with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
> - for line in fd:
> - line = line.replace("--cfg=", "")
> - line = line.replace("\n", "")
> - generated_cfg.append(line)
> -
> - # Now fill the crates list -- dependencies need to come first.
> - #
> - # Avoid O(n^2) iterations by keeping a map of indexes.
> +def generate_sysroot_crates(cfgs, editions, crate_attrs):
> crates = []
> crates_indexes = {}
> crates_cfgs = args_crates_cfgs(cfgs)
> crates_editions = args_single(editions)
> crates_crate_attrs = args_crates_cfgs(crate_attrs)
>
> - def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, is_proc_macro_library=False):
> + def append_sysroot_crate(display_name, deps):
> # Miguel Ojeda writes:
> #
> # > ... in principle even the sysroot crates may have different
> @@ -72,6 +61,52 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> # assumption if future edition moves span multiple rust versions.
> edition = crates_editions.get(display_name, "2021")
>
> + cfg = crates_cfgs.get(display_name, [])
> + crates_indexes[display_name] = len(crates)
> + crates.append({
> + "display_name": display_name,
> + # Paths in sysroot_project are relative to sysroot_src.
> + "root_module": f"{display_name}/src/lib.rs",
> + "is_workspace_member": False,
> + "is_proc_macro": False,
> + "deps": [{"crate": crates_indexes[dep], "name": dep} for dep in deps],
> + "cfg": cfg,
> + "edition": edition,
> + # Crate attributes were introduced in 1.94.0 but older versions will silently ignore this.
> + "crate_attrs": crates_crate_attrs.get(display_name, []),
> + "env": {
> + "RUST_MODFILE": "This is only for rust-analyzer"
> + }
> + })
> +
> + append_sysroot_crate("core", [])
> + append_sysroot_crate("alloc", ["core"])
> + append_sysroot_crate("std", ["alloc", "core"])
> + append_sysroot_crate("proc_macro", ["core", "std"])
> +
> + return crates
> +
> +def generate_crates(srctree, objtree, external_src, cfgs, editions, crate_attrs, common_crate_attrs):
> + # Generate the configuration list.
> + generated_cfg = []
> + with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
> + for line in fd:
> + line = line.replace("--cfg=", "")
> + line = line.replace("\n", "")
> + generated_cfg.append(line)
> +
> + # Now fill the crates list -- dependencies need to come first.
> + #
> + # Avoid O(n^2) iterations by keeping a map of indexes.
> + crates = []
> + crates_indexes = {}
> + crates_cfgs = args_crates_cfgs(cfgs)
> + crates_editions = args_single(editions)
> + crates_crate_attrs = args_crates_cfgs(crate_attrs)
> +
> + def append_crate(display_name, root_module, deps, cfg=[], is_proc_macro=False, is_proc_macro_library=False):
> + edition = crates_editions.get(display_name, "2021")
> +
> crate_attrs = crates_crate_attrs.get(display_name, [])
> # Apply common crate attrs to non-host crates.
> if not is_proc_macro_library and not is_proc_macro:
> @@ -80,7 +115,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> crate = {
> "display_name": display_name,
> "root_module": str(root_module),
> - "is_workspace_member": is_workspace_member,
> + "is_workspace_member": True,
> "is_proc_macro": is_proc_macro,
> "deps": [{"crate": crates_indexes[dep], "name": dep} for dep in deps],
> "cfg": cfg,
> @@ -100,37 +135,20 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> crates_indexes[display_name] = len(crates)
> crates.append(crate)
>
> - def append_sysroot_crate(
> - display_name,
> - deps,
> - cfg=[],
> - ):
> - append_crate(
> - display_name,
> - sysroot_src / display_name / "src" / "lib.rs",
> - deps,
> - cfg,
> - is_workspace_member=False,
> - )
> -
> - # NB: sysroot crates reexport items from one another so setting up our transitive dependencies
> - # here is important for ensuring that rust-analyzer can resolve symbols. The sources of truth
> - # for this dependency graph are `(sysroot_src / crate / "Cargo.toml" for crate in crates)`.
> - append_sysroot_crate("core", [], cfg=crates_cfgs.get("core", []))
> - append_sysroot_crate("alloc", ["core"])
> - append_sysroot_crate("std", ["alloc", "core"])
> - append_sysroot_crate("proc_macro", ["core", "std"])
> + # Sysroot crates (core, alloc, std, proc_macro) are in sysroot_project,
> + # and their deps are automatically added to all crates by rust-analyzer.
> + # We only need to define deps between our own crates here.
>
> append_crate(
> "compiler_builtins",
> srctree / "rust" / "compiler_builtins.rs",
> - ["core"],
> + [],
> )
>
> append_crate(
> "proc_macro2",
> srctree / "rust" / "proc-macro2" / "lib.rs",
> - ["core", "alloc", "std", "proc_macro"],
> + [],
> cfg=crates_cfgs["proc_macro2"],
> is_proc_macro_library=True,
> )
> @@ -138,7 +156,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> append_crate(
> "quote",
> srctree / "rust" / "quote" / "lib.rs",
> - ["core", "alloc", "std", "proc_macro", "proc_macro2"],
> + ["proc_macro2"],
> cfg=crates_cfgs["quote"],
> is_proc_macro_library=True,
> )
> @@ -146,7 +164,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> append_crate(
> "syn",
> srctree / "rust" / "syn" / "lib.rs",
> - ["std", "proc_macro", "proc_macro2", "quote"],
> + ["proc_macro2", "quote"],
> cfg=crates_cfgs["syn"],
> is_proc_macro_library=True,
> )
> @@ -154,20 +172,20 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> append_crate(
> "macros",
> srctree / "rust" / "macros" / "lib.rs",
> - ["std", "proc_macro", "proc_macro2", "quote", "syn"],
> + ["proc_macro2", "quote", "syn"],
> is_proc_macro=True,
> )
>
> append_crate(
> "build_error",
> srctree / "rust" / "build_error.rs",
> - ["core", "compiler_builtins"],
> + ["compiler_builtins"],
> )
>
> append_crate(
> "pin_init_internal",
> srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs",
> - ["std", "proc_macro"],
> + [],
> cfg=["kernel"],
> is_proc_macro=True,
> )
> @@ -175,14 +193,14 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> append_crate(
> "pin_init",
> srctree / "rust" / "pin-init" / "src" / "lib.rs",
> - ["core", "compiler_builtins", "pin_init_internal", "macros"],
> + ["pin_init_internal", "macros"],
> cfg=["kernel"],
> )
>
> append_crate(
> "ffi",
> srctree / "rust" / "ffi.rs",
> - ["core", "compiler_builtins"],
> + ["compiler_builtins"],
> )
>
> def append_crate_with_generated(
> @@ -204,9 +222,9 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> "exclude_dirs": [],
> }
>
> - append_crate_with_generated("bindings", ["core", "ffi", "pin_init"])
> - append_crate_with_generated("uapi", ["core", "ffi", "pin_init"])
> - append_crate_with_generated("kernel", ["core", "macros", "build_error", "pin_init", "ffi", "bindings", "uapi"])
> + append_crate_with_generated("bindings", ["ffi", "pin_init"])
> + append_crate_with_generated("uapi", ["ffi", "pin_init"])
> + append_crate_with_generated("kernel", ["macros", "build_error", "pin_init", "ffi", "bindings", "uapi"])
>
> def is_root_crate(build_file, target):
> try:
> @@ -234,7 +252,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions,
> append_crate(
> name,
> path,
> - ["core", "kernel", "pin_init"],
> + ["kernel", "pin_init"],
> cfg=generated_cfg,
> )
>
> @@ -261,7 +279,11 @@ def main():
>
> common_crate_attrs = args.common_crate_attrs.split() if args.common_crate_attrs else []
> rust_project = {
> - "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions, args.crate_attrs, common_crate_attrs),
> + "sysroot_src": str(args.sysroot_src),
> + "sysroot_project": {
> + "crates": generate_sysroot_crates(args.cfgs, args.editions, args.crate_attrs),
> + },
> + "crates": generate_crates(args.srctree, args.objtree, args.exttree, args.cfgs, args.editions, args.crate_attrs, common_crate_attrs),
> "sysroot": str(args.sysroot),
> }
>
>
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 23+ messages in thread* Re: [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project
2026-01-20 15:34 ` Tamir Duberstein
@ 2026-01-21 0:01 ` Jesung Yang
2026-01-22 9:23 ` Eliot Courtney
0 siblings, 1 reply; 23+ messages in thread
From: Jesung Yang @ 2026-01-21 0:01 UTC (permalink / raw)
To: Tamir Duberstein, Eliot Courtney, Jesung Yang
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Wed Jan 21, 2026 at 12:34 AM KST, Tamir Duberstein wrote:
> On Tue, Jan 20, 2026 at 3:55 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>>
>> Use rust-analyzer's sysroot_project feature to properly configure
>> sysroot crates (core, alloc, std, proc_macro). This allows
>> rust-analyzer to correctly resolve items from the sysroot and
>> automatically add sysroot crate dependencies to all project crates.
>>
>> Some sysroot crates use #[path] directives to load files outside of
>> their directory but still in the sysroot. This is disallowed by
>> rust-analyzer, so the sysroot crate are not properly loaded. Loading them
>> using sysroot_project tells rust-analyzer to let them load anything inside
>> sysroot_src.
>>
>> The sysroot_project field was added to rust-analyzer in v0.3.2328
>> (~1.87.0) and is silently ignored by older versions. In that case,
>> rust-analyzer falls back to loading the sysroot via sysroot_src.
>> This basically works, but the advantage of using sysroot_project is
>> that we can make the set of features/cfgs more similar to what the
>> actual build uses.
>
> This is a very nice patch, and perhaps obviates the need for the
> versioning infrastructure in
> https://lore.kernel.org/all/20260109-ra-fix-primitive-v2-0-249852a4145a@gmail.com/.
I still think the versioning infrastructure is a prerequisite as we're
using the `sysroot_src` field here.
If we specify `sysroot_src` without `crate_attrs = ["no_std"]`,
rust-analyzer treats `std` as a dependency for all local crates by
default. Consequently, any rust-analyzer version lacking `crate_attrs`
support (which silently ignores `crate_attrs = ["no_std"]`) would
incorrectly assume an implicit `std` dependency for all kernel modules.
Having the versioning infrastructure first allows us to handle this
transition without breaking the user experience for those on older
toolchains.
Best regards,
Jesung
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project
2026-01-21 0:01 ` Jesung Yang
@ 2026-01-22 9:23 ` Eliot Courtney
2026-01-22 11:06 ` Jesung Yang
0 siblings, 1 reply; 23+ messages in thread
From: Eliot Courtney @ 2026-01-22 9:23 UTC (permalink / raw)
To: Jesung Yang, Tamir Duberstein, Eliot Courtney
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Wed Jan 21, 2026 at 9:01 AM JST, Jesung Yang wrote:
> I still think the versioning infrastructure is a prerequisite as we're
> using the `sysroot_src` field here.
>
> If we specify `sysroot_src` without `crate_attrs = ["no_std"]`,
> rust-analyzer treats `std` as a dependency for all local crates by
> default. Consequently, any rust-analyzer version lacking `crate_attrs`
> support (which silently ignores `crate_attrs = ["no_std"]`) would
> incorrectly assume an implicit `std` dependency for all kernel modules.
> Having the versioning infrastructure first allows us to handle this
> transition without breaking the user experience for those on older
> toolchains.
Yeah, I agree that specifying sysroot_src by itself includes std and that
is potentially an issue.
But, currently due to issues like the relative #[path] include, the
sysroot crates aren't really processable very well by rust-analyzer
causing a lot of spurious errors and unresolved symbols, which make
using the LSP experience pretty bad IMO. OTOH, while the sysroot_src
approach does include std, it at least makes it usable. Personally I
find it more useful this way, but I can see the argument for both sides.
Tangential, but I'm not sure why the drivers don't specify no_std
themselves - then we wouldn't have to worry about this IIUC.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project
2026-01-22 9:23 ` Eliot Courtney
@ 2026-01-22 11:06 ` Jesung Yang
2026-01-23 5:45 ` Eliot Courtney
0 siblings, 1 reply; 23+ messages in thread
From: Jesung Yang @ 2026-01-22 11:06 UTC (permalink / raw)
To: Eliot Courtney, Jesung Yang, Tamir Duberstein
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Thu Jan 22, 2026 at 6:23 PM KST, Eliot Courtney wrote:
> On Wed Jan 21, 2026 at 9:01 AM JST, Jesung Yang wrote:
>> I still think the versioning infrastructure is a prerequisite as we're
>> using the `sysroot_src` field here.
>>
>> If we specify `sysroot_src` without `crate_attrs = ["no_std"]`,
>> rust-analyzer treats `std` as a dependency for all local crates by
>> default. Consequently, any rust-analyzer version lacking `crate_attrs`
>> support (which silently ignores `crate_attrs = ["no_std"]`) would
>> incorrectly assume an implicit `std` dependency for all kernel modules.
>> Having the versioning infrastructure first allows us to handle this
>> transition without breaking the user experience for those on older
>> toolchains.
> Yeah, I agree that specifying sysroot_src by itself includes std and that
> is potentially an issue.
>
> But, currently due to issues like the relative #[path] include, the
> sysroot crates aren't really processable very well by rust-analyzer
> causing a lot of spurious errors and unresolved symbols, which make
> using the LSP experience pretty bad IMO. OTOH, while the sysroot_src
> approach does include std, it at least makes it usable. Personally I
> find it more useful this way, but I can see the argument for both sides.
So the problem here is that the versioning infrastructure effectively
restricts the use of `sysroot_src` for older rust-analyzer versions
that do not support `crate_attrs`, which leads to yet another bad
experience. Hmm... I would like to hear others' thoughts on this
trade-off, since I don't have a perfect solution at the moment.
> Tangential, but I'm not sure why the drivers don't specify no_std
> themselves - then we wouldn't have to worry about this IIUC.
Perhaps Miguel could chime in and give some details about this, but
you can find a bit of context here [1].
On a separate note: I actually have a previous effort covering
`sysroot_src` and `crate_attrs` [2] that I'd like to land first. It
covers almost the same ground as your 6th patch (minus the
`sysroot_project` use). Since I wrote the `crate-attrs` code in
rust-analyzer itself specifically to improve its usability in the
kernel, I'm hoping to finish the full story on the kernel side. Would
you be open to that?
Thanks!
[1] https://rust-for-linux.zulipchat.com/#narrow/channel/x/topic/x/near/561668361
[2] https://lore.kernel.org/rust-for-linux/20260101-ra-fix-primitive-v1-1-def809357b4e@gmail.com/
Best regards,
Jesung
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project
2026-01-22 11:06 ` Jesung Yang
@ 2026-01-23 5:45 ` Eliot Courtney
2026-01-23 12:08 ` Miguel Ojeda
0 siblings, 1 reply; 23+ messages in thread
From: Eliot Courtney @ 2026-01-23 5:45 UTC (permalink / raw)
To: Jesung Yang, Eliot Courtney, Tamir Duberstein
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Thu Jan 22, 2026 at 8:06 PM JST, Jesung Yang wrote:
> On Thu Jan 22, 2026 at 6:23 PM KST, Eliot Courtney wrote:
>> On Wed Jan 21, 2026 at 9:01 AM JST, Jesung Yang wrote:
>>> I still think the versioning infrastructure is a prerequisite as we're
>>> using the `sysroot_src` field here.
>>>
>>> If we specify `sysroot_src` without `crate_attrs = ["no_std"]`,
>>> rust-analyzer treats `std` as a dependency for all local crates by
>>> default. Consequently, any rust-analyzer version lacking `crate_attrs`
>>> support (which silently ignores `crate_attrs = ["no_std"]`) would
>>> incorrectly assume an implicit `std` dependency for all kernel modules.
>>> Having the versioning infrastructure first allows us to handle this
>>> transition without breaking the user experience for those on older
>>> toolchains.
>> Yeah, I agree that specifying sysroot_src by itself includes std and that
>> is potentially an issue.
>>
>> But, currently due to issues like the relative #[path] include, the
>> sysroot crates aren't really processable very well by rust-analyzer
>> causing a lot of spurious errors and unresolved symbols, which make
>> using the LSP experience pretty bad IMO. OTOH, while the sysroot_src
>> approach does include std, it at least makes it usable. Personally I
>> find it more useful this way, but I can see the argument for both sides.
>
> So the problem here is that the versioning infrastructure effectively
> restricts the use of `sysroot_src` for older rust-analyzer versions
> that do not support `crate_attrs`, which leads to yet another bad
> experience. Hmm... I would like to hear others' thoughts on this
> trade-off, since I don't have a perfect solution at the moment.
I think it's possible to get it to work (at least better - not sure if
it fully fixes all issues) in RA 1.78.0 without specifying sysroot_src
if we add include_dirs to allow the relative #[path] references to be
resolved.
> On a separate note: I actually have a previous effort covering
> `sysroot_src` and `crate_attrs` [2] that I'd like to land first. It
> covers almost the same ground as your 6th patch (minus the
> `sysroot_project` use). Since I wrote the `crate-attrs` code in
> rust-analyzer itself specifically to improve its usability in the
> kernel, I'm hoping to finish the full story on the kernel side. Would
> you be open to that?
Yes, of course, please feel free to land whatever you want. I'm sorry I
didn't notice this, I think I only searched for rust[-_]analyzer in the
subject line when I was checking the existing state. I'm still working
out my workflow and how to avoid missing things like this, so I
appreciate your patience. If there's anything useful from my patch
series I can send a v2 if you would like, or I can rebase it on top of
some other patch series, or not.
Thanks~
>
> Thanks!
>
> [1] https://rust-for-linux.zulipchat.com/#narrow/channel/x/topic/x/near/561668361
> [2] https://lore.kernel.org/rust-for-linux/20260101-ra-fix-primitive-v1-1-def809357b4e@gmail.com/
>
> Best regards,
> Jesung
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project
2026-01-23 5:45 ` Eliot Courtney
@ 2026-01-23 12:08 ` Miguel Ojeda
2026-01-23 12:23 ` Gary Guo
0 siblings, 1 reply; 23+ messages in thread
From: Miguel Ojeda @ 2026-01-23 12:08 UTC (permalink / raw)
To: Eliot Courtney
Cc: Jesung Yang, Tamir Duberstein, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Fri, Jan 23, 2026 at 6:45 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>
> I think it's possible to get it to work (at least better - not sure if
> it fully fixes all issues) in RA 1.78.0 without specifying sysroot_src
> if we add include_dirs to allow the relative #[path] references to be
> resolved.
Generally speaking, if a version of rust-analyzer is complex to
support , then it may be best to consider avoid supporting it.
It is an optional development tool and many/most use the latest
version and/or the distro-provided one. Plus we will be moving to the
new minimum soon, and so far we didn't support multi-version for the
tool anyway.
So, in general, if it is something trivial to support, then why not.
Otherwise, I would recommend focusing the support on Rust 1.85 and
later (especially the latest plus versions in popular distributions).
And if a good test can be done in CI for the new multi-version support
etc., then it may make sense to test nightly and things like that too,
and even ask upstream if they would like to add the test in their CI,
like we do for the compiler and bindgen.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project
2026-01-23 12:08 ` Miguel Ojeda
@ 2026-01-23 12:23 ` Gary Guo
2026-01-23 12:31 ` Miguel Ojeda
0 siblings, 1 reply; 23+ messages in thread
From: Gary Guo @ 2026-01-23 12:23 UTC (permalink / raw)
To: Miguel Ojeda, Eliot Courtney
Cc: Jesung Yang, Tamir Duberstein, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Fri Jan 23, 2026 at 12:08 PM GMT, Miguel Ojeda wrote:
> On Fri, Jan 23, 2026 at 6:45 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>>
>> I think it's possible to get it to work (at least better - not sure if
>> it fully fixes all issues) in RA 1.78.0 without specifying sysroot_src
>> if we add include_dirs to allow the relative #[path] references to be
>> resolved.
>
> Generally speaking, if a version of rust-analyzer is complex to
> support , then it may be best to consider avoid supporting it.
>
> It is an optional development tool and many/most use the latest
> version and/or the distro-provided one. Plus we will be moving to the
> new minimum soon, and so far we didn't support multi-version for the
> tool anyway.
>
> So, in general, if it is something trivial to support, then why not.
> Otherwise, I would recommend focusing the support on Rust 1.85 and
> later (especially the latest plus versions in popular distributions).
I would still prefer we support the RA that comes with the minimum version of
Rust. I don't care about intermediate version between minimum and popular
versions, but I pin my toolchain to 1.78.
AFAIK there's no way for rustup to use a new rust-analyzer with a old toolchain.
One can certainly download rust-analyzer from other means, but rust-analyzer
does not recommend use against old rustc, anyway.
I would avoid dropping old RA support before we actually bump MSRV.
Best,
Gary
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project
2026-01-23 12:23 ` Gary Guo
@ 2026-01-23 12:31 ` Miguel Ojeda
0 siblings, 0 replies; 23+ messages in thread
From: Miguel Ojeda @ 2026-01-23 12:31 UTC (permalink / raw)
To: Gary Guo
Cc: Eliot Courtney, Jesung Yang, Tamir Duberstein, Miguel Ojeda,
Boqun Feng, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Nathan Chancellor,
Nicolas Schier, rust-for-linux, linux-kernel, linux-kbuild
On Fri, Jan 23, 2026 at 1:23 PM Gary Guo <gary@garyguo.net> wrote:
>
> I would avoid dropping old RA support before we actually bump MSRV.
There is no intentional support for old rust-analyzer at the moment.
i.e. if it works, it is because it still happens to work with the
current output.
That is why I mentioned that -- but if it actually works well today
with the current output, then sure, let's not break it.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation
2026-01-20 8:52 [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Eliot Courtney
` (5 preceding siblings ...)
2026-01-20 8:52 ` [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project Eliot Courtney
@ 2026-01-20 13:38 ` Miguel Ojeda
6 siblings, 0 replies; 23+ messages in thread
From: Miguel Ojeda @ 2026-01-20 13:38 UTC (permalink / raw)
To: Eliot Courtney, Tamir Duberstein, Jesung Yang
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier,
rust-for-linux, linux-kernel, linux-kbuild
On Tue, Jan 20, 2026 at 9:54 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>
> This series improves rust-analyzer rust-project.json generation by:
Cc'ing Tamir and Jesung, who are becoming maintainer and reviewer of
the rust-analyzer support:
https://lore.kernel.org/rust-for-linux/20260115214545.63262-1-ojeda@kernel.org/
> There is some overlap between this patch series and ones already sent
> but not applied, but it's unclear to me what the status of those are.
There is overlap, yeah. The multi-version support (which I could
imagine they may possibly want to land first before tackling other
things) is fairly clearly on the "being discussed/reviewed" side since
it was sent some days ago:
https://lore.kernel.org/rust-for-linux/20260109-ra-fix-primitive-v2-0-249852a4145a@gmail.com/
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 23+ messages in thread