public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: Mohamad Alsadhan <mo@sdhn.cc>
To: nathan@kernel.org, nsc@kernel.org
Cc: ojeda@kernel.org, gary@garyguo.net, linux-kbuild@vger.kernel.org,
	rust-for-linux@vger.kernel.org, Mohamad Alsadhan <mo@sdhn.cc>,
	Yoann Congal <yoann.congal@smile.fr>
Subject: [PATCH v2] kbuild: host: use single executable for rustc -C linker
Date: Fri, 27 Feb 2026 16:27:13 +0300	[thread overview]
Message-ID: <20260227132713.23106-1-mo@sdhn.cc> (raw)
In-Reply-To: <20260225102819.16553-1-mo@sdhn.cc>

rustc's -C linker= option expects a single executable path. When
HOSTCC contains a wrapper (e.g. "ccache gcc"), passing
-Clinker=$(HOSTCC) results in the shell splitting the value into
multiple words, and rustc interprets the additional word as an
input filename:

  error: multiple input filenames provided ...

Introduce HOSTRUSTC_LD to select the linker executable for host Rust
tools. When HOSTCC expands to multiple arguments and HOSTRUSTC_LD is
not set, fall back to the last word of HOSTCC and warn. Users needing
wrapper semantics can point HOSTRUSTC_LD at a wrapper script.

Closes: https://github.com/Rust-for-Linux/linux/issues/1224
Suggested-by: Yoann Congal <yoann.congal@smile.fr>

Acked-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
---
v1 -> v2:
  - Rename HOSTRUSTC_LINKER to HOSTRUSTC_LD for consistency
  - Introduce explicit HOSTRUSTC_LD override
  - Warn when falling back due to multi-argument HOSTCC
  - Error out if a user-specified HOSTRUSTC_LD is not an executable

v1: https://lore.kernel.org/all/20260225102819.16553-1-mo@sdhn.cc/
---
 scripts/Makefile.host | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/scripts/Makefile.host b/scripts/Makefile.host
index c1dedf646..f029f3f0c 100644
--- a/scripts/Makefile.host
+++ b/scripts/Makefile.host
@@ -87,11 +87,30 @@ hostcxx_flags  = -Wp,-MMD,$(depfile) \
                  $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
                  $(HOSTCXXFLAGS_$(target-stem).o)
 
+# rustc's `-C linker=` expects a single executable path, not a command line.
+# HOSTCC may be a multi-word command when wrapped (e.g. "ccache gcc"), which
+# would otherwise be split by the shell and mis-parsed by rustc.
+#
+# Allow users to override the linker used by host Rust tools via HOSTRUSTC_LD.
+# If HOSTCC is multi-word and HOSTRUSTC_LD is not set, default to the last
+# word of HOSTCC (typically the underlying compiler) and emit a warning.
+ifndef HOSTRUSTC_LD
+HOSTRUSTC_LD := $(HOSTCC)
+endif
+
+ifneq ($(words $(HOSTRUSTC_LD)),1)
+ifneq ($(filter command\ line environment,$(origin HOSTRUSTC_LD)),)
+$(error HOSTRUSTC_LD must be a single executable for rustc -C linker=. Got: "$(HOSTRUSTC_LD)")
+endif
+HOSTRUSTC_LD := $(lastword $(HOSTCC))
+$(warning HOSTCC expands to multiple arguments. Trying HOSTRUSTC_LD="$(HOSTRUSTC_LD)" for rustc. Set HOSTRUSTC_LD to override.)
+endif
+
 # `--out-dir` is required to avoid temporaries being created by `rustc` in the
 # current working directory, which may be not accessible in the out-of-tree
 # modules case.
 hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \
-		 -Clinker-flavor=gcc -Clinker=$(HOSTCC) \
+		 -Clinker-flavor=gcc -Clinker=$(HOSTRUSTC_LD) \
 		 -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
                  $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
                  $(HOSTRUSTFLAGS_$(target-stem))
-- 
2.52.0


  parent reply	other threads:[~2026-02-27 13:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 10:28 [PATCH] kbuild: host: use single executable for rustc -C linker Mohamad Alsadhan
2026-02-25 21:45 ` Nathan Chancellor
2026-02-26 10:12 ` Gary Guo
2026-02-27 13:27 ` Mohamad Alsadhan [this message]
2026-03-11  5:56   ` [PATCH v2] " Miguel Ojeda
2026-03-11  9:35     ` Mohamad Alsadhan
2026-03-11 14:02       ` Miguel Ojeda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260227132713.23106-1-mo@sdhn.cc \
    --to=mo@sdhn.cc \
    --cc=gary@garyguo.net \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=yoann.congal@smile.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox