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 <[email protected]>
Reviewed-by: James Le Cuirot <[email protected]>
Signed-off-by: Eli Schwartz <[email protected]>
---

v2: fix ordering bug, see range-diff

 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

Range-diff against v1:
1:  5fa0a639ef86 ! 1:  9ccac3b29092 toolchain-funcs.eclass: tc-env_build should 
also update CHOST
    @@ Commit message
     
         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 <[email protected]>
         Reviewed-by: James Le Cuirot <[email protected]>
         Signed-off-by: Eli Schwartz <[email protected]>
     
      ## eclass/toolchain-funcs.eclass ##
    -@@ eclass/toolchain-funcs.eclass: tc-export_build_env() {
    - # the target build system does not check.
    - tc-env_build() {
    -   tc-export_build_env
    +@@ eclass/toolchain-funcs.eclass: tc-env_build() {
    +   PKG_CONFIG=$(tc-getBUILD_PKG_CONFIG) \
    +   RANLIB=$(tc-getBUILD_RANLIB) \
    +   READELF=$(tc-getBUILD_READELF) \
     +  CHOST=${CBUILD:-${CHOST}} \
    -   CFLAGS=${BUILD_CFLAGS} \
    -   CXXFLAGS=${BUILD_CXXFLAGS} \
    -   CPPFLAGS=${BUILD_CPPFLAGS} \
    +   "$@"
    + }
    + 
     @@ eclass/toolchain-funcs.eclass: tc-env_build() {
      # @CODE
      econf_build() {
-- 
2.52.0


Reply via email to