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 6205B159C9C for ; Tue, 6 Aug 2024 08:47:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9D78D2BC058; Tue, 6 Aug 2024 08:47:19 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (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 7ADD92BC058 for ; Tue, 6 Aug 2024 08:47:19 +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)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 966A4342FB3 for ; Tue, 6 Aug 2024 08:47:18 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C26E21EBD for ; Tue, 6 Aug 2024 08:47:15 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <1722933010.11e91de6642a4b329566bb21b3a58a083994745f.mgorny@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/cargo.eclass X-VCS-Directories: eclass/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 11e91de6642a4b329566bb21b3a58a083994745f X-VCS-Branch: master Date: Tue, 6 Aug 2024 08:47:15 +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: 771ecf41-c5b7-483b-a668-81526a84ccae X-Archives-Hash: 41c2ae2137829ad597505fa54e38f852 commit: 11e91de6642a4b329566bb21b3a58a083994745f Author: James Le Cuirot gentoo org> AuthorDate: Wed Jul 24 14:26:34 2024 +0000 Commit: Michał Górny gentoo org> CommitDate: Tue Aug 6 08:30:10 2024 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=11e91de6 cargo.eclass: Add cargo_env helper and use it in compile, test, install Rust packages have a tendency to rebuild parts during test and install. It is not clear whether this can be addressed. We were therefore relying on some environment variables set during the compile phase for cross-compiling to work in the later phases. This is not ideal, especially if you need to build for multiple targets. These environment variables can also be useful in other contexts, such as the build runner in app-misc/anki. This change moves the setting of these variables into a separate helper that is now used in all these phases and can be used by ebuilds too. The variables are now kept local to each invocation of this helper, preventing leakage. Signed-off-by: James Le Cuirot gentoo.org> Signed-off-by: Michał Górny gentoo.org> eclass/cargo.eclass | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index aab28dbbac16..de4a012354ee 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -523,26 +523,23 @@ cargo_src_configure() { [[ ${ECARGO_ARGS[@]} ]] && einfo "Configured with: ${ECARGO_ARGS[@]}" } -# @FUNCTION: cargo_src_compile +# @FUNCTION: cargo_env +# @USAGE: Command with its arguments # @DESCRIPTION: -# Build the package using cargo build. -cargo_src_compile() { - debug-print-function ${FUNCNAME} "$@" - - [[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \ - die "FATAL: please call cargo_gen_config before using ${FUNCNAME}" - +# Run the given command under an environment needed for performing tasks with +# Cargo such as building. +cargo_env() { filter-lto tc-export AR CC CXX PKG_CONFIG if tc-is-cross-compiler; then - export CARGO_BUILD_TARGET=$(rust_abi) + local -x CARGO_BUILD_TARGET=$(rust_abi) local TRIPLE=${CARGO_BUILD_TARGET//-/_} - export CARGO_TARGET_"${TRIPLE^^}"_LINKER=$(tc-getCC) + local -x CARGO_TARGET_"${TRIPLE^^}"_LINKER=$(tc-getCC) # Set vars for cc-rs crate. tc-export_build_env - export \ + local -x \ HOST_AR=$(tc-getBUILD_AR) HOST_CC=$(tc-getBUILD_CC) HOST_CXX=$(tc-getBUILD_CXX) @@ -550,9 +547,21 @@ cargo_src_compile() { HOST_CXXFLAGS=${BUILD_CXXFLAGS} fi + "${@}" +} + +# @FUNCTION: cargo_src_compile +# @DESCRIPTION: +# Build the package using cargo build. +cargo_src_compile() { + debug-print-function ${FUNCNAME} "$@" + + [[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \ + die "FATAL: please call cargo_gen_config before using ${FUNCNAME}" + set -- cargo build $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" einfo "${@}" - "${@}" || die "cargo build failed" + cargo_env "${@}" || die "cargo build failed" } # @FUNCTION: cargo_src_install @@ -573,7 +582,7 @@ cargo_src_install() { $(usex debug --debug "") \ ${ECARGO_ARGS[@]} "$@" einfo "${@}" - "${@}" || die "cargo install failed" + cargo_env "${@}" || die "cargo install failed" rm -f "${ED}/usr/.crates.toml" || die rm -f "${ED}/usr/.crates2.json" || die @@ -590,7 +599,7 @@ cargo_src_test() { set -- cargo test $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" einfo "${@}" - "${@}" || die "cargo test failed" + cargo_env "${@}" || die "cargo test failed" } fi