* [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup
@ 2026-08-07 9:31 Harish.Sadineni
2026-08-07 9:31 ` [PATCH v2 2/3] toolchain-scripts: source target-specific environment setup scripts Harish.Sadineni
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Harish.Sadineni @ 2026-08-07 9:31 UTC (permalink / raw)
To: openembedded-core; +Cc: Sundeep.Kokkonda
From: Harish Sadineni <Harish.Sadineni@windriver.com>
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 <Harish.Sadineni@windriver.com>
---
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
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] toolchain-scripts: source target-specific environment setup scripts
2026-08-07 9:31 [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup Harish.Sadineni
@ 2026-08-07 9:31 ` Harish.Sadineni
2026-08-07 9:31 ` [PATCH v2 3/3] oeqa/sdk/cases/rust.py: Expand test to verify cargo build builds for target Harish.Sadineni
2026-08-20 8:54 ` [OE-core] [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup Richard Purdie
2 siblings, 0 replies; 4+ messages in thread
From: Harish.Sadineni @ 2026-08-07 9:31 UTC (permalink / raw)
To: openembedded-core; +Cc: Sundeep.Kokkonda
From: Harish Sadineni <Harish.Sadineni@windriver.com>
YOCTO [#15061]
Export `OECORE_TARGET_SYS` in the generated SDK and tree environment
setup scripts, and source any `*.sh` files from
`environment-setup.d/${TARGET_SYS}` in addition to the existing
`environment-setup.d` directory.
This complements the rust-cross-canadian changes, where Rust
environment setup scripts are installed under a target-specific
directory. By sourcing only the scripts that match the active target,
the SDK avoids loading environment settings for other target variants,
such as mixing 32-bit and 64-bit configurations in multilib SDKs.
Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com>
---
meta/classes-recipe/toolchain-scripts.bbclass | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/meta/classes-recipe/toolchain-scripts.bbclass b/meta/classes-recipe/toolchain-scripts.bbclass
index d94dcdee39..f0f599959d 100644
--- a/meta/classes-recipe/toolchain-scripts.bbclass
+++ b/meta/classes-recipe/toolchain-scripts.bbclass
@@ -76,6 +76,7 @@ toolchain_create_sdk_env_script () {
echo 'export OECORE_MESON_HOST_CPU_FAMILY="${@meson_cpu_family('TARGET_ARCH', d)}"' >>$script
echo 'export OECORE_MESON_HOST_CPU="${TARGET_ARCH}"' >>$script
echo 'export OECORE_MESON_HOST_ENDIAN="${@meson_endian('TARGET', d)}"' >>$script
+ echo 'export OECORE_TARGET_SYS="${TARGET_SYS}"' >> $script
echo 'unset command_not_found_handle' >> $script
@@ -110,6 +111,7 @@ toolchain_create_tree_env_script () {
echo 'export OECORE_MESON_HOST_CPU_FAMILY="${@meson_cpu_family('TARGET_ARCH', d)}"' >>$script
echo 'export OECORE_MESON_HOST_CPU="${TARGET_ARCH}"' >>$script
echo 'export OECORE_MESON_HOST_ENDIAN="${@meson_endian('TARGET', d)}"' >>$script
+ echo 'export OECORE_TARGET_SYS="${TARGET_SYS}"' >> $script
toolchain_shared_env_script
@@ -172,6 +174,12 @@ if [ -d "\$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then
. \$envfile
done
fi
+if [ -d "\$OECORE_NATIVE_SYSROOT/environment-setup.d/\$OECORE_TARGET_SYS" ]; then
+ for envfile in \$OECORE_NATIVE_SYSROOT/environment-setup.d/\$OECORE_TARGET_SYS/*.sh; do
+ . \$envfile
+ done
+fi
+
EOF
}
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] oeqa/sdk/cases/rust.py: Expand test to verify cargo build builds for target
2026-08-07 9:31 [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup Harish.Sadineni
2026-08-07 9:31 ` [PATCH v2 2/3] toolchain-scripts: source target-specific environment setup scripts Harish.Sadineni
@ 2026-08-07 9:31 ` Harish.Sadineni
2026-08-20 8:54 ` [OE-core] [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup Richard Purdie
2 siblings, 0 replies; 4+ messages in thread
From: Harish.Sadineni @ 2026-08-07 9:31 UTC (permalink / raw)
To: openembedded-core; +Cc: Sundeep.Kokkonda
From: Harish Sadineni <Harish.Sadineni@windriver.com>
Ensure that cargo build successfully builds the binary for the target by default.
This test validates whether the default build process produces the expected output
for the specified target.
Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com>
---
meta/lib/oeqa/sdk/cases/rust.py | 37 ++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/meta/lib/oeqa/sdk/cases/rust.py b/meta/lib/oeqa/sdk/cases/rust.py
index 4b115bebf5..4802a714ab 100644
--- a/meta/lib/oeqa/sdk/cases/rust.py
+++ b/meta/lib/oeqa/sdk/cases/rust.py
@@ -7,6 +7,10 @@
import os
import shutil
import unittest
+import json
+import subprocess
+import re
+
from oeqa.sdk.case import OESDKTestCase
@@ -32,8 +36,39 @@ class RustCompileTest(OESDKTestCase):
def test_cargo_build(self):
self._run('cd %s/hello; cargo add zstd' % (self.tc.sdk_dir))
- self._run('cd %s/hello; cargo build' % self.tc.sdk_dir)
+ result_env = self._run("echo $RUST_TARGET_SYS_VALUE")
+ rust_target_sys = result_env.strip()
+ result = self._run(
+ "cd %s/hello; cargo build --message-format=json-render-diagnostics"
+ % self.tc.sdk_dir
+ )
+
+ executable_path = None
+ for line in result.splitlines():
+ try:
+ msg = json.loads(line)
+ except json.JSONDecodeError:
+ continue
+
+ # Cargo emits multiple JSON messages; we want the executable
+ if isinstance(msg, dict) and msg.get("executable"):
+ executable_path = msg["executable"]
+
+ parts = executable_path.split(os.sep)
+ target_index = parts.index("target")
+ path_component = parts[target_index + 1]
+ if path_component in ("debug", "release"):
+ file_output = subprocess.check_output(["file", executable_path]).decode().strip()
+ match = re.search(r"/sysroots/([^/]+)/lib/", file_output)
+ target_triple = match.group(1) if match else None
+ else:
+ target_triple = path_component
+ self.assertTrue(
+ rust_target_sys == target_triple,
+ f"Cargo built natively for the nativesdk host instead of '{rust_target_sys}.\n"
+ f"Cargo build needs to build for target by default not nativesdk_host"
+ )
class RustHostCompileTest(OESDKTestCase):
td_vars = ['MACHINE', 'SDK_SYS']
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [OE-core] [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup
2026-08-07 9:31 [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup Harish.Sadineni
2026-08-07 9:31 ` [PATCH v2 2/3] toolchain-scripts: source target-specific environment setup scripts Harish.Sadineni
2026-08-07 9:31 ` [PATCH v2 3/3] oeqa/sdk/cases/rust.py: Expand test to verify cargo build builds for target Harish.Sadineni
@ 2026-08-20 8:54 ` Richard Purdie
2 siblings, 0 replies; 4+ messages in thread
From: Richard Purdie @ 2026-08-20 8:54 UTC (permalink / raw)
To: Harish.Sadineni, openembedded-core; +Cc: Sundeep.Kokkonda
On Fri, 2026-08-07 at 02:31 -0700, Sadineni, Harish via lists.openembedded.org wrote:
> From: Harish Sadineni <Harish.Sadineni@windriver.com>
>
> 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 <Harish.Sadineni@windriver.com>
> ---
> 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?
Cheers,
Richard
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-20 8:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07 9:31 [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup Harish.Sadineni
2026-08-07 9:31 ` [PATCH v2 2/3] toolchain-scripts: source target-specific environment setup scripts Harish.Sadineni
2026-08-07 9:31 ` [PATCH v2 3/3] oeqa/sdk/cases/rust.py: Expand test to verify cargo build builds for target Harish.Sadineni
2026-08-20 8:54 ` [OE-core] [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup Richard Purdie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox