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 234C915817D for ; Tue, 11 Jun 2024 13:45:22 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 30503E2ACB; Tue, 11 Jun 2024 13:44:58 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.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 D577AE2AC2 for ; Tue, 11 Jun 2024 13:44:57 +0000 (UTC) From: James Le Cuirot To: gentoo-dev Cc: James Le Cuirot Subject: [gentoo-dev] [PATCH v2 2/2] cargo.eclass: Enable cross-compiling by setting environment variables Date: Tue, 11 Jun 2024 14:41:56 +0100 Message-ID: <20240611134436.10245-2-chewi@gentoo.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240611134436.10245-1-chewi@gentoo.org> References: <20240611134436.10245-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: b6a8c38d-7677-4262-b2dd-dbfedf058d14 X-Archives-Hash: fc69625d3f694295319330cb2f0e544d 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 72c740cda9065..40d98211ce7f9 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" -- 2.45.1