Skip to content

Commit 7dbe46c

Browse files
committed
rust: kbuild: add proc macro library support
Add the proc macro library rule that produces `.rlib` files to be used by proc macros such as the `macros` crate. Reviewed-by: Gary Guo <gary@garyguo.net> Tested-by: Gary Guo <gary@garyguo.net> Tested-by: Jesung Yang <y.j3ms.n@gmail.com> Link: https://patch.msgid.link/20251124151837.2184382-4-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 1181c97 commit 7dbe46c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
*.o.*
4242
*.patch
4343
*.pyc
44+
*.rlib
4445
*.rmeta
4546
*.rpm
4647
*.rsi

rust/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,16 @@ $(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
421421
$(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
422422
$(call if_changed,exports)
423423

424+
quiet_cmd_rustc_procmacrolibrary = $(RUSTC_OR_CLIPPY_QUIET) PL $@
425+
cmd_rustc_procmacrolibrary = \
426+
$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
427+
$(filter-out $(skip_flags),$(rust_common_flags) $(rustc_target_flags)) \
428+
--emit=dep-info,link --crate-type rlib -O \
429+
--out-dir $(objtree)/$(obj) -L$(objtree)/$(obj) \
430+
--crate-name $(patsubst lib%.rlib,%,$(notdir $@)) $<; \
431+
mv $(objtree)/$(obj)/$(patsubst lib%.rlib,%,$(notdir $@)).d $(depfile); \
432+
sed -i '/^\#/d' $(depfile)
433+
424434
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
425435
cmd_rustc_procmacro = \
426436
$(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \

0 commit comments

Comments
 (0)