From: Miguel Ojeda <ojeda@kernel.org>
To: Miguel Ojeda <ojeda@kernel.org>,
Alex Gaynor <alex.gaynor@gmail.com>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nicolas@fjasle.eu>
Cc: "Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org,
linux-kernel@vger.kernel.org, patches@lists.linux.dev
Subject: [PATCH 18/18] rust: syn: enable support in kbuild
Date: Mon, 10 Nov 2025 10:50:23 +0100 [thread overview]
Message-ID: <20251110095025.1475896-19-ojeda@kernel.org> (raw)
In-Reply-To: <20251110095025.1475896-1-ojeda@kernel.org>
With all the new files in place and ready from the new crate, enable
the support for it in the build system.
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
Makefile | 1 +
rust/Makefile | 39 +++++++++++++++++++++++++++----
scripts/generate_rust_analyzer.py | 7 ++++++
3 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index f1b38b7fed1e..5364b3ad3600 100644
--- a/Makefile
+++ b/Makefile
@@ -1833,6 +1833,7 @@ rustfmt:
\( \
-path $(srctree)/rust/proc-macro2 \
-o -path $(srctree)/rust/quote \
+ -o -path $(srctree)/rust/syn \
\) -prune -o \
-type f -a -name '*.rs' -a ! -name '*generated*' -print \
| xargs $(RUSTFMT) $(rustfmt_flags)
diff --git a/rust/Makefile b/rust/Makefile
index 801a8cbf3bdd..984aec608c27 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -27,7 +27,7 @@ endif
obj-$(CONFIG_RUST) += exports.o
-always-$(CONFIG_RUST) += libproc_macro2.rlib libquote.rlib
+always-$(CONFIG_RUST) += libproc_macro2.rlib libquote.rlib libsyn.rlib
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c
@@ -101,6 +101,22 @@ quote-flags := \
--extern proc_macro2 \
$(call cfgs-to-flags,$(quote-cfgs))
+# `extra-traits`, `fold` and `visit` may be enabled if needed.
+syn-cfgs := \
+ feature="clone-impls" \
+ feature="derive" \
+ feature="full" \
+ feature="parsing" \
+ feature="printing" \
+ feature="proc-macro" \
+ feature="visit-mut"
+
+syn-flags := \
+ --cap-lints=allow \
+ --extern proc_macro2 \
+ --extern quote \
+ $(call cfgs-to-flags,$(syn-cfgs))
+
# `rustdoc` did not save the target modifiers, thus workaround for
# the time being (https://github.com/rust-lang/rust/issues/144521).
rustdoc_modifiers_workaround := $(if $(call rustc-min-version,108800),-Cunsafe-allow-abi-mismatch=fixed-x18)
@@ -164,11 +180,16 @@ rustdoc-quote: private skip_flags = $(quote-skip_flags)
rustdoc-quote: $(src)/quote/lib.rs rustdoc-clean rustdoc-proc_macro2 FORCE
+$(call if_changed,rustdoc)
+rustdoc-syn: private rustdoc_host = yes
+rustdoc-syn: private rustc_target_flags = $(syn-flags)
+rustdoc-syn: $(src)/syn/lib.rs rustdoc-clean rustdoc-quote FORCE
+ +$(call if_changed,rustdoc)
+
rustdoc-macros: private rustdoc_host = yes
rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
--extern proc_macro
rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean rustdoc-proc_macro2 \
- rustdoc-quote FORCE
+ rustdoc-quote rustdoc-syn FORCE
+$(call if_changed,rustdoc)
# Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should
@@ -240,6 +261,10 @@ rusttestlib-quote: private rustc_target_flags = $(quote-flags)
rusttestlib-quote: $(src)/quote/lib.rs rusttestlib-proc_macro2 FORCE
+$(call if_changed,rustc_test_library)
+rusttestlib-syn: private rustc_target_flags = $(syn-flags)
+rusttestlib-syn: $(src)/syn/lib.rs rusttestlib-quote FORCE
+ +$(call if_changed,rustc_test_library)
+
rusttestlib-macros: private rustc_target_flags = --extern proc_macro
rusttestlib-macros: private rustc_test_library_proc = yes
rusttestlib-macros: $(src)/macros/lib.rs FORCE
@@ -497,19 +522,24 @@ $(obj)/libquote.rlib: private rustc_target_flags = $(quote-flags)
$(obj)/libquote.rlib: $(src)/quote/lib.rs $(obj)/libproc_macro2.rlib FORCE
+$(call if_changed_dep,rustc_hostlibrary)
+$(obj)/libsyn.rlib: private skip_clippy = 1
+$(obj)/libsyn.rlib: private rustc_target_flags = $(syn-flags)
+$(obj)/libsyn.rlib: $(src)/syn/lib.rs $(obj)/libquote.rlib FORCE
+ +$(call if_changed_dep,rustc_hostlibrary)
+
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
cmd_rustc_procmacro = \
$(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \
-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
-Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \
--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
- --crate-type proc-macro \
+ --crate-type proc-macro -L$(objtree)/$(obj) \
--crate-name $(patsubst lib%.$(libmacros_extension),%,$(notdir $@)) \
@$(objtree)/include/generated/rustc_cfg $<
# Procedural macros can only be used with the `rustc` that compiled it.
$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib \
- $(obj)/libquote.rlib FORCE
+ $(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
+$(call if_changed_dep,rustc_procmacro)
$(obj)/$(libpin_init_internal_name): private rustc_target_flags = --cfg kernel
@@ -534,6 +564,7 @@ rust-analyzer:
--cfgs='core=$(core-cfgs)' $(core-edition) \
--cfgs='proc_macro2=$(proc_macro2-cfgs)' \
--cfgs='quote=$(quote-cfgs)' \
+ --cfgs='syn=$(syn-cfgs)' \
$(realpath $(srctree)) $(realpath $(objtree)) \
$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
> rust-project.json
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 4faf153ed2ee..5b6f7b8d6918 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -100,6 +100,13 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
cfg=crates_cfgs["quote"],
)
+ append_crate(
+ "syn",
+ srctree / "rust" / "syn" / "lib.rs",
+ ["proc_macro", "proc_macro2", "quote"],
+ cfg=crates_cfgs["syn"],
+ )
+
append_crate(
"macros",
srctree / "rust" / "macros" / "lib.rs",
--
2.51.2
next prev parent reply other threads:[~2025-11-10 9:52 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-10 9:50 [PATCH 00/18] `syn` support Miguel Ojeda
2025-11-10 9:50 ` [PATCH 01/18] rust: condvar: avoid `pub` in example Miguel Ojeda
2025-11-10 10:24 ` Alice Ryhl
2025-11-10 11:10 ` Miguel Ojeda
2025-11-10 9:50 ` [PATCH 02/18] rust: kbuild: introduce `core-flags` and `core-skip_flags` Miguel Ojeda
2025-11-10 10:19 ` Miguel Ojeda
2025-11-10 11:50 ` Alice Ryhl
2025-11-10 10:27 ` Alice Ryhl
2025-11-10 19:18 ` John Hubbard
2025-11-12 11:13 ` Miguel Ojeda
2025-11-10 9:50 ` [PATCH 03/18] rust: kbuild: simplify `--cfg` handling Miguel Ojeda
2025-11-10 10:33 ` Alice Ryhl
2025-11-10 9:50 ` [PATCH 04/18] rust: kbuild: add host library support Miguel Ojeda
2025-11-10 10:43 ` Alice Ryhl
2025-11-10 11:17 ` Miguel Ojeda
2025-11-10 9:50 ` [PATCH 05/18] rust: proc-macro2: import crate Miguel Ojeda
2025-11-10 9:50 ` [PATCH 06/18] rust: proc-macro2: add SPDX License Identifiers Miguel Ojeda
2025-11-10 9:50 ` [PATCH 07/18] rust: proc-macro2: remove `unicode_ident` dependency Miguel Ojeda
2025-11-10 10:50 ` Alice Ryhl
2025-11-10 9:50 ` [PATCH 08/18] rust: proc-macro2: add `README.md` Miguel Ojeda
2025-11-10 10:52 ` Alice Ryhl
2025-11-10 9:50 ` [PATCH 09/18] rust: proc-macro2: enable support in kbuild Miguel Ojeda
2025-11-10 11:38 ` Alice Ryhl
2025-11-10 13:10 ` Gary Guo
2025-11-10 13:28 ` Miguel Ojeda
2025-11-10 13:34 ` Alice Ryhl
2025-11-10 19:34 ` John Hubbard
2025-11-12 11:14 ` Miguel Ojeda
2025-11-24 19:36 ` John Hubbard
2025-11-24 20:00 ` Miguel Ojeda
2025-11-24 20:21 ` John Hubbard
2025-11-10 9:50 ` [PATCH 10/18] rust: quote: import crate Miguel Ojeda
2025-11-10 9:50 ` [PATCH 11/18] rust: quote: add SPDX License Identifiers Miguel Ojeda
2025-11-10 9:50 ` [PATCH 12/18] rust: quote: add `README.md` Miguel Ojeda
2025-11-10 9:50 ` [PATCH 13/18] rust: quote: enable support in kbuild Miguel Ojeda
2025-11-10 11:44 ` Alice Ryhl
2025-11-10 13:13 ` Gary Guo
2025-11-10 13:22 ` Miguel Ojeda
2025-11-10 13:35 ` Alice Ryhl
2025-11-10 9:50 ` [PATCH 14/18] rust: syn: import crate Miguel Ojeda
2025-11-10 10:26 ` Miguel Ojeda
2025-11-10 9:50 ` [PATCH 15/18] rust: syn: add SPDX License Identifiers Miguel Ojeda
2025-11-10 9:50 ` [PATCH 16/18] rust: syn: remove `unicode-ident` dependency Miguel Ojeda
2025-11-10 11:47 ` Alice Ryhl
2025-11-10 9:50 ` [PATCH 17/18] rust: syn: add `README.md` Miguel Ojeda
2025-11-10 11:47 ` Alice Ryhl
2025-11-10 9:50 ` Miguel Ojeda [this message]
2025-11-10 11:49 ` [PATCH 18/18] rust: syn: enable support in kbuild Alice Ryhl
2025-11-10 13:38 ` Miguel Ojeda
2025-11-10 13:42 ` Alice Ryhl
2025-11-10 19:43 ` John Hubbard
2025-11-10 13:59 ` [PATCH 00/18] `syn` support Gary Guo
2025-11-10 14:20 ` Miguel Ojeda
2025-11-21 4:37 ` Jesung Yang
2025-11-21 5:36 ` Miguel Ojeda
2025-11-21 9:08 ` Jesung Yang
2025-11-23 12:50 ` Miguel Ojeda
2025-11-23 22:46 ` Jesung Yang
2025-11-10 15:59 ` Jonathan Corbet
2025-11-10 16:27 ` Miguel Ojeda
2025-11-10 17:04 ` Benno Lossin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251110095025.1475896-19-ojeda@kernel.org \
--to=ojeda@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nathan@kernel.org \
--cc=nicolas@fjasle.eu \
--cc=patches@lists.linux.dev \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.