public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] rust: reduce duplicate information
@ 2026-01-20 16:10 Tamir Duberstein
  2026-01-20 16:10 ` [PATCH v2 1/2] rust: kbuild: extract configs for reuse Tamir Duberstein
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Tamir Duberstein @ 2026-01-20 16:10 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Jesung Yang
  Cc: rust-for-linux, linux-kernel, Nathan Chancellor, Nicolas Schier,
	Linux Kbuild mailing list, Tamir Duberstein

This series reuses `rust/Makefile`'s knowledge of `pin_init` and
`pin_init_internal`'s `cfg`s in `scripts/generate_rust_analzyer.py` and
reduces the ceremony needed to use that knowledge in the script.

Signed-off-by: Tamir Duberstein <tamird@kernel.org>
---
Changes in v2:
- Split into two patches. (Miguel Ojeda)
- CC kbuild. (Miguel Ojeda)
- Link to v1: https://patch.msgid.link/20260116-rust-analyzer-pin-init-duplication-v1-1-5e85c5824a02@kernel.org

---
Tamir Duberstein (2):
      rust: kbuild: extract configs for reuse
      scripts: generate_rust_analyzer.py: reduce cfg plumbing

 rust/Makefile                     | 32 +++++++++++++++++++++++---------
 scripts/generate_rust_analyzer.py | 13 +++++--------
 2 files changed, 28 insertions(+), 17 deletions(-)
---
base-commit: 24d479d26b25bce5faea3ddd9fa8f3a6c3129ea7
change-id: 20260116-rust-analyzer-pin-init-duplication-a22d05221771

Best regards,
--  
Tamir Duberstein <tamird@kernel.org>


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

* [PATCH v2 1/2] rust: kbuild: extract configs for reuse
  2026-01-20 16:10 [PATCH v2 0/2] rust: reduce duplicate information Tamir Duberstein
@ 2026-01-20 16:10 ` Tamir Duberstein
  2026-01-26  4:15   ` Miguel Ojeda
  2026-01-20 16:10 ` [PATCH v2 2/2] scripts: generate_rust_analyzer.py: reduce cfg plumbing Tamir Duberstein
  2026-01-20 19:27 ` [PATCH v2 0/2] rust: reduce duplicate information Benno Lossin
  2 siblings, 1 reply; 9+ messages in thread
From: Tamir Duberstein @ 2026-01-20 16:10 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Jesung Yang
  Cc: rust-for-linux, linux-kernel, Nathan Chancellor, Nicolas Schier,
	Linux Kbuild mailing list, Tamir Duberstein

Introduce `pin_init{,_internal}-{cfgs,flags}` and pass these new cfgs to
`generate_rust_analyzer.py` to reduce duplicate information.

Signed-off-by: Tamir Duberstein <tamird@kernel.org>
---
 rust/Makefile | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/rust/Makefile b/rust/Makefile
index 5d357dce1704..2461c5835a7e 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -210,16 +210,30 @@ rustdoc-ffi: private is-kernel-object := y
 rustdoc-ffi: $(src)/ffi.rs rustdoc-core FORCE
 	+$(call if_changed,rustdoc)
 
+pin_init_internal-cfgs := \
+    kernel
+
+pin_init_internal-flags := \
+    $(call cfgs-to-flags,$(pin_init_internal-cfgs))
+
 rustdoc-pin_init_internal: private rustdoc_host = yes
-rustdoc-pin_init_internal: private rustc_target_flags = --cfg kernel \
+rustdoc-pin_init_internal: private rustc_target_flags = $(pin_init_internal-flags) \
     --extern proc_macro --crate-type proc-macro
 rustdoc-pin_init_internal: $(src)/pin-init/internal/src/lib.rs \
     rustdoc-clean FORCE
 	+$(call if_changed,rustdoc)
 
+pin_init-cfgs := \
+    kernel
+
+pin_init-flags := \
+    --extern pin_init_internal \
+    --extern macros \
+    $(call cfgs-to-flags,$(pin_init-cfgs))
+
 rustdoc-pin_init: private rustdoc_host = yes
-rustdoc-pin_init: private rustc_target_flags = --extern pin_init_internal \
-    --extern macros --extern alloc --cfg kernel --cfg feature=\"alloc\"
+rustdoc-pin_init: private rustc_target_flags = $(pin_init-flags) \
+    --extern alloc --cfg feature=\"alloc\"
 rustdoc-pin_init: $(src)/pin-init/src/lib.rs rustdoc-pin_init_internal \
     rustdoc-macros FORCE
 	+$(call if_changed,rustdoc)
@@ -272,14 +286,13 @@ rusttestlib-macros: $(src)/macros/lib.rs \
     rusttestlib-proc_macro2 rusttestlib-quote rusttestlib-syn FORCE
 	+$(call if_changed,rustc_test_library)
 
-rusttestlib-pin_init_internal: private rustc_target_flags = --cfg kernel \
+rusttestlib-pin_init_internal: private rustc_target_flags = $(pin_init_internal-flags) \
     --extern proc_macro
 rusttestlib-pin_init_internal: private rustc_test_library_proc = yes
 rusttestlib-pin_init_internal: $(src)/pin-init/internal/src/lib.rs FORCE
 	+$(call if_changed,rustc_test_library)
 
-rusttestlib-pin_init: private rustc_target_flags = --extern pin_init_internal \
-    --extern macros --cfg kernel
+rusttestlib-pin_init: private rustc_target_flags = $(pin_init-flags)
 rusttestlib-pin_init: $(src)/pin-init/src/lib.rs rusttestlib-macros \
     rusttestlib-pin_init_internal $(obj)/$(libpin_init_internal_name) FORCE
 	+$(call if_changed,rustc_test_library)
@@ -547,7 +560,7 @@ $(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib \
     $(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
 	+$(call if_changed_dep,rustc_procmacro)
 
-$(obj)/$(libpin_init_internal_name): private rustc_target_flags = --cfg kernel
+$(obj)/$(libpin_init_internal_name): private rustc_target_flags = $(pin_init_internal-flags)
 $(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs FORCE
 	+$(call if_changed_dep,rustc_procmacro)
 
@@ -570,6 +583,8 @@ rust-analyzer:
 		--cfgs='proc_macro2=$(proc_macro2-cfgs)' \
 		--cfgs='quote=$(quote-cfgs)' \
 		--cfgs='syn=$(syn-cfgs)' \
+		--cfgs='pin_init_internal=$(pin_init_internal-cfgs)' \
+		--cfgs='pin_init=$(pin_init-cfgs)' \
 		$(realpath $(srctree)) $(realpath $(objtree)) \
 		$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
 		> rust-project.json
@@ -642,8 +657,7 @@ $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
 	+$(call if_changed_rule,rustc_library)
 
 $(obj)/pin_init.o: private skip_gendwarfksyms = 1
-$(obj)/pin_init.o: private rustc_target_flags = --extern pin_init_internal \
-    --extern macros --cfg kernel
+$(obj)/pin_init.o: private rustc_target_flags = $(pin_init-flags)
 $(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \
     $(obj)/$(libpin_init_internal_name) $(obj)/$(libmacros_name) FORCE
 	+$(call if_changed_rule,rustc_library)

-- 
2.52.0


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

* [PATCH v2 2/2] scripts: generate_rust_analyzer.py: reduce cfg plumbing
  2026-01-20 16:10 [PATCH v2 0/2] rust: reduce duplicate information Tamir Duberstein
  2026-01-20 16:10 ` [PATCH v2 1/2] rust: kbuild: extract configs for reuse Tamir Duberstein
