[PATCH] rust: kbuild: Replace and dissolve procmacro-extension variable
From: Nicolas Schier
Date: Tue Jun 16 2026 - 07:34:09 EST
Use make's $(suffix) function [1] and substitution reference [2] instead
of $(patsubst) to extract crate names for rust procmacro targets. As
there is only one user of the procmacro-extension variable, do the crate
name extraction in-place and remove procmacro-extension.
The procmacro-extension variable is used to record the binary file
suffix of dynamically loadable rust libraries -- which is 'so' on Linux
and others and 'dylib' in MacOS -- to remove that very suffix from a
target file name for reconstructing the corresponding crate name in
cmd_rustc_procmacro. Extracting the crate name from the target name
in-place is shorter and reduces complexity.
Link: https://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html # [1]
Link: https://www.gnu.org/software/make/manual/html_node/Substitution-Refs.html # [2]
Signed-off-by: Nicolas Schier <n.schier@xxxxxxxxx>
---
Link: https://lore.kernel.org/linux-kbuild/CANiq72nmPPF=6AUp5mcDJVni80ORQr0AQ-4uCZaE+CzB5kV=eg@xxxxxxxxxxxxxx/
---
rust/Makefile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/rust/Makefile b/rust/Makefile
index 63b1e355321d..30f882ba7620 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -50,7 +50,6 @@ endif
ifdef CONFIG_RUST
procmacro-name = $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name $(1) --crate-type proc-macro - </dev/null)
-procmacro-extension := $(patsubst libname.%,%,$(call procmacro-name,name))
libzerocopy_derive_name := $(call procmacro-name,zerocopy_derive)
libmacros_name := $(call procmacro-name,macros)
@@ -598,7 +597,7 @@ quiet_cmd_rustc_procmacro = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET))
-Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \
--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
--crate-type proc-macro -L$(objtree)/$(obj) \
- --crate-name $(patsubst lib%.$(procmacro-extension),%,$(notdir $@)) \
+ --crate-name $(basename $(@F:lib%=%)) \
@$(objtree)/include/generated/rustc_cfg $<
# Procedural macros can only be used with the `rustc` that compiled it.
---
base-commit: b3f94b2b3f3e51ab880a51fc6510e1dafba654ed
change-id: 20260611-rust-kbuild-replace-procmacro-extension-22c459a24382
Best regards,
--
Nicolas Schier