From: James Le Cuirot <chewi@gentoo.org>
To: gentoo-dev <gentoo-dev@lists.gentoo.org>
Cc: James Le Cuirot <chewi@gentoo.org>
Subject: [gentoo-dev] [PATCH 2/2] cargo.eclass: Enable cross-compiling by setting environment variables
Date: Fri, 7 Jun 2024 17:59:25 +0100 [thread overview]
Message-ID: <20240607170027.15760-2-chewi@gentoo.org> (raw)
In-Reply-To: <20240607170027.15760-1-chewi@gentoo.org>
CARGO_BUILD_TARGET and CARGO_TARGET_<triple>_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 <chewi@gentoo.org>
---
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
prev parent reply other threads:[~2024-06-07 17:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-07 16:59 [gentoo-dev] [PATCH 1/2] cargo.eclass: Drop EAPI 7 support James Le Cuirot
2024-06-07 16:59 ` James Le Cuirot [this message]
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=20240607170027.15760-2-chewi@gentoo.org \
--to=chewi@gentoo.org \
--cc=gentoo-dev@lists.gentoo.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