@ 2026-01-20 16:10 ` Tamir Duberstein
  2026-01-21  1:16   ` Jesung Yang
  2026-01-20 19:27 ` [PATCH v2 0/2] rust: reduce duplicate information Benno Lossin
  2 siblings, 1 reply; 9+ messages in thread
From: Tamir Duberstein @ 2026-01-20 16:10 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Jesung Yang
  Cc: rust-for-linux, linux-kernel, Nathan Chancellor, Nicolas Schier,
	Linux Kbuild mailing list, Tamir Duberstein

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


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

* Re: [PATCH v2 0/2] rust: reduce duplicate information
  2026-01-20 16:10 [PATCH v2 0/2] rust: reduce duplicate information Tamir Duberstein
  2026-01-20 16:10 ` [PATCH v2 1/2] rust: kbuild: extract configs for reuse Tamir Duberstein
  2026-01-20 16:10 ` [PATCH v2 2/2] scripts: generate_rust_analyzer.py: reduce cfg plumbing Tamir Duberstein
@ 2026-01-20 19:27 ` Benno Lossin
  2 siblings, 0 replies; 9+ messages in thread
From: Benno Lossin @ 2026-01-20 19:27 UTC (permalink / raw)
  To: Tamir Duberstein, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Jesung Yang
  Cc: rust-for-linux, linux-kernel, Nathan Chancellor, Nicolas Schier,
	Linux Kbuild mailing list

On Tue Jan 20, 2026 at 5:10 PM CET, Tamir Duberstein wrote:
> This series reuses `rust/Makefile`'s knowledge of `pin_init` and
> `pin_init_internal`'s `cfg`s in `scripts/generate_rust_analzyer.py` and
> reduces the ceremony needed to use that knowledge in the script.

This is a cool idea, I don't maintain the makefile code, so this doesn't
mean much, but it's on my radar :)

Acked-by: Benno Lossin <lossin@kernel.org>

Cheers,
Benno

> Signed-off-by: Tamir Duberstein <tamird@kernel.org>
> ---
> Changes in v2:
> - Split into two patches. (Miguel Ojeda)
> - CC kbuild. (Miguel Ojeda)
> - Link to v1: https://patch.msgid.link/20260116-rust-analyzer-pin-init-duplication-v1-1-5e85c5824a02@kernel.org
>
> ---
> Tamir Duberstein (2):
>       rust: kbuild: extract configs for reuse
>       scripts: generate_rust_analyzer.py: reduce cfg plumbing
>
>  rust/Makefile                     | 32 +++++++++++++++++++++++---------
>  scripts/generate_rust_analyzer.py | 13 +++++--------
>  2 files changed, 28 insertions(+), 17 deletions(-)
> ---
> base-commit: 24d479d26b25bce5faea3ddd9fa8f3a6c3129ea7
> change-id: 20260116-rust-analyzer-pin-init-duplication-a22d05221771
>
> Best regards,
> --  
> Tamir Duberstein <tamird@kernel.org>


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

