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
On Tue, Jan 20, 2026 at 3:54 AM Eliot Courtney <ecourtney@nvidia.com> wrote:
>
> 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
This is a bit sloppy. If we expect exactly one edition per crate, we
should error when we find that is not the case.
Separately this is almost identical to `args_crates_cfgs`; it would be
better to unify the implementation.
> +
> 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")
This logic is incorrect, and the relocation of this comment is also
incorrect. The sysroot crates std, alloc, and proc_macro should also
be compiled with core's edition (this comment explains why). Your
patch changes that to edition 2021, which is incorrect.
>
> - 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
>
>
On Tue, Jan 20, 2026 at 9:54 AM Eliot Courtney <ecourtney@nvidia.com> wrote: > > 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 Could you please explain in the commit message the reasons behind the change? i.e. commit messages should explain the "why" (advantages etc.), not just the "what". Thanks! Cheers, Miguel
© 2016 - 2026 Red Hat, Inc.