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 <
chewi@gentoo.org>
---
eclass/cargo.eclass | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index 7db34efb4e174..b6d5fe21f0a7b 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)
+ declare -x CARGO_BUILD_TARGE