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 4994515815E for ; Sat, 10 Feb 2024 07:49:54 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 880F1E2A44; Sat, 10 Feb 2024 07:49:53 +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) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6A57EE2A44 for ; Sat, 10 Feb 2024 07:49:53 +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 6CA60343198 for ; Sat, 10 Feb 2024 07:49:51 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id BDE32118C for ; Sat, 10 Feb 2024 07:49:49 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1707551357.869a67efcaedbf7d08fe16057466f58ac1f21a84.sam@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: dev-lang/rust/, dev-lang/rust/files/ X-VCS-Repository: repo/gentoo X-VCS-Files: dev-lang/rust/files/1.74.1-cross-compile-libz.patch dev-lang/rust/rust-1.74.1.ebuild dev-lang/rust/rust-1.75.0.ebuild X-VCS-Directories: dev-lang/rust/files/ dev-lang/rust/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 869a67efcaedbf7d08fe16057466f58ac1f21a84 X-VCS-Branch: master Date: Sat, 10 Feb 2024 07:49:49 +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: da3dcbf2-35f2-44b3-b475-5f9a5b162dbd X-Archives-Hash: 42292cf8cb1c66c2edb86d77ad81f0d9 commit: 869a67efcaedbf7d08fe16057466f58ac1f21a84 Author: Matoro Mahri matoro tk> AuthorDate: Fri Feb 9 15:48:17 2024 +0000 Commit: Sam James gentoo org> CommitDate: Sat Feb 10 07:49:17 2024 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=869a67ef 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.tk> Closes: https://github.com/gentoo/gentoo/pull/35246 Signed-off-by: Sam James gentoo.org> .../rust/files/1.74.1-cross-compile-libz.patch | 19 +++++++++ dev-lang/rust/rust-1.74.1.ebuild | 46 ++++++++++++++++------ dev-lang/rust/rust-1.75.0.ebuild | 46 ++++++++++++++++------ 3 files changed, 89 insertions(+), 22 deletions(-) diff --git a/dev-lang/rust/files/1.74.1-cross-compile-libz.patch b/dev-lang/rust/files/1.74.1-cross-compile-libz.patch new file mode 100644 index 000000000000..f2a881b46134 --- /dev/null +++ b/dev-lang/rust/files/1.74.1-cross-compile-libz.patch @@ -0,0 +1,19 @@ +https://paste.sr.ht/~kchibisov/682321e0fd4a3ece4a4b7b71591896f5cd3cdb22 +https://github.com/gentoo/gentoo/pull/35246#discussion_r1484525497 + +diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs +index f606fa483ca..8a2e1c40e8b 100644 +--- a/compiler/rustc_llvm/build.rs ++++ b/compiler/rustc_llvm/build.rs +@@ -237,10 +237,7 @@ fn main() { + // of llvm-config, not the target that we're attempting to link. + let mut cmd = Command::new(&llvm_config); + cmd.arg(llvm_link_arg).arg("--libs"); +- +- if !is_crossed { +- cmd.arg("--system-libs"); +- } ++ cmd.arg("--system-libs"); + + if (target.starts_with("arm") && !target.contains("freebsd")) + || target.starts_with("mips-") 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" diff --git a/dev-lang/rust/rust-1.75.0.ebuild b/dev-lang/rust/rust-1.75.0.ebuild index 0f5a1abd1f6e..1c9761e003fe 100644 --- a/dev-lang/rust/rust-1.75.0.ebuild +++ b/dev-lang/rust/rust-1.75.0.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.67.0-doc-wasm.patch @@ -186,7 +187,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-} @@ -258,6 +259,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 @@ -300,7 +313,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 @@ -349,6 +362,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 @@ -380,17 +395,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" @@ -428,7 +450,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"