Skip to content

Commit 5c8d16a

Browse files
committed
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>
1 parent dc6b431 commit 5c8d16a

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

rust/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ rust-analyzer:
592592
--cfgs='proc_macro2=$(proc_macro2-cfgs)' \
593593
--cfgs='quote=$(quote-cfgs)' \
594594
--cfgs='syn=$(syn-cfgs)' \
595+
--cfgs='pin_init_internal=$(pin_init_internal-cfgs)' \
596+
--cfgs='pin_init=$(pin_init-cfgs)' \
595597
$(realpath $(srctree)) $(realpath $(objtree)) \
596598
$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
597599
> rust-project.json

scripts/generate_rust_analyzer.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def build_crate(
7878
is_workspace_member: Optional[bool],
7979
edition: Optional[str],
8080
) -> Crate:
81-
cfg = cfg if cfg is not None else []
81+
cfg = cfg if cfg is not None else crates_cfgs.get(display_name, [])
8282
is_workspace_member = (
8383
is_workspace_member if is_workspace_member is not None else True
8484
)
@@ -203,7 +203,7 @@ def append_sysroot_crate(
203203
# NB: sysroot crates reexport items from one another so setting up our transitive dependencies
204204
# here is important for ensuring that rust-analyzer can resolve symbols. The sources of truth
205205
# for this dependency graph are `(sysroot_src / crate / "Cargo.toml" for crate in crates)`.
206-
core = append_sysroot_crate("core", [], cfg=crates_cfgs.get("core", []))
206+
core = append_sysroot_crate("core", [])
207207
alloc = append_sysroot_crate("alloc", [core])
208208
std = append_sysroot_crate("std", [alloc, core])
209209
proc_macro = append_sysroot_crate("proc_macro", [core, std])
@@ -218,22 +218,19 @@ def append_sysroot_crate(
218218
"proc_macro2",
219219
srctree / "rust" / "proc-macro2" / "lib.rs",
220220
[core, alloc, std, proc_macro],
221-
cfg=crates_cfgs["proc_macro2"],
222221
)
223222

224223
quote = append_crate(
225224
"quote",
226225
srctree / "rust" / "quote" / "lib.rs",
227226
[core, alloc, std, proc_macro, proc_macro2],
228-
cfg=crates_cfgs["quote"],
229227
edition="2018",
230228
)
231229

232230
syn = append_crate(
233231
"syn",
234232
srctree / "rust" / "syn" / "lib.rs",
235233
[std, proc_macro, proc_macro2, quote],
236-
cfg=crates_cfgs["syn"],
237234
)
238235

239236
macros = append_proc_macro_crate(
@@ -252,14 +249,12 @@ def append_sysroot_crate(
252249
"pin_init_internal",
253250
srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs",
254251
[std, proc_macro, proc_macro2, quote, syn],
255-
cfg=["kernel"],
256252
)
257253

258254
pin_init = append_crate(
259255
"pin_init",
260256
srctree / "rust" / "pin-init" / "src" / "lib.rs",
261257
[core, compiler_builtins, pin_init_internal, macros],
262-
cfg=["kernel"],
263258
)
264259

265260
ffi = append_crate(

0 commit comments

Comments
 (0)