rust: add PROCMACROLDFLAGS
Subsystems (3)
PATCH 1/1 rust: add PROCMACROLDFLAGS
These are additional flags to be passed when linking proc macros for the Rust toolchain. If unset, it defaults to $(HOSTLDFLAGS).
This is needed because the list of flags to link hostprogs is not necessarily the same as the list of flags used to link libmacros.so. When we build proc macros, we need the latter, not the former. To distinguish between the two, introduce this new variable to stand out from HOSTLDFLAGS used to link other host progs.
--- Documentation/kbuild/kbuild.rst | 5 +++++ Makefile | 1 + rust/Makefile | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-)
Documentation/kbuild/kbuild.rst +5 -0
@@ -91,6 +91,11 @@ HOSTRUSTFLAGS ------------- Additional flags to be passed to $(HOSTRUSTC) when building host programs. +PROCMACROLDFLAGS +------------- +Additional flags to be passed when linking proc macros for the Rust toolchain. +If unset, it defaults to $(HOSTLDFLAGS). + HOSTLDFLAGS ----------- Additional flags to be passed when linking host programs.
Makefile +1 -0
@@ -469,6 +469,7 @@ KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \ -I $(srctree)/scripts/include KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \ -Zallow-features= $(HOSTRUSTFLAGS) +KBUILD_PROCMACROLDFLAGS := $(or $(PROCMACROLDFLAGS),$(HOSTLDFLAGS)) KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS) KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
rust/Makefile +1 -1
@@ -322,7 +322,7 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@ cmd_rustc_procmacro = \ $(RUSTC_OR_CLIPPY) $(rust_common_flags) \ -Clinker-flavor=gcc -Clinker=$(HOSTCC) \ - -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \ + -Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \ --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \ --crate-type proc-macro \ --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Alice Ryhl
reviewerQuoted 22 lines · HONG Yifan
These are additional flags to be passed when linking proc macros for the Rust toolchain. If unset, it defaults to $(HOSTLDFLAGS).
This is needed because the list of flags to link hostprogs is not necessarily the same as the list of flags used to link libmacros.so. When we build proc macros, we need the latter, not the former. To distinguish between the two, introduce this new variable to stand out from HOSTLDFLAGS used to link other host progs.
Signed-off-by HONG Yifan <[email protected]>--- Documentation/kbuild/kbuild.rst | 5 +++++ Makefile | 1 + rust/Makefile | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-)Documentation/kbuild/kbuild.rst +0
-0
Documentation/kbuild/kbuild.rst HOSTRUSTFLAGS · line 97
Quoted 7 lines
Documentation/kbuild/kbuild.rst +4
-0@@ -91,6 +91,11 @@ HOSTRUSTFLAGS ------------- Additional flags to be passed to $(HOSTRUSTC) when building host programs. +PROCMACROLDFLAGS +------------- +Additional flags to be passed when linking proc macros for the Rust toolchain. +If unset, it defaults to $(HOSTLDFLAGS).
It may be less confusing to say "when linking Rust proc macros" here. Saying "for the Rust toolchain" could be confusing, as the proc macros are "for" use with the various pieces of kernel source code. Most people would not think of them as being "for the toolchain".
If you want to mention the toolchain, you could add a sentence: "Since proc macros are loaded by rustc at build time, they must be linked in a way that is compatible with the rustc toolchain being used."
Alice
PATCH v2 1/1 rust: add PROCMACROLDFLAGS
These are additional flags to be passed when linking proc macros for the Rust toolchain. If unset, it defaults to $(HOSTLDFLAGS).
This is needed because the list of flags to link hostprogs is not necessarily the same as the list of flags used to link libmacros.so. When we build proc macros, we need the latter, not the former. To distinguish between the two, introduce this new variable to stand out from HOSTLDFLAGS used to link other host progs.
---
v1 -> v2: Updated text in kbuild.rst as suggested by [email protected].
Documentation/kbuild/kbuild.rst | 7 +++++++ Makefile | 1 + rust/Makefile | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-)
Documentation/kbuild/kbuild.rst +7 -0
@@ -91,6 +91,13 @@ HOSTRUSTFLAGS ------------- Additional flags to be passed to $(HOSTRUSTC) when building host programs. +PROCMACROLDFLAGS +------------- +Additional flags to be passed when linking Rust proc macros. Since proc macros +are loaded by rustc at build time, they must be linked in a way that is +compatible with the rustc toolchain being used. If unset, it defaults to +$(HOSTLDFLAGS). + HOSTLDFLAGS ----------- Additional flags to be passed when linking host programs.
Makefile +1 -0
@@ -469,6 +469,7 @@ KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \ -I $(srctree)/scripts/include KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \ -Zallow-features= $(HOSTRUSTFLAGS) +KBUILD_PROCMACROLDFLAGS := $(or $(PROCMACROLDFLAGS),$(HOSTLDFLAGS)) KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS) KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
rust/Makefile +1 -1
@@ -322,7 +322,7 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@ cmd_rustc_procmacro = \ $(RUSTC_OR_CLIPPY) $(rust_common_flags) \ -Clinker-flavor=gcc -Clinker=$(HOSTCC) \ - -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \ + -Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \ --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \ --crate-type proc-macro \ --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<
--
2.47.0.rc1.288.g06298d1525-goog
Quoted 11 lines · HONG Yifan
These are additional flags to be passed when linking proc macros for the Rust toolchain. If unset, it defaults to $(HOSTLDFLAGS).
This is needed because the list of flags to link hostprogs is not necessarily the same as the list of flags used to link libmacros.so. When we build proc macros, we need the latter, not the former. To distinguish between the two, introduce this new variable to stand out from HOSTLDFLAGS used to link other host progs.
Signed-off-by HONG Yifan <[email protected]>