* [PATCH v1] rust: add PROCMACROLDFLAGS
@ 2024-10-17 20:01 HONG Yifan
2024-10-17 20:38 ` Alice Ryhl
0 siblings, 1 reply; 4+ messages in thread
From: HONG Yifan @ 2024-10-17 20:01 UTC (permalink / raw)
To: mmaurer, Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Jonathan Corbet, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl
Cc: HONG Yifan, kernel-team, linux-kbuild, linux-doc, linux-kernel,
rust-for-linux
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 <elsk@google.com>
---
Documentation/kbuild/kbuild.rst | 5 +++++
Makefile | 1 +
rust/Makefile | 2 +-
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst
index 1796b3eba37b..d9866394bd98 100644
--- a/Documentation/kbuild/kbuild.rst
+++ b/Documentation/kbuild/kbuild.rst
@@ -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.
diff --git a/Makefile b/Makefile
index b77ac70f8be4..89cdf0eca7de 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/rust/Makefile b/rust/Makefile
index 3678e79317f1..95ceaba35975 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v1] rust: add PROCMACROLDFLAGS
2024-10-17 20:01 [PATCH v1] rust: add PROCMACROLDFLAGS HONG Yifan
@ 2024-10-17 20:38 ` Alice Ryhl
2024-10-17 21:04 ` [PATCH v2] " HONG Yifan
0 siblings, 1 reply; 4+ messages in thread
From: Alice Ryhl @ 2024-10-17 20:38 UTC (permalink / raw)
To: HONG Yifan
Cc: mmaurer, Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Jonathan Corbet, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, kernel-team,
linux-kbuild, linux-doc, linux-kernel, rust-for-linux
On Thu, Oct 17, 2024 at 10:01 PM HONG Yifan <elsk@google.com> wrote:
>
> 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 <elsk@google.com>
> ---
> Documentation/kbuild/kbuild.rst | 5 +++++
> Makefile | 1 +
> rust/Makefile | 2 +-
> 3 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst
> index 1796b3eba37b..d9866394bd98 100644
> --- a/Documentation/kbuild/kbuild.rst
> +++ b/Documentation/kbuild/kbuild.rst
> @@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] rust: add PROCMACROLDFLAGS
2024-10-17 20:38 ` Alice Ryhl
@ 2024-10-17 21:04 ` HONG Yifan
2024-10-18 8:38 ` Alice Ryhl
0 siblings, 1 reply; 4+ messages in thread
From: HONG Yifan @ 2024-10-17 21:04 UTC (permalink / raw)
To: aliceryhl, Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Jonathan Corbet, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg
Cc: elsk, kernel-team, linux-doc, linux-kbuild, linux-kernel, mmaurer,
rust-for-linux
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 <elsk@google.com>
---
v1 -> v2: Updated text in kbuild.rst as suggested by aliceryhl@google.com.
Documentation/kbuild/kbuild.rst | 7 +++++++
Makefile | 1 +
rust/Makefile | 2 +-
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst
index 1796b3eba37b..5ba8c4afd44b 100644
--- a/Documentation/kbuild/kbuild.rst
+++ b/Documentation/kbuild/kbuild.rst
@@ -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.
diff --git a/Makefile b/Makefile
index b77ac70f8be4..89cdf0eca7de 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/rust/Makefile b/rust/Makefile
index 3678e79317f1..95ceaba35975 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] rust: add PROCMACROLDFLAGS
2024-10-17 21:04 ` [PATCH v2] " HONG Yifan
@ 2024-10-18 8:38 ` Alice Ryhl
0 siblings, 0 replies; 4+ messages in thread
From: Alice Ryhl @ 2024-10-18 8:38 UTC (permalink / raw)
To: HONG Yifan
Cc: Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Jonathan Corbet, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, kernel-team,
linux-doc, linux-kbuild, linux-kernel, mmaurer, rust-for-linux
On Thu, Oct 17, 2024 at 11:05 PM HONG Yifan <elsk@google.com> wrote:
>
> 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 <elsk@google.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-18 8:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-17 20:01 [PATCH v1] rust: add PROCMACROLDFLAGS HONG Yifan
2024-10-17 20:38 ` Alice Ryhl
2024-10-17 21:04 ` [PATCH v2] " HONG Yifan
2024-10-18 8:38 ` Alice Ryhl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox