Skip to content

Commit e30e219

Browse files
committed
rust: proc-macro2: enable support in kbuild
With all the new files in place and ready from the new crate, enable the support for it in the build system. `proc_macro_byte_character` and `proc_macro_c_str_literals` were stabilized in Rust 1.79.0 [1] and were implemented earlier than our minimum Rust version (1.78) [2][3]. Thus just enable them instead of using the `cfg` that `proc-macro2` uses to emulate them in older compilers. Link: rust-lang/rust#123431 [1] Link: rust-lang/rust#112711 [2] Link: rust-lang/rust#119651 [3] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent eb30622 commit e30e219

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,9 @@ PHONY += rustfmt rustfmtcheck
18301830

18311831
rustfmt:
18321832
$(Q)find $(srctree) $(RCS_FIND_IGNORE) \
1833+
\( \
1834+
-path $(srctree)/rust/proc-macro2 \
1835+
\) -prune -o \
18331836
-type f -a -name '*.rs' -a ! -name '*generated*' -print \
18341837
| xargs $(RUSTFMT) $(rustfmt_flags)
18351838

rust/Makefile

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ endif
2727

2828
obj-$(CONFIG_RUST) += exports.o
2929

30+
always-$(CONFIG_RUST) += libproc_macro2.rlib
31+
3032
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs
3133
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c
3234

@@ -65,6 +67,17 @@ core-cfgs = \
6567

6668
core-edition := $(if $(call rustc-min-version,108700),2024,2021)
6769

70+
proc_macro2-cfgs := \
71+
--cfg 'feature="proc-macro"' \
72+
--cfg wrap_proc_macro \
73+
$(if $(call rustc-min-version,108800),--cfg proc_macro_span_file --cfg proc_macro_span_location)
74+
75+
# Stable since Rust 1.79.0: `feature(proc_macro_byte_character,proc_macro_c_str_literals)`.
76+
proc_macro2-flags := \
77+
--cap-lints=allow \
78+
-Zcrate-attr='feature(proc_macro_byte_character,proc_macro_c_str_literals)' \
79+
$(proc_macro2-cfgs)
80+
6881
# `rustdoc` did not save the target modifiers, thus workaround for
6982
# the time being (https://github.com/rust-lang/rust/issues/144521).
7083
rustdoc_modifiers_workaround := $(if $(call rustc-min-version,108800),-Cunsafe-allow-abi-mismatch=fixed-x18)
@@ -114,10 +127,15 @@ rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
114127
$(Q)for f in $(rustdoc_output)/static.files/rustdoc-*.css; do \
115128
echo ".logo-container > img { object-fit: contain; }" >> $$f; done
116129

130+
rustdoc-proc_macro2: private rustdoc_host = yes
131+
rustdoc-proc_macro2: private rustc_target_flags = $(proc_macro2-flags)
132+
rustdoc-proc_macro2: $(src)/proc-macro2/lib.rs rustdoc-clean FORCE
133+
+$(call if_changed,rustdoc)
134+
117135
rustdoc-macros: private rustdoc_host = yes
118136
rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
119137
--extern proc_macro
120-
rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean FORCE
138+
rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean rustdoc-proc_macro2 FORCE
121139
+$(call if_changed,rustdoc)
122140

123141
# Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should
@@ -174,6 +192,10 @@ rusttestlib-build_error: $(src)/build_error.rs FORCE
174192
rusttestlib-ffi: $(src)/ffi.rs FORCE
175193
+$(call if_changed,rustc_test_library)
176194

195+
rusttestlib-proc_macro2: private rustc_target_flags = $(proc_macro2-flags)
196+
rusttestlib-proc_macro2: $(src)/proc-macro2/lib.rs FORCE
197+
+$(call if_changed,rustc_test_library)
198+
177199
rusttestlib-macros: private rustc_target_flags = --extern proc_macro
178200
rusttestlib-macros: private rustc_test_library_proc = yes
179201
rusttestlib-macros: $(src)/macros/lib.rs FORCE
@@ -420,6 +442,11 @@ quiet_cmd_rustc_hostlibrary = $(RUSTC_OR_CLIPPY_QUIET) H $@
420442
mv $(objtree)/$(obj)/$(patsubst lib%.rlib,%,$(notdir $@)).d $(depfile); \
421443
sed -i '/^\#/d' $(depfile)
422444

445+
$(obj)/libproc_macro2.rlib: private skip_clippy = 1
446+
$(obj)/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags)
447+
$(obj)/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE
448+
+$(call if_changed_dep,rustc_hostlibrary)
449+
423450
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
424451
cmd_rustc_procmacro = \
425452
$(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \
@@ -431,7 +458,7 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
431458
@$(objtree)/include/generated/rustc_cfg $<
432459

433460
# Procedural macros can only be used with the `rustc` that compiled it.
434-
$(obj)/$(libmacros_name): $(src)/macros/lib.rs FORCE
461+
$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib FORCE
435462
+$(call if_changed_dep,rustc_procmacro)
436463

437464
$(obj)/$(libpin_init_internal_name): private rustc_target_flags = --cfg kernel

0 commit comments

Comments
 (0)