On 20-08-2026 02:24 pm, Richard Purdie wrote:
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know 
the content is safe.

On Fri, 2026-08-07 at 02:31 -0700, Sadineni, Harish via lists.openembedded.org 
wrote:
From: Harish Sadineni<[email protected]>

YOCTO [#15061]

Fixes 32-bit Cargo build failures when using multilib-enabled SDKs.

Store the generated environment setup script in a target-specific
subdirectory so that sourcing the SDK environment always loads the
matching script for the selected target, avoiding accidental reuse of
the 64-bit configuration when building for a 32-bit target.

Also update `CARGO_TARGET_<TRIPLE>_RUSTFLAGS` to add an explicit
`-L` search path to the target `rustlib` directory inside the sysroot.
This ensures Cargo can locate the correct target-specific Rust libraries
during cross-compilation with the cross-canadian toolchain.

Signed-off-by: Harish Sadineni<[email protected]>
---
  meta/recipes-devtools/rust/rust-cross-canadian.inc | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/meta/recipes-devtools/rust/rust-cross-canadian.inc 
b/meta/recipes-devtools/rust/rust-cross-canadian.inc
index f083bcda82..bdc63e221f 100644
--- a/meta/recipes-devtools/rust/rust-cross-canadian.inc
+++ b/meta/recipes-devtools/rust/rust-cross-canadian.inc
@@ -51,15 +51,17 @@ do_install () {
      chmod +x "$outfile"
      create_sdk_wrapper "${SYS_BINDIR}/target-rust-ccld-wrapper" "CC"

-    ENV_SETUP_DIR=${D}${base_prefix}/environment-setup.d
-    mkdir "${ENV_SETUP_DIR}"
+    ENV_SETUP_DIR=${D}${base_prefix}/environment-setup.d/${TARGET_SYS}
+    mkdir -p "${ENV_SETUP_DIR}"
      RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/${RUST_TARGET_SYS}_rust.sh"

      RUST_TARGET_TRIPLE=`echo ${RUST_TARGET_SYS} | tr '[:lower:]' '[:upper:]' 
| sed 's/-/_/g'`

      cat <<- EOF > "${RUST_ENV_SETUP_SH}"
-     export 
CARGO_TARGET_${RUST_TARGET_TRIPLE}_RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr 
-C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT"
-     export CARGO_BUILD_TARGET="${RUST_TARGET_SYS}"
+     export RUST_TARGET_SYS_VALUE="${RUST_TARGET_SYS}"
+     
LIB_PATH="\$OECORE_TARGET_SYSROOT/usr/${baselib}/rustlib/${RUST_TARGET_SYS}/lib"
+     export 
CARGO_TARGET_${RUST_TARGET_TRIPLE}_RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr 
-C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT -L \$LIB_PATH"
+        export CARGO_BUILD_TARGET="${RUST_TARGET_SYS}"
       export 
RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib"
       EOF
I'm a bit confused here. The script in question already has
${RUST_TARGET_SYS} in its name, so it is already target specific. Why
do we need to move it to a target specific directory?
Hi Richard,

Even though the script filename includes ${RUST_TARGET_SYS}, for multilib SDKs both the 32-bit and 64-bit scripts end up in the same environment-setup  directory.

The SDK's environment-sourcing logic sources every '*.sh' file in that directory, so both scripts get sourced regardless of which target you're building for. Since 'CARGO_TARGET_<TRIPLE>_RUSTFLAGS' and 'CARGO_BUILD_TARGET' are set unconditionally in each script, whichever one is sourced /last/ wins and that can silently override the 32-bit settings with the 64-bit ones (or vice versa). That's what causes the 32-bit Cargo build to fail.

Putting each script in a target-specific subdirectory (environment-setup.d/${TARGET_SYS}/) ensures only the script matching the selected target gets sourced, so the two configurations no longer clobber each other.

Thanks,
Harish


Cheers,

Richard

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#243903): 
https://lists.openembedded.org/g/openembedded-core/message/243903
Mute This Topic: https://lists.openembedded.org/mt/120640029/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to