All of lore.kernel.org
 help / color / mirror / Atom feed
* [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; 9+ 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] 9+ 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-09-07 21:56   ` [OE-core] " Richard Purdie
       [not found]   ` <18D328AC1287253A.77878@lists.openembedded.org>
  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, 2 replies; 9+ 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] 9+ 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; 9+ 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] 9+ 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
  2026-08-21  8:55   ` Harish Sadineni
  2 siblings, 1 reply; 9+ 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] 9+ messages in thread

* Re: [OE-core] [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup
  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
@ 2026-08-21  8:55   ` Harish Sadineni
  2026-08-27 17:31     ` Richard Purdie
  0 siblings, 1 reply; 9+ messages in thread
From: Harish Sadineni @ 2026-08-21  8:55 UTC (permalink / raw)
  To: Richard Purdie, openembedded-core; +Cc: Sundeep.Kokkonda

[-- Attachment #1: Type: text/plain, Size: 3907 bytes --]


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<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?
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
>

[-- Attachment #2: Type: text/html, Size: 4932 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [OE-core] [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup
  2026-08-21  8:55   ` Harish Sadineni
@ 2026-08-27 17:31     ` Richard Purdie
  2026-09-07 18:17       ` Harish Sadineni
  0 siblings, 1 reply; 9+ messages in thread
From: Richard Purdie @ 2026-08-27 17:31 UTC (permalink / raw)
  To: Harish.Sadineni, openembedded-core; +Cc: Sundeep.Kokkonda

On Fri, 2026-08-21 at 14:25 +0530, Sadineni, Harish via lists.openembedded.org wrote:
> 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.

Ok, can you point me to which "environment-sourcing logic" we're taking
about? Is this in the test code or within the SDK itself. I suspect we
should be fixing that issue...
> 
> 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.
> 

Perhaps. I'd like to avoid the complexity if we can so I'd like to
understand more about where this is happening.

Cheers,

Richard


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [OE-core] [PATCH v2 1/3] rust-cross-canadian: install target-specific env scripts and fix rustlib lookup
  2026-08-27 17:31     ` Richard Purdie
@ 2026-09-07 18:17       ` Harish Sadineni
  0 siblings, 0 replies; 9+ messages in thread
From: Harish Sadineni @ 2026-09-07 18:17 UTC (permalink / raw)
  To: Richard Purdie, openembedded-core; +Cc: Sundeep.Kokkonda


On 27-08-2026 11:01 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-21 at 14:25 +0530, Sadineni, Harish via lists.openembedded.org wrote:
>> 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.
> Ok, can you point me to which "environment-sourcing logic" we're taking
> about? Is this in the test code or within the SDK itself. I suspect we
> should be fixing that issue...

Hi Richard,

toolchain-scripts.bbclass is responsible for generating the 
environment-setup-* files for the SDK, and
the generated script includes logic (in toolchain_shared_env_script()) 
that sources every .sh file in the
environment-setup.d/ directory (both under $OECORE_TARGET_SYSROOT and 
$OECORE_NATIVE_SYSROOT).


https://git.openembedded.org/openembedded-core/tree/meta/classes-recipe/toolchain-scripts.bbclass#n164

>> 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.
>>
> Perhaps. I'd like to avoid the complexity if we can so I'd like to
> understand more about where this is happening.

This is happening with multilib enabled, do_testsdk & In sdk 32-bit 
cargo build fails because of this issue.

I've got another implementation this can be fixed with a if condition 
based on target arch instead of a subdirectory.
New approach is below with this we can also drop "[PATCH v2 2/3] 
toolchain-scripts: source target-specific environment setup scripts"

