Skip to content

Commit 11f3aa1

Browse files
nbdd0121ojeda
authored andcommitted
rust: compile libcore with edition 2024 for 1.87+
commit f4daa80 upstream. Rust 1.87 (released on 2025-05-15) compiles core library with edition 2024 instead of 2021 [1]. Ensure that the edition matches libcore's expectation to avoid potential breakage. [ J3m3 reported in Zulip [2] that the `rust-analyzer` target was broken after this patch -- indeed, we need to avoid `core-cfgs` since those are passed to the `rust-analyzer` target. So, instead, I tweaked the patch to create a new `core-edition` variable and explicitly mention the `--edition` flag instead of reusing `core-cfg`s. In addition, pass a new argument using this new variable to `generate_rust_analyzer.py` so that we set the right edition there. By the way, for future reference: the `filter-out` change is needed for Rust < 1.87, since otherwise we would skip the `--edition=2021` we just added, ending up with no edition flag, and thus the compiler would default to the 2015 one. [2] https://rust-for-linux.zulipchat.com/#narrow/channel/291565/topic/x/near/520206547 - Miguel ] Cc: [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs). Link: rust-lang/rust#138162 [1] Reported-by: est31 <[email protected]> Closes: Rust-for-Linux#1163 Signed-off-by: Gary Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]> [ Solved conflicts for 6.12.y backport. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 279190f commit 11f3aa1

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

rust/Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ endif
5353
core-cfgs = \
5454
--cfg no_fp_fmt_parse
5555

56+
core-edition := $(if $(call rustc-min-version,108700),2024,2021)
57+
5658
quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
5759
cmd_rustdoc = \
5860
OBJTREE=$(abspath $(objtree)) \
@@ -95,8 +97,8 @@ rustdoc-macros: $(src)/macros/lib.rs FORCE
9597

9698
# Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should
9799
# not be needed -- see https://github.com/rust-lang/rust/pull/128307.
98-
rustdoc-core: private skip_flags = -Wrustdoc::unescaped_backticks
99-
rustdoc-core: private rustc_target_flags = $(core-cfgs)
100+
rustdoc-core: private skip_flags = --edition=2021 -Wrustdoc::unescaped_backticks
101+
rustdoc-core: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs)
100102
rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
101103
+$(call if_changed,rustdoc)
102104

@@ -372,7 +374,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
372374
cmd_rustc_library = \
373375
OBJTREE=$(abspath $(objtree)) \
374376
$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
375-
$(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \
377+
$(filter-out $(skip_flags),$(rust_flags)) $(rustc_target_flags) \
376378
--emit=dep-info=$(depfile) --emit=obj=$@ \
377379
--emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
378380
--crate-type rlib -L$(objtree)/$(obj) \
@@ -383,7 +385,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
383385

384386
rust-analyzer:
385387
$(Q)$(srctree)/scripts/generate_rust_analyzer.py \
386-
--cfgs='core=$(core-cfgs)' \
388+
--cfgs='core=$(core-cfgs)' $(core-edition) \
387389
$(realpath $(srctree)) $(realpath $(objtree)) \
388390
$(rustc_sysroot) $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \
389391
$(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json
@@ -407,9 +409,9 @@ define rule_rustc_library
407409
endef
408410

409411
$(obj)/core.o: private skip_clippy = 1
410-
$(obj)/core.o: private skip_flags = -Wunreachable_pub
412+
$(obj)/core.o: private skip_flags = --edition=2021 -Wunreachable_pub
411413
$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
412-
$(obj)/core.o: private rustc_target_flags = $(core-cfgs)
414+
$(obj)/core.o: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs)
413415
$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs \
414416
$(wildcard $(objtree)/include/config/RUSTC_VERSION_TEXT) FORCE
415417
+$(call if_changed_rule,rustc_library)

scripts/generate_rust_analyzer.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def args_crates_cfgs(cfgs):
1818

1919
return crates_cfgs
2020

21-
def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
21+
def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edition):
2222
# Generate the configuration list.
2323
cfg = []
2424
with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
@@ -34,7 +34,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
3434
crates_indexes = {}
3535
crates_cfgs = args_crates_cfgs(cfgs)
3636

37-
def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
37+
def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
3838
crates_indexes[display_name] = len(crates)
3939
crates.append({
4040
"display_name": display_name,
@@ -43,7 +43,7 @@ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=Tr
4343
"is_proc_macro": is_proc_macro,
4444
"deps": [{"crate": crates_indexes[dep], "name": dep} for dep in deps],
4545
"cfg": cfg,
46-
"edition": "2021",
46+
"edition": edition,
4747
"env": {
4848
"RUST_MODFILE": "This is only for rust-analyzer"
4949
}
@@ -53,19 +53,21 @@ def append_sysroot_crate(
5353
display_name,
5454
deps,
5555
cfg=[],
56+
edition="2021",
5657
):
5758
append_crate(
5859
display_name,
5960
sysroot_src / display_name / "src" / "lib.rs",
6061
deps,
6162
cfg,
6263
is_workspace_member=False,
64+
edition=edition,
6365
)
6466

6567
# NB: sysroot crates reexport items from one another so setting up our transitive dependencies
6668
# here is important for ensuring that rust-analyzer can resolve symbols. The sources of truth
6769
# for this dependency graph are `(sysroot_src / crate / "Cargo.toml" for crate in crates)`.
68-
append_sysroot_crate("core", [], cfg=crates_cfgs.get("core", []))
70+
append_sysroot_crate("core", [], cfg=crates_cfgs.get("core", []), edition=core_edition)
6971
append_sysroot_crate("alloc", ["core"])
7072
append_sysroot_crate("std", ["alloc", "core"])
7173
append_sysroot_crate("proc_macro", ["core", "std"])
@@ -155,6 +157,7 @@ def main():
155157
parser = argparse.ArgumentParser()
156158
parser.add_argument('--verbose', '-v', action='store_true')
157159
parser.add_argument('--cfgs', action='append', default=[])
160+
parser.add_argument("core_edition")
158161
parser.add_argument("srctree", type=pathlib.Path)
159162
parser.add_argument("objtree", type=pathlib.Path)
160163
parser.add_argument("sysroot", type=pathlib.Path)
@@ -171,7 +174,7 @@ def main():
171174
assert args.sysroot in args.sysroot_src.parents
172175

173176
rust_project = {
174-
"crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs),
177+
"crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.core_edition),
175178
"sysroot": str(args.sysroot),
176179
}
177180

0 commit comments

Comments
 (0)