[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20250424-rust-analyzer-host-v6-13-40e67fe5c38a@gmail.com>
Date: Thu, 24 Apr 2025 06:38:41 -0400
From: Tamir Duberstein <tamird@...il.com>
To: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>,
Boris-Chengbiao Zhou <bobo1239@....de>, Kees Cook <kees@...nel.org>,
Fiona Behrens <me@...enk.dev>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
Lukas Wirth <lukas.wirth@...rous-systems.com>,
Tamir Duberstein <tamird@...il.com>,
Daniel Almeida <daniel.almeida@...labora.com>
Subject: [PATCH v6 13/13] scripts: generate_rust_analyzer.py: use
`cfg_groups`
Declare common `cfg`s just once to reduce the size of rust-analyzer.json
from 30619 to 2624 lines.
Link: https://github.com/rust-lang/rust-analyzer/commit/2607c09fddef36da0d6f0a84625db5e20a5ebde3
Reviewed-by: Daniel Almeida <daniel.almeida@...labora.com>
Tested-by: Daniel Almeida <daniel.almeida@...labora.com>
Reviewed-by: Trevor Gross <tmgross@...ch.edu>
Signed-off-by: Tamir Duberstein <tamird@...il.com>
---
scripts/generate_rust_analyzer.py | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 5f04e3785854..aa79b56ff6f4 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -29,6 +29,7 @@ class Crate(TypedDict):
root_module: str
is_workspace_member: bool
deps: List[Dependency]
+ cfg_groups: List[str]
cfg: List[str]
edition: Literal["2021"]
env: Dict[str, str]
@@ -51,15 +52,8 @@ def generate_crates(
sysroot_src: pathlib.Path,
external_src: pathlib.Path,
crates_cfgs: DefaultDict[str, List[str]],
+ cfg_groups: List[str],
) -> List[Crate]:
- # Generate the configuration list.
- cfg = []
- with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
- for line in fd:
- line = line.replace("--cfg=", "")
- line = line.replace("\n", "")
- cfg.append(line)
-
# Now fill the crates list.
crates: List[Crate] = []
@@ -76,6 +70,9 @@ def generate_crates(
"root_module": str(root_module),
"is_workspace_member": is_workspace_member,
"deps": deps,
+ # `cfg_groups` contain the configs generated by the kernel build system; upstream
+ # (sysroot) crates are not aware of them.
+ "cfg_groups": cfg_groups if is_workspace_member else [],
"cfg": cfg,
"edition": "2021",
"env": {
@@ -298,7 +295,7 @@ def generate_crates(
name,
path,
deps=[core, kernel],
- cfg=cfg,
+ cfg=[],
)
return crates
@@ -338,6 +335,10 @@ def main() -> None:
for crate, _, vals in (cfg.partition("=") for cfg in args.cfgs)
}
+ # Generate the configuration list.
+ with open(args.objtree / "include" / "generated" / "rustc_cfg") as fd:
+ cfg_groups = {"rustc_cfg": [line.lstrip("--cfg=").rstrip("\n") for line in fd]}
+
rust_project = {
"crates": generate_crates(
args.srctree,
@@ -345,8 +346,10 @@ def main() -> None:
args.sysroot_src,
args.exttree,
defaultdict(list, crates_cfg),
+ list(cfg_groups.keys()),
),
"sysroot": str(args.sysroot),
+ "cfg_groups": cfg_groups,
}
json.dump(rust_project, sys.stdout, sort_keys=True, indent=4)
--
2.49.0
Powered by blists - more mailing lists