Skip to content

Commit 88de91c

Browse files
committed
rust: quote: 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. Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Gary Guo <gary@garyguo.net> Tested-by: Gary Guo <gary@garyguo.net> Tested-by: Jesung Yang <y.j3ms.n@gmail.com> Link: https://patch.msgid.link/20251124151837.2184382-15-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 51177f0 commit 88de91c

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,7 @@ rustfmt:
18341834
$(Q)find $(srctree) $(RCS_FIND_IGNORE) \
18351835
\( \
18361836
-path $(srctree)/rust/proc-macro2 \
1837+
-o -path $(srctree)/rust/quote \
18371838
\) -prune -o \
18381839
-type f -a -name '*.rs' -a ! -name '*generated*' -print \
18391840
| xargs $(RUSTFMT) $(rustfmt_flags)

rust/Makefile

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ endif
2727

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

30-
always-$(CONFIG_RUST) += libproc_macro2.rlib
30+
always-$(CONFIG_RUST) += libproc_macro2.rlib libquote.rlib
3131

3232
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs
3333
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c
@@ -89,6 +89,18 @@ proc_macro2-flags := \
8989
-Zcrate-attr='feature(proc_macro_byte_character,proc_macro_c_str_literals)' \
9090
$(call cfgs-to-flags,$(proc_macro2-cfgs))
9191

92+
quote-cfgs := \
93+
feature="proc-macro"
94+
95+
quote-skip_flags := \
96+
--edition=2021
97+
98+
quote-flags := \
99+
--edition=2018 \
100+
--cap-lints=allow \
101+
--extern proc_macro2 \
102+
$(call cfgs-to-flags,$(quote-cfgs))
103+
92104
# `rustdoc` did not save the target modifiers, thus workaround for
93105
# the time being (https://github.com/rust-lang/rust/issues/144521).
94106
rustdoc_modifiers_workaround := $(if $(call rustc-min-version,108800),-Cunsafe-allow-abi-mismatch=fixed-x18)
@@ -143,10 +155,17 @@ rustdoc-proc_macro2: private rustc_target_flags = $(proc_macro2-flags)
143155
rustdoc-proc_macro2: $(src)/proc-macro2/lib.rs rustdoc-clean FORCE
144156
+$(call if_changed,rustdoc)
145157

158+
rustdoc-quote: private rustdoc_host = yes
159+
rustdoc-quote: private rustc_target_flags = $(quote-flags)
160+
rustdoc-quote: private skip_flags = $(quote-skip_flags)
161+
rustdoc-quote: $(src)/quote/lib.rs rustdoc-clean rustdoc-proc_macro2 FORCE
162+
+$(call if_changed,rustdoc)
163+
146164
rustdoc-macros: private rustdoc_host = yes
147165
rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
148166
--extern proc_macro
149-
rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean rustdoc-proc_macro2 FORCE
167+
rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean rustdoc-proc_macro2 \
168+
rustdoc-quote FORCE
150169
+$(call if_changed,rustdoc)
151170

152171
# Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should
@@ -207,6 +226,11 @@ rusttestlib-proc_macro2: private rustc_target_flags = $(proc_macro2-flags)
207226
rusttestlib-proc_macro2: $(src)/proc-macro2/lib.rs FORCE
208227
+$(call if_changed,rustc_test_library)
209228

229+
rusttestlib-quote: private skip_flags = $(quote-skip_flags)
230+
rusttestlib-quote: private rustc_target_flags = $(quote-flags)
231+
rusttestlib-quote: $(src)/quote/lib.rs rusttestlib-proc_macro2 FORCE
232+
+$(call if_changed,rustc_test_library)
233+
210234
rusttestlib-macros: private rustc_target_flags = --extern proc_macro
211235
rusttestlib-macros: private rustc_test_library_proc = yes
212236
rusttestlib-macros: $(src)/macros/lib.rs FORCE
@@ -458,6 +482,12 @@ $(obj)/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags)
458482
$(obj)/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE
459483
+$(call if_changed_dep,rustc_procmacrolibrary)
460484

485+
$(obj)/libquote.rlib: private skip_clippy = 1
486+
$(obj)/libquote.rlib: private skip_flags = $(quote-skip_flags)
487+
$(obj)/libquote.rlib: private rustc_target_flags = $(quote-flags)
488+
$(obj)/libquote.rlib: $(src)/quote/lib.rs $(obj)/libproc_macro2.rlib FORCE
489+
+$(call if_changed_dep,rustc_procmacrolibrary)
490+
461491
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
462492
cmd_rustc_procmacro = \
463493
$(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \
@@ -469,7 +499,8 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
469499
@$(objtree)/include/generated/rustc_cfg $<
470500

471501
# Procedural macros can only be used with the `rustc` that compiled it.
472-
$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib FORCE
502+
$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib \
503+
$(obj)/libquote.rlib FORCE
473504
+$(call if_changed_dep,rustc_procmacro)
474505

475506
$(obj)/$(libpin_init_internal_name): private rustc_target_flags = --cfg kernel
@@ -493,6 +524,7 @@ rust-analyzer:
493524
$(Q)MAKEFLAGS= $(srctree)/scripts/generate_rust_analyzer.py \
494525
--cfgs='core=$(core-cfgs)' $(core-edition) \
495526
--cfgs='proc_macro2=$(proc_macro2-cfgs)' \
527+
--cfgs='quote=$(quote-cfgs)' \
496528
$(realpath $(srctree)) $(realpath $(objtree)) \
497529
$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
498530
> rust-project.json

scripts/generate_rust_analyzer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ def append_sysroot_crate(
9393
cfg=crates_cfgs["proc_macro2"],
9494
)
9595

96+
append_crate(
97+
"quote",
98+
srctree / "rust" / "quote" / "lib.rs",
99+
["alloc", "proc_macro", "proc_macro2"],
100+
cfg=crates_cfgs["quote"],
101+
)
102+
96103
append_crate(
97104
"macros",
98105
srctree / "rust" / "macros" / "lib.rs",

0 commit comments

Comments
 (0)