public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Sam James <sam@gentoo.org>
To: James Le Cuirot <chewi@gentoo.org>
Cc: gentoo-dev <gentoo-dev@lists.gentoo.org>
Subject: Re: [gentoo-dev] [PATCH 1/5 v3] cargo.eclass: Add cargo_env helper and use it in compile, test, install
Date: Thu, 25 Jul 2024 12:48:16 +0100	[thread overview]
Message-ID: <87r0bhk7zz.fsf@gentoo.org> (raw)
In-Reply-To: <20240725112005.10045-3-chewi@gentoo.org> (James Le Cuirot's message of "Thu, 25 Jul 2024 12:19:32 +0100")

James Le Cuirot <chewi@gentoo.org> writes:

> 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.

The series looks OK but please let Ionen cast an eye over it as well as
mgorny, espec. for distutils-r1.

(Also, remember to CC eclass maints!)

>
> 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_TARGET=$(rust_abi)
>  		local TRIPLE=${CARGO_BUILD_TARGET//-/_}
> -		export CARGO_TARGET_"${TRIPLE^^}"_LINKER=$(tc-getCC)
> +		declare -x CARGO_TARGET_"${TRIPLE^^}"_LINKER=$(tc-getCC)
>
>  		# Set vars for cc-rs crate.
>  		tc-export_build_env
> -		export \
> +		declare -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


      parent reply	other threads:[~2024-07-25 11:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-25 11:19 [gentoo-dev] [PATCH 1/5 v3] cargo.eclass: Add cargo_env helper and use it in compile, test, install James Le Cuirot
2024-07-25 11:19 ` [gentoo-dev] [PATCH 2/5 v3] cargo.eclass: Handle LDFLAGS and RUSTFLAGS better James Le Cuirot
2024-07-25 11:19 ` [gentoo-dev] [PATCH 3/5 v3] cargo.eclass: Explicitly tell rustc not to strip binaries James Le Cuirot
2024-07-25 11:19 ` [gentoo-dev] [PATCH 4/5 v3] cargo.eclass: Shadow flag variables so that LTO filtering remains local James Le Cuirot
2024-07-25 11:50   ` Sam James
2024-07-25 11:19 ` [gentoo-dev] [PATCH 5/5 v3] distutils-r1.eclass: Use cargo_env when appropriate for flag handling James Le Cuirot
2024-07-25 11:48 ` Sam James [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=87r0bhk7zz.fsf@gentoo.org \
    --to=sam@gentoo.org \
    --cc=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