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 <y.j3ms.n@gmail.com>
Acked-by: Benno Lossin <lossin@kernel.org>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://patch.msgid.link/20260127-rust-analyzer-pin-init-duplication-v3-2-118c48c35e88@kernel.org
Signed-off-by: Tamir Duberstein <tamird@kernel.org>
This commit is contained in:
Tamir Duberstein 2026-01-27 08:55:51 -05:00
parent dc6b431f18
commit 5c8d16ac49
No known key found for this signature in database
GPG Key ID: D04C0E2517D71297
2 changed files with 4 additions and 7 deletions

View File

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

View File

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