* Re: [PATCH v2 2/2] scripts: generate_rust_analyzer.py: reduce cfg plumbing
  2026-01-20 16:10 ` [PATCH v2 2/2] scripts: generate_rust_analyzer.py: reduce cfg plumbing Tamir Duberstein
@ 2026-01-21  1:16   ` Jesung Yang
  2026-01-21 14:13     ` Tamir Duberstein
  0 siblings, 1 reply; 9+ messages in thread
From: Jesung Yang @ 2026-01-21  1:16 UTC (permalink / raw)
  To: Tamir Duberstein, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Jesung Yang
  Cc: rust-for-linux, linux-kernel, Nathan Chancellor, Nicolas Schier,
	Linux Kbuild mailing list

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(


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

* Re: [PATCH v2 2/2] scripts: generate_rust_analyzer.py: reduce cfg plumbing
  2026-01-21  1:16   ` Jesung Yang
@ 2026-01-21 14:13     ` Tamir Duberstein
  2026-01-21 23:12       ` Jesung Yang
  0 siblings, 1 reply; 9+ messages in thread
From: Tamir Duberstein @ 2026-01-21 14:13 UTC (permalink / raw)
  To: Jesung Yang
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, rust-for-linux, linux-kernel, Nathan Chancellor,
	Nicolas Schier, Linux Kbuild mailing list

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(
>

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

* Re: [PATCH v2 2/2] scripts: generate_rust_analyzer.py: reduce cfg plumbing
  2026-01-21 14:13     ` Tamir Duberstein
@ 2026-01-21 23:12       ` Jesung Yang
  2026-01-22 15:09         ` Tamir Duberstein
  0 siblings, 1 reply; 9+ messages in thread
From: Jesung Yang @ 2026-01-21 23:12 UTC (permalink / raw)
  To: 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, rust-for-linux, linux-kernel, Nathan Chancellor,
	Nicolas Schier, Linux Kbuild mailing list

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

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

* Re: [PATCH v2 2/2] scripts: generate_rust_analyzer.py: reduce cfg plumbing
  2026-01-21 23:12       ` Jesung Yang
@ 2026-01-22 15:09         ` Tamir Duberstein
  0 siblings, 0 replies; 9+ messages in thread
From: Tamir Duberstein @ 2026-01-22 15:09 UTC (permalink / raw)
  To: Jesung Yang
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, rust-for-linux, linux-kernel, Nathan Chancellor,
	Nicolas Schier, Linux Kbuild mailing list

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

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

* Re: [PATCH v2 1/2] rust: kbuild: extract configs for reuse
  2026-01-20 16:10 ` [PATCH v2 1/2] rust: kbuild: extract configs for reuse Tamir Duberstein
@ 2026-01-26  4:15   ` Miguel Ojeda
  0 siblings, 0 replies; 9+ messages in thread
From: Miguel Ojeda @ 2026-01-26  4:15 UTC (permalink / raw)
  To: Tamir Duberstein
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Jesung Yang, rust-for-linux, linux-kernel,
	Nathan Chancellor, Nicolas Schier, Linux Kbuild mailing list

On Tue, Jan 20, 2026 at 5:10 PM Tamir Duberstein <tamird@kernel.org> wrote:
>
> Introduce `pin_init{,_internal}-{cfgs,flags}` and pass these new cfgs to
> `generate_rust_analyzer.py` to reduce duplicate information.
>
> Signed-off-by: Tamir Duberstein <tamird@kernel.org>

Looks good -- my suggestion was to move the two rust-analyzer lines
here (`--cfgs=`) also into the second patch, i.e. here it would just
be about factoring out the flags, and then in the second one you pass
them to `rust-analyzer` and use the information.

Doing it here doesn't hurt, since it will be unused on the script
side, so it is also fine, but I thought it would be more
understandable the other way around.

Anyway, I could perhaps take this one with or without the two lines,
and then next cycle you can apply to rust-analyzer the other one.

Thanks!

Cheers,
Miguel

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

end of thread, other threads:[~2026-01-26  4:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-20 16:10 [PATCH v2 0/2] rust: reduce duplicate information Tamir Duberstein
2026-01-20 16:10 ` [PATCH v2 1/2] rust: kbuild: extract configs for reuse Tamir Duberstein
2026-01-26  4:15   ` Miguel Ojeda
2026-01-20 16:10 ` [PATCH v2 2/2] scripts: generate_rust_analyzer.py: reduce cfg plumbing Tamir Duberstein
2026-01-21  1:16   ` Jesung Yang
2026-01-21 14:13     ` Tamir Duberstein
2026-01-21 23:12       ` Jesung Yang
2026-01-22 15:09         ` Tamir Duberstein
2026-01-20 19:27 ` [PATCH v2 0/2] rust: reduce duplicate information Benno Lossin

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