From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id D0A3715817D for ; Wed, 12 Jun 2024 13:20:11 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DA16A2BC014; Wed, 12 Jun 2024 13:20:10 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id BB4972BC014 for ; Wed, 12 Jun 2024 13:20:10 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id DFA7533BE19 for ; Wed, 12 Jun 2024 13:20:09 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 4CA3C1C9B for ; Wed, 12 Jun 2024 13:20:08 +0000 (UTC) From: "James Le Cuirot" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "James Le Cuirot" Message-ID: <1718198281.375da3684e685c6fd8367ffcf37e090526d55e4d.chewi@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/cargo.eclass X-VCS-Directories: eclass/ X-VCS-Committer: chewi X-VCS-Committer-Name: James Le Cuirot X-VCS-Revision: 375da3684e685c6fd8367ffcf37e090526d55e4d X-VCS-Branch: master Date: Wed, 12 Jun 2024 13:20:08 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: c13395af-26a7-46df-8f17-5aed1a9bde63 X-Archives-Hash: fd1a4d044c5cae7d81b6c5971d385c95 commit: 375da3684e685c6fd8367ffcf37e090526d55e4d Author: James Le Cuirot gentoo org> AuthorDate: Fri May 31 21:49:47 2024 +0000 Commit: James Le Cuirot gentoo org> CommitDate: Wed Jun 12 13:18:01 2024 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=375da368 cargo.eclass: Enable cross-compiling by setting environment variables CARGO_BUILD_TARGET and CARGO_TARGET__LINKER are enough for pure Rust. The linker otherwise defaults to `cc`. This doesn't respect any linker specified in LDFLAGS, but this is also true for native builds. We would need to do something with RUSTFLAGS. The HOST_* variables are for the cc-rs crate, which is often used to build non-Rust code. It uses the usual variables (CC, CFLAGS, etc) for the target. Signed-off-by: James Le Cuirot gentoo.org> eclass/cargo.eclass | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index 72c740cda906..40d98211ce7f 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -34,7 +34,7 @@ case ${EAPI} in ;; esac -inherit flag-o-matic multiprocessing toolchain-funcs +inherit flag-o-matic multiprocessing rust-toolchain toolchain-funcs [[ ! ${CARGO_OPTIONAL} ]] && BDEPEND="${RUST_DEPEND}" @@ -525,6 +525,21 @@ cargo_src_compile() { filter-lto tc-export AR CC CXX PKG_CONFIG + if tc-is-cross-compiler; then + export CARGO_BUILD_TARGET=$(rust_abi) + local TRIPLE=${CARGO_BUILD_TARGET//-/_} + export CARGO_TARGET_"${TRIPLE^^}"_LINKER=$(tc-getCC) + + # Set vars for cc-rs crate. + tc-export_build_env + export \ + HOST_AR=$(tc-getBUILD_AR) + HOST_CC=$(tc-getBUILD_CC) + HOST_CXX=$(tc-getBUILD_CXX) + HOST_CFLAGS=${BUILD_CFLAGS} + HOST_CXXFLAGS=${BUILD_CXXFLAGS} + fi + set -- cargo build $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" einfo "${@}" "${@}" || die "cargo build failed"