--- a/meta/recipes-devtools/rust/rust-cross-canadian.inc
+++ b/meta/recipes-devtools/rust/rust-cross-canadian.inc
@@ -58,9 +58,13 @@ do_install () {
      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_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib"
+ 
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"
+       if [ "\$OECORE_TARGET_ARCH" = "${TARGET_ARCH}" ]; then
+           export RUST_TARGET_SYS_VALUE="${RUST_TARGET_SYS}"
+           export CARGO_BUILD_TARGET="${RUST_TARGET_SYS}"
+           export 
RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib"
+       fi
         EOF

      chown -R root.root ${D}

If this fine?, i will send a v3.

Thanks,
Harish

>
> Cheers,
>
> Richard


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [OE-core] [PATCH v2 2/3] toolchain-scripts: source target-specific environment setup scripts
  2026-08-07  9:31 ` [PATCH v2 2/3] toolchain-scripts: source target-specific environment setup scripts Harish.Sadineni
@ 2026-09-07 21:56   ` Richard Purdie
       [not found]   ` <18D328AC1287253A.77878@lists.openembedded.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Richard Purdie @ 2026-09-07 21:56 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]
> 
> 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
>  }

Thanks to your other emails, I think I finally understand what is going
on here. Sorry for being a bit slow in understanding the issues
involved. I think what has been confusing me is that we have this code
which was meant to handle the target specific scripts:

https://git.openembedded.org/openembedded-core/commit/?id=2d9466734f0c0c90724820bc36992b2800ffa4d0

which I appear to have added in 2014. I can't find any record of
anything actually successfully adding a target environment.d file using
the above layout, everything is nativesdk based as far as I can see.
I'm not even sure it is possible to add such a thing easily.

So your approach is probably the right one but at the same time, we
should probably remove this other confusing one, assuming we can find
nothing installing such scripts. That should reduce the confusion and
code complexity a little.

This does bring one further detail we need to get right, which is the
name of the directory.

The recipe is named: PN = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}"

i.e. it regenerates if TARGET_ARCH changes.

You're placing the files in TARGET_SYS, which is not equal to
TARGET_ARCH. Which one is correct? If we build a target which combines
glibc and musl, would we need a different rust-cross-canadian for each
libc?

I suspect PN is wrong and it should also use TARGET_SYS?

The patches in this series also need to be the other way around - add
the search path in first, then use it in the next patch.

Cheers,

Richard


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [OE-core] [PATCH v2 2/3] toolchain-scripts: source target-specific environment setup scripts
       [not found]   ` <18D328AC1287253A.77878@lists.openembedded.org>
@ 2026-09-07 22:10     ` Richard Purdie
  0 siblings, 0 replies; 9+ messages in thread
From: Richard Purdie @ 2026-09-07 22:10 UTC (permalink / raw)
  To: Harish.Sadineni, openembedded-core; +Cc: Sundeep.Kokkonda

On Mon, 2026-09-07 at 22:56 +0100, Richard Purdie via lists.openembedded.org wrote:
> 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]
> > 
> > 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
> >  }
> 
> Thanks to your other emails, I think I finally understand what is going
> on here. Sorry for being a bit slow in understanding the issues
> involved. I think what has been confusing me is that we have this code
> which was meant to handle the target specific scripts:
> 
> https://git.openembedded.org/openembedded-core/commit/?id=2d9466734f0c0c90724820bc36992b2800ffa4d0
> 
> which I appear to have added in 2014. I can't find any record of
> anything actually successfully adding a target environment.d file using
> the above layout, everything is nativesdk based as far as I can see.
> I'm not even sure it is possible to add such a thing easily.
> 
> So your approach is probably the right one but at the same time, we
> should probably remove this other confusing one, assuming we can find
> nothing installing such scripts. That should reduce the confusion and
> code complexity a little.
> 
> This does bring one further detail we need to get right, which is the
> name of the directory.
> 
> The recipe is named: PN = "rust-cross-canadian-${TRANSLATED_TARGET_ARCH}"
> 
> i.e. it regenerates if TARGET_ARCH changes.
> 
> You're placing the files in TARGET_SYS, which is not equal to
> TARGET_ARCH. Which one is correct? If we build a target which combines
> glibc and musl, would we need a different rust-cross-canadian for each
> libc?
> 
> I suspect PN is wrong and it should also use TARGET_SYS?
> 
> The patches in this series also need to be the other way around - add
> the search path in first, then use it in the next patch.

I meant to also mention, if you add TARGET_SYS/TARGET_ARCH to the
search path, you can remove it from the script filename.

Cheers,

Richard


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-09-07 22:10 UTC | newest]

Thread overview: 9+ 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-09-07 21:56   ` [OE-core] " Richard Purdie
     [not found]   ` <18D328AC1287253A.77878@lists.openembedded.org>
2026-09-07 22:10     ` Richard Purdie
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
2026-08-21  8:55   ` Harish Sadineni
2026-08-27 17:31     ` Richard Purdie
2026-09-07 18:17       ` Harish Sadineni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.