From: Eliot Courtney <ecourtney@nvidia.com>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"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>,
"Nathan Chancellor" <nathan@kernel.org>,
"Nicolas Schier" <nsc@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kbuild@vger.kernel.org,
Eliot Courtney <ecourtney@nvidia.com>
Subject: [PATCH 2/6] scripts: generate_rust_analyzer: plumb editions via command line
Date: Tue, 20 Jan 2026 17:52:51 +0900 [thread overview]
Message-ID: <20260120-ra-fix-v1-2-829e4e92818c@nvidia.com> (raw)
In-Reply-To: <20260120-ra-fix-v1-0-829e4e92818c@nvidia.com>
Add --editions argument to pass crate editions in a similar way to the
existing --cfgs mechanism.
It sets editions as follows:
- core: 2024 for rustc >= 1.87 otherwise 2021
- quote: 2018
- all others: 2021
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
rust/Makefile | 8 +++--
scripts/generate_rust_analyzer.py | 70 ++++++++++++++++++++++-----------------
2 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/rust/Makefile b/rust/Makefile
index 4dcc2eff51cb..2238b0b69197 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -95,8 +95,10 @@ quote-cfgs := \
quote-skip_flags := \
--edition=2021
+quote-edition := 2018
+
quote-flags := \
- --edition=2018 \
+ --edition=$(quote-edition) \
--cap-lints=allow \
--extern proc_macro2 \
$(call cfgs-to-flags,$(quote-cfgs))
@@ -567,10 +569,12 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
rust-analyzer:
$(Q)MAKEFLAGS= $(srctree)/scripts/generate_rust_analyzer.py \
- --cfgs='core=$(core-cfgs)' $(core-edition) \
+ --cfgs='core=$(core-cfgs)' \
--cfgs='proc_macro2=$(proc_macro2-cfgs)' \
--cfgs='quote=$(quote-cfgs)' \
--cfgs='syn=$(syn-cfgs)' \
+ --editions='core=$(core-edition)' \
+ --editions='quote=$(quote-edition)' \
$(realpath $(srctree)) $(realpath $(objtree)) \
$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
> rust-project.json
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index c188d1f1fd5b..17ed5546504b 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -11,6 +11,13 @@ import pathlib
import subprocess
import sys
+def args_single(args):
+ result = {}
+ for arg in args:
+ crate, val = arg.split("=", 1)
+ result[crate] = val
+ return result
+
def args_crates_cfgs(cfgs):
crates_cfgs = {}
for cfg in cfgs:
@@ -19,7 +26,7 @@ def args_crates_cfgs(cfgs):
return crates_cfgs
-def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edition):
+def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, editions):
# Generate the configuration list.
generated_cfg = []
with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
@@ -34,8 +41,35 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
crates = []
crates_indexes = {}
crates_cfgs = args_crates_cfgs(cfgs)
+ crates_editions = args_single(editions)
+
+ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
+ # Miguel Ojeda writes:
+ #
+ # > ... in principle even the sysroot crates may have different
+ # > editions.
+ # >
+ # > For instance, in the move to 2024, it seems all happened at once
+ # > in 1.87.0 in these upstream commits:
+ # >
+ # > 0e071c2c6a58 ("Migrate core to Rust 2024")
+ # > f505d4e8e380 ("Migrate alloc to Rust 2024")
+ # > 0b2489c226c3 ("Migrate proc_macro to Rust 2024")
+ # > 993359e70112 ("Migrate std to Rust 2024")
+ # >
+ # > But in the previous move to 2021, `std` moved in 1.59.0, while
+ # > the others in 1.60.0:
+ # >
+ # > b656384d8398 ("Update stdlib to the 2021 edition")
+ # > 06a1c14d52a8 ("Switch all libraries to the 2021 edition")
+ #
+ # Link: https://lore.kernel.org/all/CANiq72kd9bHdKaAm=8xCUhSHMy2csyVed69bOc4dXyFAW4sfuw@mail.gmail.com/
+ #
+ # At the time of writing all rust versions we support build the
+ # sysroot crates with the same edition. We may need to relax this
+ # assumption if future edition moves span multiple rust versions.
+ edition = crates_editions.get(display_name, "2021")
- def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
crate = {
"display_name": display_name,
"root_module": str(root_module),
@@ -68,31 +102,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
deps,
cfg,
is_workspace_member=False,
- # Miguel Ojeda writes:
- #
- # > ... in principle even the sysroot crates may have different
- # > editions.
- # >
- # > For instance, in the move to 2024, it seems all happened at once
- # > in 1.87.0 in these upstream commits:
- # >
- # > 0e071c2c6a58 ("Migrate core to Rust 2024")
- # > f505d4e8e380 ("Migrate alloc to Rust 2024")
- # > 0b2489c226c3 ("Migrate proc_macro to Rust 2024")
- # > 993359e70112 ("Migrate std to Rust 2024")
- # >
- # > But in the previous move to 2021, `std` moved in 1.59.0, while
- # > the others in 1.60.0:
- # >
- # > b656384d8398 ("Update stdlib to the 2021 edition")
- # > 06a1c14d52a8 ("Switch all libraries to the 2021 edition")
- #
- # Link: https://lore.kernel.org/all/CANiq72kd9bHdKaAm=8xCUhSHMy2csyVed69bOc4dXyFAW4sfuw@mail.gmail.com/
- #
- # At the time of writing all rust versions we support build the
- # sysroot crates with the same edition. We may need to relax this
- # assumption if future edition moves span multiple rust versions.
- edition=core_edition,
)
# NB: sysroot crates reexport items from one another so setting up our transitive dependencies
@@ -120,8 +129,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
"quote",
srctree / "rust" / "quote" / "lib.rs",
["core", "alloc", "std", "proc_macro", "proc_macro2"],
- cfg=crates_cfgs["quote"],
- edition="2018",
+ cfg=crates_cfgs["quote"]
)
append_crate(
@@ -224,7 +232,7 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', '-v', action='store_true')
parser.add_argument('--cfgs', action='append', default=[])
- parser.add_argument("core_edition")
+ parser.add_argument('--editions', action='append', default=[])
parser.add_argument("srctree", type=pathlib.Path)
parser.add_argument("objtree", type=pathlib.Path)
parser.add_argument("sysroot", type=pathlib.Path)
@@ -238,7 +246,7 @@ def main():
)
rust_project = {
- "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.core_edition),
+ "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.editions),
"sysroot": str(args.sysroot),
}
--
2.52.0
next prev parent reply other threads:[~2026-01-20 8:54 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 8:52 [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Eliot Courtney
2026-01-20 8:52 ` [PATCH 1/6] scripts: generate_rust_analyzer: rename cfg to generated_cfg Eliot Courtney
2026-01-20 15:28 ` Tamir Duberstein
2026-03-02 17:09 ` Tamir Duberstein
2026-01-20 8:52 ` Eliot Courtney [this message]
2026-01-20 13:57 ` [PATCH 2/6] scripts: generate_rust_analyzer: plumb editions via command line Miguel Ojeda
2026-01-20 15:28 ` Tamir Duberstein
2026-01-20 8:52 ` [PATCH 3/6] scripts: generate_rust_analyzer: plumb crate-attrs Eliot Courtney
2026-01-20 15:28 ` Tamir Duberstein
2026-01-20 8:52 ` [PATCH 4/6] scripts: generate_rust_analyzer: plumb common crate-attrs for non-host crates Eliot Courtney
2026-01-20 15:28 ` Tamir Duberstein
2026-01-20 8:52 ` [PATCH 5/6] scripts: generate_rust_analyzer: add pin_init to driver crate deps Eliot Courtney
2026-01-20 15:28 ` Tamir Duberstein
2026-01-20 8:52 ` [PATCH 6/6] scripts: generate_rust_analyzer: move sysroot crates to sysroot_project Eliot Courtney
2026-01-20 15:34 ` Tamir Duberstein
2026-01-21 0:01 ` Jesung Yang
2026-01-22 9:23 ` Eliot Courtney
2026-01-22 11:06 ` Jesung Yang
2026-01-23 5:45 ` Eliot Courtney
2026-01-23 12:08 ` Miguel Ojeda
2026-01-23 12:23 ` Gary Guo
2026-01-23 12:31 ` Miguel Ojeda
2026-01-20 13:38 ` [PATCH 0/6] scripts: generate_rust_analyzer: improve rust-project.json generation Miguel Ojeda
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=20260120-ra-fix-v1-2-829e4e92818c@nvidia.com \
--to=ecourtney@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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
all inboxes | Powered by JetHome®