Skip to content

Commit 7374017

Browse files
committed
rust: syn: 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 <[email protected]> Reviewed-by: Gary Guo <[email protected]> Tested-by: Gary Guo <[email protected]> Tested-by: Jesung Yang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 1112ba8 commit 7374017

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

Makefile

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

rust/Makefile

Lines changed: 34 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 libquote.rlib
30+
always-$(CONFIG_RUST) += libproc_macro2.rlib libquote.rlib libsyn.rlib
3131

3232
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs
3333
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c
@@ -101,6 +101,22 @@ quote-flags := \
101101
--extern proc_macro2 \
102102
$(call cfgs-to-flags,$(quote-cfgs))
103103

104+
# `extra-traits`, `fold` and `visit` may be enabled if needed.
105+
syn-cfgs := \
106+
feature="clone-impls" \
107+
feature="derive" \
108+
feature="full" \
109+
feature="parsing" \
110+
feature="printing" \
111+
feature="proc-macro" \
112+
feature="visit-mut"
113+
114+
syn-flags := \
115+
--cap-lints=allow \
116+
--extern proc_macro2 \
117+
--extern quote \
118+
$(call cfgs-to-flags,$(syn-cfgs))
119+
104120
# `rustdoc` did not save the target modifiers, thus workaround for
105121
# the time being (https://github.com/rust-lang/rust/issues/144521).
106122
rustdoc_modifiers_workaround := $(if $(call rustc-min-version,108800),-Cunsafe-allow-abi-mismatch=fixed-x18)
@@ -161,11 +177,16 @@ rustdoc-quote: private skip_flags = $(quote-skip_flags)
161177
rustdoc-quote: $(src)/quote/lib.rs rustdoc-clean rustdoc-proc_macro2 FORCE
162178
+$(call if_changed,rustdoc)
163179

180+
rustdoc-syn: private rustdoc_host = yes
181+
rustdoc-syn: private rustc_target_flags = $(syn-flags)
182+
rustdoc-syn: $(src)/syn/lib.rs rustdoc-clean rustdoc-quote FORCE
183+
+$(call if_changed,rustdoc)
184+
164185
rustdoc-macros: private rustdoc_host = yes
165186
rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
166187
--extern proc_macro
167188
rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean rustdoc-proc_macro2 \
168-
rustdoc-quote FORCE
189+
rustdoc-quote rustdoc-syn FORCE
169190
+$(call if_changed,rustdoc)
170191

171192
# Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should
@@ -231,6 +252,10 @@ rusttestlib-quote: private rustc_target_flags = $(quote-flags)
231252
rusttestlib-quote: $(src)/quote/lib.rs rusttestlib-proc_macro2 FORCE
232253
+$(call if_changed,rustc_test_library)
233254

255+
rusttestlib-syn: private rustc_target_flags = $(syn-flags)
256+
rusttestlib-syn: $(src)/syn/lib.rs rusttestlib-quote FORCE
257+
+$(call if_changed,rustc_test_library)
258+
234259
rusttestlib-macros: private rustc_target_flags = --extern proc_macro
235260
rusttestlib-macros: private rustc_test_library_proc = yes
236261
rusttestlib-macros: $(src)/macros/lib.rs FORCE
@@ -488,6 +513,11 @@ $(obj)/libquote.rlib: private rustc_target_flags = $(quote-flags)
488513
$(obj)/libquote.rlib: $(src)/quote/lib.rs $(obj)/libproc_macro2.rlib FORCE
489514
+$(call if_changed_dep,rustc_procmacrolibrary)
490515

516+
$(obj)/libsyn.rlib: private skip_clippy = 1
517+
$(obj)/libsyn.rlib: private rustc_target_flags = $(syn-flags)
518+
$(obj)/libsyn.rlib: $(src)/syn/lib.rs $(obj)/libquote.rlib FORCE
519+
+$(call if_changed_dep,rustc_procmacrolibrary)
520+
491521
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
492522
cmd_rustc_procmacro = \
493523
$(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \
@@ -500,7 +530,7 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
500530

501531
# Procedural macros can only be used with the `rustc` that compiled it.
502532
$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib \
503-
$(obj)/libquote.rlib FORCE
533+
$(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
504534
+$(call if_changed_dep,rustc_procmacro)
505535

506536
$(obj)/$(libpin_init_internal_name): private rustc_target_flags = --cfg kernel
@@ -525,6 +555,7 @@ rust-analyzer:
525555
--cfgs='core=$(core-cfgs)' $(core-edition) \
526556
--cfgs='proc_macro2=$(proc_macro2-cfgs)' \
527557
--cfgs='quote=$(quote-cfgs)' \
558+
--cfgs='syn=$(syn-cfgs)' \
528559
$(realpath $(srctree)) $(realpath $(objtree)) \
529560
$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
530561
> rust-project.json

scripts/generate_rust_analyzer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ def append_sysroot_crate(
100100
cfg=crates_cfgs["quote"],
101101
)
102102

103+
append_crate(
104+
"syn",
105+
srctree / "rust" / "syn" / "lib.rs",
106+
["proc_macro", "proc_macro2", "quote"],
107+
cfg=crates_cfgs["syn"],
108+
)
109+
103110
append_crate(
104111
"macros",
105112
srctree / "rust" / "macros" / "lib.rs",

0 commit comments

Comments
 (0)