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 D837C15817D for ; Fri, 7 Jun 2024 17:01:13 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5E76DE2A1A; Fri, 7 Jun 2024 17:00:45 +0000 (UTC) Received: from smtp.gentoo.org (smtp.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)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 13232E2A15 for ; Fri, 7 Jun 2024 17:00:45 +0000 (UTC) From: James Le Cuirot To: gentoo-dev Cc: James Le Cuirot Subject: [gentoo-dev] [PATCH 2/2] cargo.eclass: Enable cross-compiling by setting environment variables Date: Fri, 7 Jun 2024 17:59:25 +0100 Message-ID: <20240607170027.15760-2-chewi@gentoo.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240607170027.15760-1-chewi@gentoo.org> References: <20240607170027.15760-1-chewi@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: 5e2ec13e-877d-4413-ac79-5159f6528f71 X-Archives-Hash: 44040115cfbd84b526881a4217591c63 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 --- eclass/cargo.eclass | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index ef55e0613e61c..9390d488f8327 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -38,7 +38,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}" @@ -529,6 +529,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" -- 2.45.1