diff mbox series

[v2,4/4] rust: Add test to verify cargo build builds for target

Message ID 20250730084818.27093-4-Harish.Sadineni@windriver.com
State New
Headers show
Series [v2,1/4] Revert "rust: remove redundant cargo config file" | expand

Commit Message

Sadineni, Harish July 30, 2025, 8:48 a.m. UTC
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                  | 16 ++++++++++++++++
 .../rust/rust-cross-canadian.inc                 |  1 +
 2 files changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/sdk/cases/rust.py b/meta/lib/oeqa/sdk/cases/rust.py
index 4b115bebf5..17908f21f5 100644
--- a/meta/lib/oeqa/sdk/cases/rust.py
+++ b/meta/lib/oeqa/sdk/cases/rust.py
@@ -4,6 +4,7 @@ 
 # SPDX-License-Identifier: MIT
 #
 
+import json
 import os
 import shutil
 import unittest
@@ -33,6 +34,21 @@  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)
+    def test_check_cargo_build_default_target(self):
+        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 | jq -rc 'select(.executable != null) | .executable'" % (self.tc.sdk_dir))
+        lines = result.strip().splitlines()
+        last_path = lines[-1]
+        parts = last_path.split(os.sep)
+        target_index = parts.index("target")
+        target_triple = parts[target_index + 1]
+
+        self.assertEqual(
+            rust_target_sys,
+            target_triple,
+            f"Target triple mismatch: env '{rust_target_sys}' != path '{target_triple}'"
+        )
 
 class RustHostCompileTest(OESDKTestCase):
     td_vars = ['MACHINE', 'SDK_SYS']
diff --git a/meta/recipes-devtools/rust/rust-cross-canadian.inc b/meta/recipes-devtools/rust/rust-cross-canadian.inc
index ba11cab524..c0f6b85bb5 100644
--- a/meta/recipes-devtools/rust/rust-cross-canadian.inc
+++ b/meta/recipes-devtools/rust/rust-cross-canadian.inc
@@ -61,6 +61,7 @@  do_install () {
         LIB_PATH="\$OECORE_TARGET_SYSROOT/usr/lib/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 RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib"
+	export RUST_TARGET_SYS_VALUE="${RUST_TARGET_SYS}"
 	EOF
 
     chown -R root.root ${D}