[PATCH v2] rust: kbuild: Replace and dissolve procmacro-extension variable
From: Nicolas Schier
Date: Wed Jun 17 2026 - 10:10:27 EST
Use make's $(basename) 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]
Reviewed-by: Tamir Duberstein <tamird@xxxxxxxxxx>
Tested-by: Tamir Duberstein <tamird@xxxxxxxxxx>
Signed-off-by: Nicolas Schier <n.schier@xxxxxxxxx>
---
Link: https://lore.kernel.org/linux-kbuild/CANiq72nmPPF=6AUp5mcDJVni80ORQr0AQ-4uCZaE+CzB5kV=eg@xxxxxxxxxxxxxx/
---
Changes in v2:
* Let commit message reference correct make function
(suffix -> basename) (Tamir)
* Cc kbuild
* Link to v1: https://patch.msgid.link/20260616-rust-kbuild-replace-procmacro-extension-v1-1-cad72998faee@xxxxxxxxx
---
rust/Makefile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/rust/Makefile b/rust/Makefile
index a870d1616c71..73f0ec4a3e90 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)
@@ -599,7 +598,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