Skip to content

Commit c9ac20b

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 <ojeda@kernel.org>
1 parent 5704ae4 commit c9ac20b

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-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: 28 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,16 @@ 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+
74+
# `feature(...)`s stable since Rust 1.79.0.
75+
proc_macro2-flags := \
76+
--cap-lints=allow \
77+
-Zcrate-attr='feature(proc_macro_byte_character,proc_macro_c_str_literals)' \
78+
$(proc_macro2-cfgs)
79+
6880
# `rustdoc` did not save the target modifiers, thus workaround for
6981
# the time being (https://github.com/rust-lang/rust/issues/144521).
7082
rustdoc_modifiers_workaround := $(if $(call rustc-min-version,108800),-Cunsafe-allow-abi-mismatch=fixed-x18)
@@ -114,10 +126,15 @@ rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
114126
$(Q)for f in $(rustdoc_output)/static.files/rustdoc-*.css; do \
115127
echo ".logo-container > img { object-fit: contain; }" >> $$f; done
116128

129+
rustdoc-proc_macro2: private rustdoc_host = yes
130+
rustdoc-proc_macro2: private rustc_target_flags = $(proc_macro2-flags)
131+
rustdoc-proc_macro2: $(src)/proc-macro2/lib.rs rustdoc-clean FORCE
132+
+$(call if_changed,rustdoc)
133+
117134
rustdoc-macros: private rustdoc_host = yes
118135
rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
119136
--extern proc_macro
120-
rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean FORCE
137+
rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean rustdoc-proc_macro2 FORCE
121138
+$(call if_changed,rustdoc)
122139

123140
# Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should
@@ -174,6 +191,10 @@ rusttestlib-build_error: $(src)/build_error.rs FORCE
174191
rusttestlib-ffi: $(src)/ffi.rs FORCE
175192
+$(call if_changed,rustc_test_library)
176193

194+
rusttestlib-proc_macro2: private rustc_target_flags = $(proc_macro2-flags)
195+
rusttestlib-proc_macro2: $(src)/proc-macro2/lib.rs FORCE
196+
+$(call if_changed,rustc_test_library)
197+
177198
rusttestlib-macros: private rustc_target_flags = --extern proc_macro
178199
rusttestlib-macros: private rustc_test_library_proc = yes
179200
rusttestlib-macros: $(src)/macros/lib.rs FORCE
@@ -420,6 +441,11 @@ quiet_cmd_rustc_hostlibrary = $(RUSTC_OR_CLIPPY_QUIET) H $@
420441
mv $(objtree)/$(obj)/$(patsubst lib%.rlib,%,$(notdir $@)).d $(depfile); \
421442
sed -i '/^\#/d' $(depfile)
422443

444+
$(obj)/libproc_macro2.rlib: private skip_clippy = 1
445+
$(obj)/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags)
446+
$(obj)/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE
447+
+$(call if_changed_dep,rustc_hostlibrary)
448+
423449
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
424450
cmd_rustc_procmacro = \
425451
$(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \
@@ -431,7 +457,7 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
431457
@$(objtree)/include/generated/rustc_cfg $<
432458

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

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

0 commit comments

Comments
 (0)