summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatoro Mahri <matoro_gentoo@matoro.tk>2024-02-09 10:48:17 -0500
committerSam James <sam@gentoo.org>2024-02-10 07:49:17 +0000
commit869a67efcaedbf7d08fe16057466f58ac1f21a84 (patch)
treeb8d944eb302af8b530012de7283694f51a4bdd45 /dev-lang/rust/rust-1.74.1.ebuild
parentdev-libs/raft: drop 0.18.3, 0.20.0, 0.21.0 (diff)
downloadgentoo-869a67efcaedbf7d08fe16057466f58ac1f21a84.tar.gz
gentoo-869a67efcaedbf7d08fe16057466f58ac1f21a84.tar.bz2
gentoo-869a67efcaedbf7d08fe16057466f58ac1f21a84.zip
dev-lang/rust: crossdev support
This allows Rust to be cross-compiled with crossdev. This is the last item for bug 680652, closing it. Note that this is for a foreign CHOST, i.e., CBUILD != CHOST == CTARGET. It does not cover the scenario for CBUILD == CHOST != CTARGET(s), which is tracked separately in bug 679878. A number of changes were required in order to make this work: * Force USE=system-bootstrap, since we cannot specify the appropriate boostrap URL based on CBUILD in SRC_URI * LLVm is compiled twice as part of the build, once for host and once for target. However, the rust build uses the same settings from config.toml for both builds. Therefore we cannot override flags nor default-linker and must let rust choose them for us. * Set the appropriate build/host variables which correspond to CBUILD/CHOST. This works as expected. * Set PKG_CONFIG and OPENSSL_*_DIR variables; cargo needs these for some reason. * Enforce that LLVM_TARGETS is set correctly for both host and target arches. This uses the new llvm_tuple_to_target function, introduced in https://github.com/gentoo/gentoo/pull/33996 * Lastly a small patch to rust source is needed, to tell it to link with system libz. It's unclear why this scenario was excluded under cross-compile conditions in upstream rust. See: https://paste.sr.ht/~kchibisov/682321e0fd4a3ece4a4b7b71591896f5cd3cdb22 Bug: https://bugs.gentoo.org/679878 Closes: https://bugs.gentoo.org/680652 Signed-off-by: Matoro Mahri <matoro_gentoo@matoro.tk> Closes: https://github.com/gentoo/gentoo/pull/35246 Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'dev-lang/rust/rust-1.74.1.ebuild')
-rw-r--r--dev-lang/rust/rust-1.74.1.ebuild46
1 files changed, 35 insertions, 11 deletions
diff --git a/dev-lang/rust/rust-1.74.1.ebuild b/dev-lang/rust/rust-1.74.1.ebuild
index 956ce4016716..b37b1fd78ff5 100644
--- a/dev-lang/rust/rust-1.74.1.ebuild
+++ b/dev-lang/rust/rust-1.74.1.ebuild
@@ -163,6 +163,7 @@ RESTRICT="test"
VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/rust.asc
PATCHES=(
+ "${FILESDIR}"/1.74.1-cross-compile-libz.patch
#"${FILESDIR}"/1.72.0-bump-libc-deps-to-0.2.146.patch # pending refresh
"${FILESDIR}"/1.70.0-ignore-broken-and-non-applicable-tests.patch
"${FILESDIR}"/1.62.1-musl-dynamic-linking.patch
@@ -184,7 +185,7 @@ bootstrap_rust_version_check() {
[[ ${MERGE_TYPE} == binary ]] && return
local rustc_wanted="$(ver_cut 1).$(($(ver_cut 2) - 1))"
local rustc_toonew="$(ver_cut 1).$(($(ver_cut 2) + 1))"
- local rustc_version=( $(eselect --brief rust show 2>/dev/null) )
+ local rustc_version=( $(eselect --brief --root="${BROOT}" rust show 2>/dev/null) )
rustc_version=${rustc_version[0]#rust-bin-}
rustc_version=${rustc_version#rust-}
@@ -256,6 +257,18 @@ pkg_setup() {
python-any-r1_pkg_setup
export LIBGIT2_NO_PKG_CONFIG=1 #749381
+ if tc-is-cross-compiler; then
+ export PKG_CONFIG_ALLOW_CROSS=1
+ export PKG_CONFIG_PATH="${ROOT}/usr/$(get_libdir)/pkgconfig"
+ export OPENSSL_INCLUDE_DIR="${ROOT}/usr/include"
+ export OPENSSL_LIB_DIR="${ROOT}/usr/$(get_libdir)"
+
+ use system-bootstrap || die "USE=system-bootstrap is required when cross-compiling"
+ use system-llvm && die "USE=system-llvm not allowed when cross-compiling"
+ local cross_llvm_target="$(llvm_tuple_to_target "${CBUILD}")"
+ use "llvm_targets_${cross_llvm_target}" || \
+ die "Must enable LLVM_TARGETS=${cross_llvm_target} matching CBUILD=${CBUILD} when cross-compiling"
+ fi
use system-bootstrap && bootstrap_rust_version_check
@@ -298,7 +311,7 @@ src_prepare() {
if ! use system-bootstrap; then
has_version sys-devel/gcc || esetup_unwind_hack
local rust_stage0_root="${WORKDIR}"/rust-stage0
- local rust_stage0="rust-${RUST_STAGE0_VERSION}-$(rust_abi)"
+ local rust_stage0="rust-${RUST_STAGE0_VERSION}-$(rust_abi "${CBUILD}")"
"${WORKDIR}/${rust_stage0}"/install.sh --disable-ldconfig \
--without=rust-docs-json-preview,rust-docs --destdir="${rust_stage0_root}" --prefix=/ || die
@@ -347,6 +360,8 @@ src_configure() {
[[ -d ${rust_stage0_root} ]] || die "${rust_stage0_root} is not a directory"
rust_target="$(rust_abi)"
+ rust_build="$(rust_abi "${CBUILD}")"
+ rust_host="$(rust_abi "${CHOST}")"
local cm_btype="$(usex debug DEBUG RELEASE)"
cat <<- _EOF_ > "${S}"/config.toml
@@ -378,17 +393,24 @@ src_configure() {
enable-warnings = false
[llvm.build-config]
CMAKE_VERBOSE_MAKEFILE = "ON"
- CMAKE_C_FLAGS_${cm_btype} = "${CFLAGS}"
- CMAKE_CXX_FLAGS_${cm_btype} = "${CXXFLAGS}"
- CMAKE_EXE_LINKER_FLAGS_${cm_btype} = "${LDFLAGS}"
- CMAKE_MODULE_LINKER_FLAGS_${cm_btype} = "${LDFLAGS}"
- CMAKE_SHARED_LINKER_FLAGS_${cm_btype} = "${LDFLAGS}"
- CMAKE_STATIC_LINKER_FLAGS_${cm_btype} = "${ARFLAGS}"
+ $(if ! tc-is-cross-compiler; then
+ # When cross-compiling, LLVM is compiled twice, once for host and
+ # once for target. Unfortunately, this build configuration applies
+ # to both, which means any flags applicable to one target but not
+ # the other will break. Conditionally disable respecting user
+ # flags when cross-compiling.
+ echo "CMAKE_C_FLAGS_${cm_btype} = \"${CFLAGS}\""
+ echo "CMAKE_CXX_FLAGS_${cm_btype} = \"${CXXFLAGS}\""
+ echo "CMAKE_EXE_LINKER_FLAGS_${cm_btype} = \"${LDFLAGS}\""
+ echo "CMAKE_MODULE_LINKER_FLAGS_${cm_btype} = \"${LDFLAGS}\""
+ echo "CMAKE_SHARED_LINKER_FLAGS_${cm_btype} = \"${LDFLAGS}\""
+ echo "CMAKE_STATIC_LINKER_FLAGS_${cm_btype} = \"${ARFLAGS}\""
+ fi)
[build]
build-stage = 2
test-stage = 2
- build = "${rust_target}"
- host = ["${rust_target}"]
+ build = "${rust_build}"
+ host = ["${rust_host}"]
target = [${rust_targets}]
cargo = "${rust_stage0_root}/bin/cargo"
rustc = "${rust_stage0_root}/bin/rustc"
@@ -426,7 +448,9 @@ src_configure() {
debuginfo-level-tests = 0
backtrace = true
incremental = false
- default-linker = "$(tc-getCC)"
+ $(if ! tc-is-cross-compiler; then
+ echo "default-linker = \"$(tc-getCC)\""
+ fi)
parallel-compiler = $(toml_usex parallel-compiler)
channel = "$(usex nightly nightly stable)"
description = "gentoo"