From: Dmitrii Dolgov <9erthalion6@gmail.com>
To: linux-perf-users@vger.kernel.org, Ian Rogers <irogers@google.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>,
Miguel Ojeda <ojeda@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Dmitrii Dolgov <9erthalion6@gmail.com>
Subject: [PATCH v1] tools build: Fix rust cross compilation
Date: Thu, 12 Feb 2026 19:57:14 +0100 [thread overview]
Message-ID: <20260212185810.648364-1-9erthalion6@gmail.com> (raw)
Currently no target is specified to compile rust code when needed, which
breaks cross compilation. Detect required target and pass it via
rust_flags to the compiler.
Note that CROSS_COMPILE might be different from what rust compiler
expects, since it may omit the target vendor value, e.g.
"aarch64-linux-gnu" instead of "aarch64-unknown-linux-gnu". Thus provide
an explicit RUST_TARGET_ARCH, and if not specified, try to match
the CROSS_COMPILE value.
Tested using arm64 cross-compilation example from [1].
[1]: https://perfwiki.github.io/main/arm64-cross-compilation-dockerfile/
Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com>
---
tools/build/Build.include | 9 +++++++++
tools/perf/Makefile.config | 18 ++++++++++++++++++
tools/perf/Makefile.perf | 4 +++-
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/tools/build/Build.include b/tools/build/Build.include
index e45b2eb0d24..cd0baa7a168 100644
--- a/tools/build/Build.include
+++ b/tools/build/Build.include
@@ -98,6 +98,15 @@ c_flags_2 = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(c_flags_1))
c_flags = $(filter-out $(CFLAGS_REMOVE_$(obj)), $(c_flags_2))
cxx_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CXXFLAGS) -D"BUILD_STR(s)=\#s" $(CXXFLAGS_$(basetarget).o) $(CXXFLAGS_$(obj))
+###
+# Rust flags to be used on rule definition, includes:
+# - global $(RUST_FLAGS)
+# - per target Rust flags
+# - per object Rust flags
+rust_flags_1 = $(RUST_FLAGS) $(RUST_FLAGS_$(basetarget).o) $(RUST_FLAGS_$(obj))
+rust_flags_2 = $(filter-out $(RUST_FLAGS_REMOVE_$(basetarget).o), $(rust_flags_1))
+rust_flags = $(filter-out $(RUST_FLAGS_REMOVE_$(obj)), $(rust_flags_2))
+
###
## HOSTCC C flags
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index a8dc72cfe48..9b164b442da 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -1163,6 +1163,24 @@ ifndef NO_RUST
CFLAGS += -DHAVE_RUST_SUPPORT
$(call detected,CONFIG_RUST_SUPPORT)
endif
+
+ ifneq ($(CROSS_COMPILE),)
+ ifneq ($(RUST_TARGET_ARCH),)
+ RUST_FLAGS += --target=$(RUST_TARGET_ARCH)
+ else
+ # CROSS_COMPILE specifies the target triple, which may not match what
+ # Rust expects, e.g. it can omit the target vendor if C toolchain is
+ # used. For example the value can be aarch64-linux-gnu, where Rust uses
+ # aarch64-unknown-linux-gnu. Try to match that and insert an "unknown"
+ # vendor if omitted.
+ TRIPLE := $(subst -, ,$(CROSS_COMPILE:%-=%))
+ ifeq ($(words $(TRIPLE)),3)
+ RUST_FLAGS += --target=$(word 1,$(TRIPLE))-unknown-$(word 2,$(TRIPLE))-$(word 3,$(TRIPLE))
+ else
+ RUST_FLAGS += --target=$(CROSS_COMPILE:%-=%)
+ endif
+ endif
+ endif
endif
# Among the variables below, these:
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index a6d8ca3e923..621800e1716 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -17,6 +17,8 @@ include ../scripts/utilities.mak
#
# Define CROSS_COMPILE as prefix name of compiler if you want cross-builds.
#
+# Define RUST_TARGET_ARCH as rust target arch if you want cross-builds.
+#
# Define LIBPERL to enable perl script extension.
#
# Define NO_LIBPYTHON to disable python script extension.
@@ -271,7 +273,7 @@ ifeq ($(PYLINT),1)
PYLINT := $(shell which pylint 2> /dev/null)
endif
-export srctree OUTPUT RM CC CXX RUSTC LD AR CFLAGS CXXFLAGS V BISON FLEX AWK
+export srctree OUTPUT RM CC CXX RUSTC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK
export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT
include $(srctree)/tools/build/Makefile.include
base-commit: 5d1ab659fb93eed85d6d8b2937013360157032f4
--
2.52.0
next reply other threads:[~2026-02-12 18:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-12 18:57 Dmitrii Dolgov [this message]
2026-02-12 19:13 ` Miguel Ojeda
2026-02-12 19:18 ` Dmitry Dolgov
2026-02-13 19:12 Dmitrii Dolgov
2026-02-16 20:41 ` Miguel Ojeda
2026-02-17 8:22 ` Dmitry Dolgov
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=20260212185810.648364-1-9erthalion6@gmail.com \
--to=9erthalion6@gmail.com \
--cc=acme@kernel.org \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
--cc=ojeda@kernel.org \
/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
all inboxes | Powered by JetHome®