• [gentoo-dev] [PATCH] cargo.eclass: Only tell Cargo to cross-compile whe

    From James Le Cuirot@21:1/5 to All on Sun Mar 23 21:10:01 2025
    This avoids the build host vs target flag separation issue. Sometimes it
    is important for the build host to use the right flags. We cannot fix
    this for cross-compiling now, but it should at least work for native
    builds.

    Closes: https://bugs.gentoo.org/951740
    Signed-off-by: James Le Cuirot <chewi@gentoo.org>
    ---
    eclass/cargo.eclass | 8 +++++++-
    1 file changed, 7 insertions(+), 1 deletion(-)

    diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
    index dae2b93f24f31..95d485ab20c34 100644
    --- a/eclass/cargo.eclass
    +++ b/eclass/cargo.eclass
    @@ -448,7 +448,9 @@ _cargo_gen_git_config() {
    # Return the directory within target that contains the build, e.g.
    # target/aarch64-unknown-linux-gnu/release.
    cargo_target_dir() {
    - echo "${CARGO_TARGET_DIR:-target}/$(rust_abi)/$(usex debug debug release)"
    + local abi
    + tc-is-cross-compiler && abi=/$(rust_abi)
    + echo "${CARGO_TARGET_DIR:-target}${abi}/$(usex debug debug release)"
    }

    # @FUNCTION: cargo_update_crates
    @@ -762,6 +764,10 @@ cargo_env() {
    # locally. Do this in a subshell so that they remain set afterwards.
    unset CARGO_BUILD_RUSTFLAGS CARGO_ENCODED_RUSTFLAGS RUSTFLAGS

    + # Only tell Cargo to cross-compile when actually needed to avoid the
    + # aforementioned build host vs target flag separation issue.
    + tc-is-cross-compiler || unset
  • From Sam James@21:1/5 to James Le Cuirot on Sat Mar 29 14:00:01 2025
    James Le Cuirot <chewi@gentoo.org> writes:

    This avoids the build host vs target flag separation issue. Sometimes it
    is important for the build host to use the right flags. We cannot fix
    this for cross-compiling now, but it should at least work for native
    builds.


    LGTM.

    Closes: https://bugs.gentoo.org/951740
    Signed-off-by: James Le Cuirot <chewi@gentoo.org>
    ---
    eclass/cargo.eclass | 8 +++++++-
    1 file changed, 7 insertions(+), 1 deletion(-)

    diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
    index dae2b93f24f31..95d485ab20c34 100644
    --- a/eclass/cargo.eclass
    +++ b/eclass/cargo.eclass
    @@ -448,7 +448,9 @@ _cargo_gen_git_config() {
    # Return the directory within target that contains the build, e.g.
    # target/aarch64-unknown-linux-gnu/release.
    cargo_target_dir() {
    - echo "${CARGO_TARGET_DIR:-target}/$(rust_abi)/$(usex debug debug release)"
    + local abi
    + tc-is-cross-compiler && abi=/$(rust_abi)
    + echo "${CARGO_TARGET_DIR:-target}${abi}/$(usex debug debug release)"
    }

    # @FUNCTION: cargo_update_crates
    @@ -762,6 +764,10 @@ cargo_env() {
    # locally. Do this in a subshell so that they remain set afterwards.
    unset CARGO_BUILD_RUSTFLAGS CARGO_ENCODED_RUSTFLAGS RUSTFLAGS

    + # Only tell Cargo to cross-compile when actually needed to avoid the
    + # aforementioned build host vs target flag separation issue.
    + tc-is-cross-compiler || unset CARGO_BUILD_TARGET
    +
    "${@}"
    )
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)