Skip to content

Commit 21072d1

Browse files
nbdd0121smb49
authored andcommitted
rust: compile libcore with edition 2024 for 1.87+
BugLink: https://bugs.launchpad.net/bugs/2119603 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/linux#1163 Signed-off-by: Gary Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Manuel Diewald <[email protected]> Signed-off-by: Mehmet Basaran <[email protected]>
1 parent d87bb99 commit 21072d1

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
@@ -57,6 +57,8 @@ endif
5757
core-cfgs = \
5858
--cfg no_fp_fmt_parse
5959

60+
core-edition := $(if $(call rustc-min-version,108700),2024,2021)
61+
6062
# `rustc` recognizes `--remap-path-prefix` since 1.26.0, but `rustdoc` only
6163
# since Rust 1.81.0. Moreover, `rustdoc` ICEs on out-of-tree builds since Rust
6264
# 1.82.0 (https://github.com/rust-lang/rust/issues/138520). Thus workaround both
@@ -103,8 +105,8 @@ rustdoc-macros: $(src)/macros/lib.rs FORCE
103105

104106
# Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should
105107
# not be needed -- see https://github.com/rust-lang/rust/pull/128307.
106-
rustdoc-core: private skip_flags = -Wrustdoc::unescaped_backticks
107-
rustdoc-core: private rustc_target_flags = $(core-cfgs)
108+
rustdoc-core: private skip_flags = --edition=2021 -Wrustdoc::unescaped_backticks
109+
rustdoc-core: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs)
108110
rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
109111
+$(call if_changed,rustdoc)
110112

@@ -382,7 +384,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
382384
cmd_rustc_library = \
383385
OBJTREE=$(abspath $(objtree)) \
384386
$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
385-
$(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \
387+
$(filter-out $(skip_flags),$(rust_flags)) $(rustc_target_flags) \
386388
--emit=dep-info=$(depfile) --emit=obj=$@ \
387389
--emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
388390
--crate-type rlib -L$(objtree)/$(obj) \
@@ -393,7 +395,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
393395

394396
rust-analyzer:
395397
$(Q)MAKEFLAGS= $(srctree)/scripts/generate_rust_analyzer.py \
396-
--cfgs='core=$(core-cfgs)' \
398+
--cfgs='core=$(core-cfgs)' $(core-edition) \
397399
$(realpath $(srctree)) $(realpath $(objtree)) \
398400
$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
399401
> rust-project.json
@@ -442,9 +444,9 @@ $(obj)/helpers/helpers.o: $(src)/helpers/helpers.c $(recordmcount_source) FORCE
442444
$(obj)/exports.o: private skip_gendwarfksyms = 1
443445

444446
$(obj)/core.o: private skip_clippy = 1
445-
$(obj)/core.o: private skip_flags = -Wunreachable_pub
447+
$(obj)/core.o: private skip_flags = --edition=2021 -Wunreachable_pub
446448
$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
447-
$(obj)/core.o: private rustc_target_flags = $(core-cfgs)
449+
$(obj)/core.o: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs)
448450
$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs \
449451
$(wildcard $(objtree)/include/config/RUSTC_VERSION_TEXT) FORCE
450452
+$(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
@@ -19,7 +19,7 @@ def args_crates_cfgs(cfgs):
1919

2020
return crates_cfgs
2121

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

38-
def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
38+
def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False, edition="2021"):
3939
crate = {
4040
"display_name": display_name,
4141
"root_module": str(root_module),
4242
"is_workspace_member": is_workspace_member,
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
}
@@ -61,19 +61,21 @@ def append_sysroot_crate(
6161
display_name,
6262
deps,
6363
cfg=[],
64+
edition="2021",
6465
):
6566
append_crate(
6667
display_name,
6768
sysroot_src / display_name / "src" / "lib.rs",
6869
deps,
6970
cfg,
7071
is_workspace_member=False,
72+
edition=edition,
7173
)
7274

7375
# NB: sysroot crates reexport items from one another so setting up our transitive dependencies
7476
# here is important for ensuring that rust-analyzer can resolve symbols. The sources of truth
7577
# for this dependency graph are `(sysroot_src / crate / "Cargo.toml" for crate in crates)`.
76-
append_sysroot_crate("core", [], cfg=crates_cfgs.get("core", []))
78+
append_sysroot_crate("core", [], cfg=crates_cfgs.get("core", []), edition=core_edition)
7779
append_sysroot_crate("alloc", ["core"])
7880
append_sysroot_crate("std", ["alloc", "core"])
7981
append_sysroot_crate("proc_macro", ["core", "std"])
@@ -162,6 +164,7 @@ def main():
162164
parser = argparse.ArgumentParser()
163165
parser.add_argument('--verbose', '-v', action='store_true')
164166
parser.add_argument('--cfgs', action='append', default=[])
167+
parser.add_argument("core_edition")
165168
parser.add_argument("srctree", type=pathlib.Path)
166169
parser.add_argument("objtree", type=pathlib.Path)
167170
parser.add_argument("sysroot", type=pathlib.Path)
@@ -178,7 +181,7 @@ def main():
178181
assert args.sysroot in args.sysroot_src.parents
179182

180183
rust_project = {
181-
"crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs),
184+
"crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.core_edition),
182185
"sysroot": str(args.sysroot),
183186
}
184187

0 commit comments

Comments
 (0)