commit:     94de850364cc06256d3824871bb12f9612706a26
Author:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 20 08:56:30 2025 +0000
Commit:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Tue Dec 30 11:26:11 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=94de8503

cargo.eclass: Build with --target for non-native multilib ABIs

Ebuilds were having to explicitly pass --target to work around this.

Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>

 eclass/cargo.eclass | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index 5c2b89b6a718..cbde35be727b 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -453,13 +453,22 @@ _cargo_gen_git_config() {
        fi
 }
 
+# @FUNCTION: _cargo_needs_target
+# @INTERNAL
+# @DESCRIPTION:
+# Cargo does not apply flags to the build host when --target is given, even if
+# it is the native target, so only pass it when actually needed.
+_cargo_needs_target() {
+       tc-is-cross-compiler || { has multilib-build ${INHERITED} && ! 
multilib_is_native_abi; }
+}
+
 # @FUNCTION: cargo_target_dir
 # @DESCRIPTION:
 # Return the directory within target that contains the build, e.g.
 # target/aarch64-unknown-linux-gnu/release.
 cargo_target_dir() {
        local abi
-       tc-is-cross-compiler && abi=/$(rust_abi)
+       _cargo_needs_target && abi=/$(rust_abi)
        echo "${CARGO_TARGET_DIR:-target}${abi}/$(usex debug debug release)"
 }
 
@@ -776,7 +785,7 @@ cargo_env() {
 
                # Only tell Cargo to cross-compile when actually needed to 
avoid the
                # aforementioned build host vs target flag separation issue.
-               tc-is-cross-compiler || unset CARGO_BUILD_TARGET
+               _cargo_needs_target || unset CARGO_BUILD_TARGET
 
                "${@}"
        )

Reply via email to