From: Gary Guo <gary@garyguo.net>
To: Jesung Yang via B4 Relay <devnull+y.j3ms.n.gmail.com@kernel.org>
Cc: y.j3ms.n@gmail.com, "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scripts: generate_rust_analyzer: reduce the output file size
Date: Thu, 1 Jan 2026 22:09:03 +0000 [thread overview]
Message-ID: <20260101220903.0c099099.gary@garyguo.net> (raw)
In-Reply-To: <20260101-rust-project-reduce-size-v1-1-4cd66e9e02d9@gmail.com>
On Thu, 01 Jan 2026 08:21:24 +0000
Jesung Yang via B4 Relay <devnull+y.j3ms.n.gmail.com@kernel.org> wrote:
> From: Jesung Yang <y.j3ms.n@gmail.com>
>
> Use the `cfg_groups` field to aggregate common configurations into a
> single project-level definition. This avoids repeating identical `cfg`s
> across crates.
>
> As a result, the size of the generated `rust-project.json` is reduced
> from 11MiB to 406KiB (about 96% reduction).
This feature is not available with Rust Analyzer 1.78.
Best,
Gary
>
> Signed-off-by: Jesung Yang <y.j3ms.n@gmail.com>
> ---
> This patch depends on [1] to ensure it merges cleanly without conflicts.
>
> [1] https://lore.kernel.org/rust-for-linux/20260101-ra-fix-primitive-v1-1-def809357b4e@gmail.com/
> ---
> scripts/generate_rust_analyzer.py | 34 ++++++++++++++++++++--------------
> 1 file changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index 6178a53516ec35f308897e65c5001edd81b0d3dd..2a8578fb784d08b2a5e628bfab935080759d2dce 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -19,15 +19,7 @@ def args_crates_cfgs(cfgs):
>
> return crates_cfgs
>
> -def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
> - # 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)
> -
> +def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, kernel_cfg_group):
> # Now fill the crates list -- dependencies need to come first.
> #
> # Avoid O(n^2) iterations by keeping a map of indexes.
> @@ -35,7 +27,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
> crates_indexes = {}
> crates_cfgs = args_crates_cfgs(cfgs)
>
> - def append_crate(display_name, root_module, deps, cfg=[], crate_attrs=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
> + def append_crate(display_name, root_module, deps, cfg=[], cfg_groups=[], crate_attrs=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
> crate = {
> "display_name": display_name,
> "root_module": str(root_module),
> @@ -48,6 +40,8 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
> "RUST_MODFILE": "This is only for rust-analyzer"
> }
> }
> + if len(cfg_groups) > 0:
> + crate["cfg_groups"] = cfg_groups
> if len(crate_attrs) > 0:
> crate["crate_attrs"] = crate_attrs
> if is_proc_macro:
> @@ -134,7 +128,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
> display_name,
> srctree / "rust"/ display_name / "lib.rs",
> deps,
> - cfg=cfg,
> + cfg_groups=[kernel_cfg_group],
> crate_attrs=crate_attrs,
> )
> crates[-1]["env"]["OBJTREE"] = str(objtree.resolve(True))
> @@ -189,7 +183,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
> name,
> path,
> ["kernel"],
> - cfg=cfg,
> + cfg_groups=[kernel_cfg_group],
> crate_attrs=["no_std"],
> )
>
> @@ -214,10 +208,22 @@ def main():
> # Making sure that the `sysroot` and `sysroot_src` belong to the same toolchain.
> assert args.sysroot in args.sysroot_src.parents
>
> + # Generate the configuration list.
> + cfg = []
> + with open(args.objtree / "include" / "generated" / "rustc_cfg") as fd:
> + for line in fd:
> + line = line.replace("--cfg=", "")
> + line = line.replace("\n", "")
> + cfg.append(line)
> + kernel_cfg_group = "kernel"
> +
> rust_project = {
> - "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs),
> + "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, kernel_cfg_group),
> "sysroot": str(args.sysroot),
> - "sysroot_src": str(args.sysroot_src)
> + "sysroot_src": str(args.sysroot_src),
> + "cfg_groups": {
> + kernel_cfg_group: cfg,
> + },
> }
>
> json.dump(rust_project, sys.stdout, sort_keys=True, indent=4)
>
> ---
> base-commit: f8f9c1f4d0c7a64600e2ca312dec824a0bc2f1da
> change-id: 20260101-rust-project-reduce-size-d829a7a708ae
> prerequisite-change-id: 20260101-ra-fix-primitive-78154fe8173f:v1
> prerequisite-patch-id: 0544fdf5522949047a81c3580960183375574fd3
>
> Best regards,
next prev parent reply other threads:[~2026-01-01 22:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-01 8:21 [PATCH] scripts: generate_rust_analyzer: reduce the output file size Jesung Yang via B4 Relay
2026-01-01 22:09 ` Gary Guo [this message]
2026-01-02 1:04 ` Jesung Yang
2026-01-02 10:36 ` Gary Guo
2026-01-02 10:56 ` Miguel Ojeda
2026-01-02 13:07 ` Jesung Yang
2026-01-02 13:06 ` Jesung Yang
2026-01-02 15:27 ` Tamir Duberstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260101220903.0c099099.gary@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=devnull+y.j3ms.n.gmail.com@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=y.j3ms.n@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox