Centralize `cfg` lookup in `append_crate` to avoid having to do so for
each crate. Remove hardcoded `cfg`s for `pin-init{,-internal}` now that
these are passed from `rust/Makefile`.
Signed-off-by: Tamir Duberstein <tamird@kernel.org>
---
scripts/generate_rust_analyzer.py | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 147d0cc94068..b96d3cbe3df1 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -35,7 +35,9 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
crates_indexes = {}
crates_cfgs = args_crates_cfgs(cfgs)
- def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
+ def append_crate(display_name, root_module, deps, cfg=None, is_workspace_member=True, is_proc_macro=False, edition="2021"):
+ if cfg is None:
+ cfg = crates_cfgs.get(display_name, [])
crate = {
"display_name": display_name,
"root_module": str(root_module),
@@ -60,7 +62,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
def append_sysroot_crate(
display_name,
deps,
- cfg=[],
+ cfg=None,
edition="2021",
):
append_crate(
@@ -75,7 +77,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
# 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", []), edition=core_edition)
+ append_sysroot_crate("core", [], edition=core_edition)
append_sysroot_crate("alloc", ["core"])
append_sysroot_crate("std", ["alloc", "core"])
append_sysroot_crate("proc_macro", ["core", "std"])
@@ -90,21 +92,18 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
"proc_macro2",
srctree / "rust" / "proc-macro2" / "lib.rs",
["core", "alloc", "std", "proc_macro"],
- cfg=crates_cfgs["proc_macro2"],
)
append_crate(
"quote",
srctree / "rust" / "quote" / "lib.rs",
["alloc", "proc_macro", "proc_macro2"],
- cfg=crates_cfgs["quote"],
)
append_crate(
"syn",
srctree / "rust" / "syn" / "lib.rs",
["proc_macro", "proc_macro2", "quote"],
- cfg=crates_cfgs["syn"],
)
append_crate(
@@ -124,7 +123,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
"pin_init_internal",
srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs",
[],
- cfg=["kernel"],
is_proc_macro=True,
)
@@ -132,7 +130,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
"pin_init",
srctree / "rust" / "pin-init" / "src" / "lib.rs",
["core", "pin_init_internal", "macros"],
- cfg=["kernel"],
)
append_crate(
--
2.52.0
On Wed Jan 21, 2026 at 1:10 AM KST, Tamir Duberstein wrote:
> Centralize `cfg` lookup in `append_crate` to avoid having to do so for
> each crate. Remove hardcoded `cfg`s for `pin-init{,-internal}` now that
> these are passed from `rust/Makefile`.
>
> Signed-off-by: Tamir Duberstein <tamird@kernel.org>
> ---
> scripts/generate_rust_analyzer.py | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index 147d0cc94068..b96d3cbe3df1 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -35,7 +35,9 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> crates_indexes = {}
> crates_cfgs = args_crates_cfgs(cfgs)
>
> - def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
> + def append_crate(display_name, root_module, deps, cfg=None, is_workspace_member=True, is_proc_macro=False, edition="2021"):
> + if cfg is None:
> + cfg = crates_cfgs.get(display_name, [])
Could we add a brief comment explaining how the behavior of
`append_crate` changes according to the `cfg` parameter? Since `None`
and an empty list have different effects, documenting that distinction
would make the intended behavior clearer.
This would also help later when we add proper Python docstrings.
Thanks!
Best regards,
Jesung
> crate = {
> "display_name": display_name,
> "root_module": str(root_module),
> @@ -60,7 +62,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> def append_sysroot_crate(
> display_name,
> deps,
> - cfg=[],
> + cfg=None,
> edition="2021",
> ):
> append_crate(
> @@ -75,7 +77,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> # 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", []), edition=core_edition)
> + append_sysroot_crate("core", [], edition=core_edition)
> append_sysroot_crate("alloc", ["core"])
> append_sysroot_crate("std", ["alloc", "core"])
> append_sysroot_crate("proc_macro", ["core", "std"])
> @@ -90,21 +92,18 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> "proc_macro2",
> srctree / "rust" / "proc-macro2" / "lib.rs",
> ["core", "alloc", "std", "proc_macro"],
> - cfg=crates_cfgs["proc_macro2"],
> )
>
> append_crate(
> "quote",
> srctree / "rust" / "quote" / "lib.rs",
> ["alloc", "proc_macro", "proc_macro2"],
> - cfg=crates_cfgs["quote"],
> )
>
> append_crate(
> "syn",
> srctree / "rust" / "syn" / "lib.rs",
> ["proc_macro", "proc_macro2", "quote"],
> - cfg=crates_cfgs["syn"],
> )
>
> append_crate(
> @@ -124,7 +123,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> "pin_init_internal",
> srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs",
> [],
> - cfg=["kernel"],
> is_proc_macro=True,
> )
>
> @@ -132,7 +130,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> "pin_init",
> srctree / "rust" / "pin-init" / "src" / "lib.rs",
> ["core", "pin_init_internal", "macros"],
> - cfg=["kernel"],
> )
>
> append_crate(
On Tue, Jan 20, 2026 at 8:16 PM Jesung Yang <y.j3ms.n@gmail.com> wrote:
>
> On Wed Jan 21, 2026 at 1:10 AM KST, Tamir Duberstein wrote:
> > Centralize `cfg` lookup in `append_crate` to avoid having to do so for
> > each crate. Remove hardcoded `cfg`s for `pin-init{,-internal}` now that
> > these are passed from `rust/Makefile`.
> >
> > Signed-off-by: Tamir Duberstein <tamird@kernel.org>
> > ---
> > scripts/generate_rust_analyzer.py | 13 +++++--------
> > 1 file changed, 5 insertions(+), 8 deletions(-)
> >
> > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> > index 147d0cc94068..b96d3cbe3df1 100755
> > --- a/scripts/generate_rust_analyzer.py
> > +++ b/scripts/generate_rust_analyzer.py
> > @@ -35,7 +35,9 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> > crates_indexes = {}
> > crates_cfgs = args_crates_cfgs(cfgs)
> >
> > - def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
> > + def append_crate(display_name, root_module, deps, cfg=None, is_workspace_member=True, is_proc_macro=False, edition="2021"):
> > + if cfg is None:
> > + cfg = crates_cfgs.get(display_name, [])
>
> Could we add a brief comment explaining how the behavior of
> `append_crate` changes according to the `cfg` parameter? Since `None`
> and an empty list have different effects, documenting that distinction
> would make the intended behavior clearer.
I don't think this is necessary - it won't age well when we change the
entire API surface here in the next version of the series[0] that adds
type annotations.
Link: https://lore.kernel.org/all/20250424-rust-analyzer-host-v6-0-40e67fe5c38a@gmail.com/
[0]
> This would also help later when we add proper Python docstrings.
Same as above: a lot of change is coming. Is this worth considering right now?
>
> Thanks!
>
> Best regards,
> Jesung
>
> > crate = {
> > "display_name": display_name,
> > "root_module": str(root_module),
> > @@ -60,7 +62,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> > def append_sysroot_crate(
> > display_name,
> > deps,
> > - cfg=[],
> > + cfg=None,
> > edition="2021",
> > ):
> > append_crate(
> > @@ -75,7 +77,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> > # 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", []), edition=core_edition)
> > + append_sysroot_crate("core", [], edition=core_edition)
> > append_sysroot_crate("alloc", ["core"])
> > append_sysroot_crate("std", ["alloc", "core"])
> > append_sysroot_crate("proc_macro", ["core", "std"])
> > @@ -90,21 +92,18 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> > "proc_macro2",
> > srctree / "rust" / "proc-macro2" / "lib.rs",
> > ["core", "alloc", "std", "proc_macro"],
> > - cfg=crates_cfgs["proc_macro2"],
> > )
> >
> > append_crate(
> > "quote",
> > srctree / "rust" / "quote" / "lib.rs",
> > ["alloc", "proc_macro", "proc_macro2"],
> > - cfg=crates_cfgs["quote"],
> > )
> >
> > append_crate(
> > "syn",
> > srctree / "rust" / "syn" / "lib.rs",
> > ["proc_macro", "proc_macro2", "quote"],
> > - cfg=crates_cfgs["syn"],
> > )
> >
> > append_crate(
> > @@ -124,7 +123,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> > "pin_init_internal",
> > srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs",
> > [],
> > - cfg=["kernel"],
> > is_proc_macro=True,
> > )
> >
> > @@ -132,7 +130,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> > "pin_init",
> > srctree / "rust" / "pin-init" / "src" / "lib.rs",
> > ["core", "pin_init_internal", "macros"],
> > - cfg=["kernel"],
> > )
> >
> > append_crate(
>
On Wed Jan 21, 2026 at 11:13 PM KST, Tamir Duberstein wrote:
> On Tue, Jan 20, 2026 at 8:16 PM Jesung Yang <y.j3ms.n@gmail.com> wrote:
>> On Wed Jan 21, 2026 at 1:10 AM KST, Tamir Duberstein wrote:
>> > Centralize `cfg` lookup in `append_crate` to avoid having to do so for
>> > each crate. Remove hardcoded `cfg`s for `pin-init{,-internal}` now that
>> > these are passed from `rust/Makefile`.
>> >
>> > Signed-off-by: Tamir Duberstein <tamird@kernel.org>
>> > ---
>> > scripts/generate_rust_analyzer.py | 13 +++++--------
>> > 1 file changed, 5 insertions(+), 8 deletions(-)
>> >
>> > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
>> > index 147d0cc94068..b96d3cbe3df1 100755
>> > --- a/scripts/generate_rust_analyzer.py
>> > +++ b/scripts/generate_rust_analyzer.py
>> > @@ -35,7 +35,9 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
>> > crates_indexes = {}
>> > crates_cfgs = args_crates_cfgs(cfgs)
>> >
>> > - def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
>> > + def append_crate(display_name, root_module, deps, cfg=None, is_workspace_member=True, is_proc_macro=False, edition="2021"):
>> > + if cfg is None:
>> > + cfg = crates_cfgs.get(display_name, [])
>>
>> Could we add a brief comment explaining how the behavior of
>> `append_crate` changes according to the `cfg` parameter? Since `None`
>> and an empty list have different effects, documenting that distinction
>> would make the intended behavior clearer.
>
> I don't think this is necessary - it won't age well when we change the
> entire API surface here in the next version of the series[0] that adds
> type annotations.
>
> Link: https://lore.kernel.org/all/20250424-rust-analyzer-host-v6-0-40e67fe5c38a@gmail.com/
> [0]
>
>> This would also help later when we add proper Python docstrings.
>
> Same as above: a lot of change is coming. Is this worth considering right now?
Fair point, thanks for the context.
Reviewed-by: Jesung Yang <y.j3ms.n@gmail.com>
By the way, could you share your plan for upcoming major changes? It
would help me prepare and align my series if I know the intended
direction. I currently have these on my radar:
[1] https://lore.kernel.org/all/20250424-rust-analyzer-host-v6-0-40e67fe5c38a@gmail.com/
[2] https://lore.kernel.org/rust-for-linux/20260109-ra-fix-primitive-v2-0-249852a4145a@gmail.com/
[3] https://lore.kernel.org/rust-for-linux/20260120-ra-fix-v1-0-829e4e92818c@nvidia.com/
I assume you would prefer merging [1] first? Please let me know if I'm
missing something.
Thanks!
Best regards,
Jesung
On Wed, Jan 21, 2026 at 6:12 PM Jesung Yang <y.j3ms.n@gmail.com> wrote:
>
> On Wed Jan 21, 2026 at 11:13 PM KST, Tamir Duberstein wrote:
> > On Tue, Jan 20, 2026 at 8:16 PM Jesung Yang <y.j3ms.n@gmail.com> wrote:
> >> On Wed Jan 21, 2026 at 1:10 AM KST, Tamir Duberstein wrote:
> >> > Centralize `cfg` lookup in `append_crate` to avoid having to do so for
> >> > each crate. Remove hardcoded `cfg`s for `pin-init{,-internal}` now that
> >> > these are passed from `rust/Makefile`.
> >> >
> >> > Signed-off-by: Tamir Duberstein <tamird@kernel.org>
> >> > ---
> >> > scripts/generate_rust_analyzer.py | 13 +++++--------
> >> > 1 file changed, 5 insertions(+), 8 deletions(-)
> >> >
> >> > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> >> > index 147d0cc94068..b96d3cbe3df1 100755
> >> > --- a/scripts/generate_rust_analyzer.py
> >> > +++ b/scripts/generate_rust_analyzer.py
> >> > @@ -35,7 +35,9 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> >> > crates_indexes = {}
> >> > crates_cfgs = args_crates_cfgs(cfgs)
> >> >
> >> > - def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
> >> > + def append_crate(display_name, root_module, deps, cfg=None, is_workspace_member=True, is_proc_macro=False, edition="2021"):
> >> > + if cfg is None:
> >> > + cfg = crates_cfgs.get(display_name, [])
> >>
> >> Could we add a brief comment explaining how the behavior of
> >> `append_crate` changes according to the `cfg` parameter? Since `None`
> >> and an empty list have different effects, documenting that distinction
> >> would make the intended behavior clearer.
> >
> > I don't think this is necessary - it won't age well when we change the
> > entire API surface here in the next version of the series[0] that adds
> > type annotations.
> >
> > Link: https://lore.kernel.org/all/20250424-rust-analyzer-host-v6-0-40e67fe5c38a@gmail.com/
> > [0]
> >
> >> This would also help later when we add proper Python docstrings.
> >
> > Same as above: a lot of change is coming. Is this worth considering right now?
>
> Fair point, thanks for the context.
>
> Reviewed-by: Jesung Yang <y.j3ms.n@gmail.com>
>
> By the way, could you share your plan for upcoming major changes? It
> would help me prepare and align my series if I know the intended
> direction. I currently have these on my radar:
>
> [1] https://lore.kernel.org/all/20250424-rust-analyzer-host-v6-0-40e67fe5c38a@gmail.com/
> [2] https://lore.kernel.org/rust-for-linux/20260109-ra-fix-primitive-v2-0-249852a4145a@gmail.com/
> [3] https://lore.kernel.org/rust-for-linux/20260120-ra-fix-v1-0-829e4e92818c@nvidia.com/
>
> I assume you would prefer merging [1] first? Please let me know if I'm
> missing something.
Yeah, these are the big changes I'm currently aware of. I'm going to
look for ways to split [1] into smaller parts. The main thing I'd like
to get in ASAP is type annotations as maintenance becomes much easier
following that.
>
> Thanks!
>
> Best regards,
> Jesung
© 2016 - 2026 Red Hat, Inc.