[PATCH v2] rust: kbuild: Replace and dissolve procmacro-extension variable

Nicolas Schier <[email protected]>
Newsgroups gmane.linux.kbuild.devel,gmane.linux.kernel.rust,gmane.linux.kernel
Message-ID <20260617-rust-kbuild-replace-procmacro-extension-v2-1-667bdc3a6435@fritz.com>
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 <[email protected]>
Tested-by: Tamir Duberstein <[email protected]>
Signed-off-by: Nicolas Schier <[email protected]>
---
Link: https://lore.kernel.org/linux-kbuild/CANiq72nmPPF=6AUp5mcDJVni80ORQr0AQ-4uCZaE+CzB5kV=eg@mail.gmail.com/
---
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@fritz.com
---
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.