Skip to content

Commit 4f353e0

Browse files
YakoYakoYokuYokuojeda
authored andcommitted
scripts: generate_rust_analyzer: provide cfgs for core and alloc
Both `core` and `alloc` have their `cfgs` (such as `no_rc`) missing in `rust-project.json`. To remedy this, pass the flags to `generate_rust_analyzer.py` for them to be added to a dictionary where each key corresponds to a crate and each value to a list of `cfg`s. The dictionary is then used to pass the `cfg`s to each crate in the generated file (for `core` and `alloc` only). Signed-off-by: Martin Rodriguez Reboredo <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Removed `Suggested-by` as discussed in mailing list. ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 08ab786 commit 4f353e0

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

rust/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
374374

375375
rust-analyzer:
376376
$(Q)$(srctree)/scripts/generate_rust_analyzer.py \
377+
--cfgs='core=$(core-cfgs)' --cfgs='alloc=$(alloc-cfgs)' \
377378
$(abs_srctree) $(abs_objtree) \
378379
$(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \
379380
$(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json

scripts/generate_rust_analyzer.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
import pathlib
1111
import sys
1212

13-
def generate_crates(srctree, objtree, sysroot_src, external_src):
13+
def args_crates_cfgs(cfgs):
14+
crates_cfgs = {}
15+
for cfg in cfgs:
16+
crate, vals = cfg.split("=", 1)
17+
crates_cfgs[crate] = vals.replace("--cfg", "").split()
18+
19+
return crates_cfgs
20+
21+
def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
1422
# Generate the configuration list.
1523
cfg = []
1624
with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
@@ -24,6 +32,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src):
2432
# Avoid O(n^2) iterations by keeping a map of indexes.
2533
crates = []
2634
crates_indexes = {}
35+
crates_cfgs = args_crates_cfgs(cfgs)
2736

2837
def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
2938
crates_indexes[display_name] = len(crates)
@@ -45,6 +54,7 @@ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=Tr
4554
"core",
4655
sysroot_src / "core" / "src" / "lib.rs",
4756
[],
57+
cfg=crates_cfgs.get("core", []),
4858
is_workspace_member=False,
4959
)
5060

@@ -58,6 +68,7 @@ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=Tr
5868
"alloc",
5969
srctree / "rust" / "alloc" / "lib.rs",
6070
["core", "compiler_builtins"],
71+
cfg=crates_cfgs.get("alloc", []),
6172
)
6273

6374
append_crate(
@@ -131,6 +142,7 @@ def is_root_crate(build_file, target):
131142
def main():
132143
parser = argparse.ArgumentParser()
133144
parser.add_argument('--verbose', '-v', action='store_true')
145+
parser.add_argument('--cfgs', action='append', default=[])
134146
parser.add_argument("srctree", type=pathlib.Path)
135147
parser.add_argument("objtree", type=pathlib.Path)
136148
parser.add_argument("sysroot_src", type=pathlib.Path)
@@ -143,7 +155,7 @@ def main():
143155
)
144156

145157
rust_project = {
146-
"crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree),
158+
"crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs),
147159
"sysroot_src": str(args.sysroot_src),
148160
}
149161

0 commit comments

Comments
 (0)