From: Tamir Duberstein Date: Tue, 27 Jan 2026 13:55:51 +0000 (-0500) Subject: scripts: generate_rust_analyzer.py: reduce cfg plumbing X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c8d16ac49405c5b77c955684849528f7d4d6b81;p=thirdparty%2Fkernel%2Flinux.git scripts: generate_rust_analyzer.py: reduce cfg plumbing Pass `pin_init{,_internal}-cfgs` from rust/Makefile to scripts/generate_rust_analyzer.py. Remove hardcoded `cfg`s in scripts/generate_rust_analyzer.py for `pin-init{,-internal}` now that these are passed from `rust/Makefile`. Centralize `cfg` lookup in scripts/generate_rust_analyzer.py in `append_crate` to avoid having to do so for each crate. Reviewed-by: Jesung Yang Acked-by: Benno Lossin Acked-by: Miguel Ojeda Link: https://patch.msgid.link/20260127-rust-analyzer-pin-init-duplication-v3-2-118c48c35e88@kernel.org Signed-off-by: Tamir Duberstein --- diff --git a/rust/Makefile b/rust/Makefile index 629b3bdd2b206..061a4e7af3b87 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -592,6 +592,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 diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py index 2977dfff76b3a..b4a55344688dd 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -78,7 +78,7 @@ def generate_crates( is_workspace_member: Optional[bool], edition: Optional[str], ) -> Crate: - cfg = cfg if cfg is not None else [] + cfg = cfg if cfg is not None else crates_cfgs.get(display_name, []) is_workspace_member = ( is_workspace_member if is_workspace_member is not None else True ) @@ -203,7 +203,7 @@ def generate_crates( # 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)`. - core = append_sysroot_crate("core", [], cfg=crates_cfgs.get("core", [])) + core = append_sysroot_crate("core", []) alloc = append_sysroot_crate("alloc", [core]) std = append_sysroot_crate("std", [alloc, core]) proc_macro = append_sysroot_crate("proc_macro", [core, std]) @@ -218,14 +218,12 @@ def generate_crates( "proc_macro2", srctree / "rust" / "proc-macro2" / "lib.rs", [core, alloc, std, proc_macro], - cfg=crates_cfgs["proc_macro2"], ) quote = append_crate( "quote", srctree / "rust" / "quote" / "lib.rs", [core, alloc, std, proc_macro, proc_macro2], - cfg=crates_cfgs["quote"], edition="2018", ) @@ -233,7 +231,6 @@ def generate_crates( "syn", srctree / "rust" / "syn" / "lib.rs", [std, proc_macro, proc_macro2, quote], - cfg=crates_cfgs["syn"], ) macros = append_proc_macro_crate( @@ -252,14 +249,12 @@ def generate_crates( "pin_init_internal", srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs", [std, proc_macro, proc_macro2, quote, syn], - cfg=["kernel"], ) pin_init = append_crate( "pin_init", srctree / "rust" / "pin-init" / "src" / "lib.rs", [core, compiler_builtins, pin_init_internal, macros], - cfg=["kernel"], ) ffi = append_crate(