commit:     d896feeeb738b0cad0acd6667845454ddc51eb92
Author:     Eli Schwartz <eschwartz <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 25 05:59:02 2026 +0000
Commit:     Eli Schwartz <eschwartz <AT> gentoo <DOT> org>
CommitDate: Thu Mar 12 15:21:00 2026 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d896feee

toolchain-funcs.eclass: tc-env_build should also update CHOST

The whole purpose of this function is really just to run specific
commands "as CHOST=${CBUILD}" during cross, in case you really need
CBUILD copies of stuff e.g. to do asset generation.

We also have an econf helper which... sets CHOST then runs econf. And
ebuilds such as anki and zig also override CHOST when using
tc-env_build, which implies it is useful/needed.

While exploring app-containers/containerd failing to cross build, I
observed a challenging issue for go-env.eclass as well. One may wish to
use tc-env_build to override the go env to set up, as such:

```
tc-env_build go-env_set_compile_environment emake ....
```

but the latter function sets go's host mode (goarch) based on CHOST,
while the former function checks for cross mode by comparing CHOST
versus CBUILD. Once again, we need a wrapper for tc-env_build to run,
just to set CHOST?

It seems simpler and more consistent to always set it.

Note order is important; tc-getBUILD_XXX must appear and run on the
command line *first*, as they use CHOST internally.

Bug: https://bugs.gentoo.org/966257
Reviewed-by: Sam James <sam <AT> gentoo.org>
Reviewed-by: James Le Cuirot <chewi <AT> gentoo.org>
Signed-off-by: Eli Schwartz <eschwartz <AT> gentoo.org>

 eclass/toolchain-funcs.eclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 89da26b867b1..2b57fc118705 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -402,6 +402,7 @@ tc-env_build() {
        PKG_CONFIG=$(tc-getBUILD_PKG_CONFIG) \
        RANLIB=$(tc-getBUILD_RANLIB) \
        READELF=$(tc-getBUILD_READELF) \
+       CHOST=${CBUILD:-${CHOST}} \
        "$@"
 }
 
@@ -445,8 +446,7 @@ tc-env_build() {
 # @CODE
 econf_build() {
        local CBUILD=${CBUILD:-${CHOST}}
-       econf_env() { CHOST=${CBUILD} econf "$@"; }
-       tc-env_build econf_env "$@"
+       tc-env_build econf "$@"
 }
 
 # @FUNCTION: tc-ld-is-bfd

Reply via email to