Skip to contentSkip to conversation

rust-cross-canadian: set CARGO_TARGET_<triple>_RUSTFLAGS

PATCH Superseded Sean Nyekjaer 2 participants 4 messages Sep 29, 2023 – Sep 30, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 rust-cross-canadian: set CARGO_TARGET_<triple>_RUSTFLAGS

Avoid setting sdk-wide RUSTFLAGS as these flags only are valid when building for target.
This will enable building for different targets with different RUSTFLAGS.

---
 meta/recipes-devtools/rust/rust-cross-canadian.inc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
meta/recipes-devtools/rust/rust-cross-canadian.inc +3 -1
index d569ac59f5..d25646237c 100644
@@ -54,8 +54,10 @@ do_install () {
     mkdir "${ENV_SETUP_DIR}"
     RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh"
 
+    RUST_TARGET_TRIPLE=`echo ${RUST_TARGET_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
+
     cat <<- EOF > "${RUST_ENV_SETUP_SH}"
-	export RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr -C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT"
+	export CARGO_TARGET_${RUST_TARGET_TRIPLE}_RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr -C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT"
 	export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib"
 	EOF
 
Signature · 1 line
2.42.0
#1 lore raw

PATCH 2/3 rust-cross-canadian: set CARGO_TARGET_<triple>_RUNNER for nativesdk

This will enable us to build and run rust programs on the sdk host.

% cargo run --target x86_64-oesdk-linux-gnu -vv
Fresh hello v0.1.0 (~/development/hello)
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running /usr/local/sdk/sysroots/x86_64-oesdk-linux/lib/ld-linux-x86-64.so.2 target/x86_64-oesdk-linux-gnu/debug/hello
Hello, world

---
 meta/recipes-devtools/rust/rust-cross-canadian.inc | 3 +++
 1 file changed, 3 insertions(+)
meta/recipes-devtools/rust/rust-cross-canadian.inc +3 -0
index d25646237c..5b89216658 100644
@@ -55,9 +55,12 @@ do_install () {
     RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh"
 
     RUST_TARGET_TRIPLE=`echo ${RUST_TARGET_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
+    RUST_HOST_TRIPLE=`echo ${RUST_HOST_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
+    SDKARCH=`echo ${SDK_ARCH} | 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_TARGET_${RUST_HOST_TRIPLE}_RUNNER="\$OECORE_NATIVE_SYSROOT/lib/ld-linux-${SDKARCH}.so.2"
 	export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib"
 	EOF
 
Signature · 1 line
2.42.0
#2 lore raw

PATCH 3/3 oeqa/sdk/rust: Add build and run test of rust binary with SDK host

In reply to Sean Nyekjaer

Add a QA test to the SDK to test that a basic cargo build works for the SDK host.

---
I know that cargo build and cargo run is kinda redundant for the cargo run command. But I guess it's easier to see whats happening here...

 meta/lib/oeqa/sdk/cases/rust.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
meta/lib/oeqa/sdk/cases/rust.py +22 -0
index 31036f0f14..9404078b1d 100644
@@ -33,3 +33,25 @@ class RustCompileTest(OESDKTestCase):
 
     def test_cargo_build(self):
         self._run('cd %s/hello; cargo build' % self.tc.sdk_dir)
+
+class RustHostCompileTest(OESDKTestCase):
+    td_vars = ['MACHINE', 'SDKMACHINE']
+
+    @classmethod
+    def setUpClass(self):
+        targetdir = os.path.join(self.tc.sdk_dir, "hello")
+        try:
+            shutil.rmtree(targetdir)
+        except FileNotFoundError:
+            pass
+        shutil.copytree(os.path.join(self.tc.sdk_files_dir, "rust/hello"), targetdir)
+
+    def setUp(self):
+        machine = self.td.get("MACHINE")
+        if not self.tc.hasHostPackage("packagegroup-rust-cross-canadian-%s" % machine):
+            raise unittest.SkipTest("RustCompileTest class: SDK doesn't contain a Rust cross-canadian toolchain")
+
+    def test_cargo_build(self):
+        machine = self.td.get("SDKMACHINE")
+        self._run('cd %s/hello; cargo build --target %s-oesdk-linux-gnu' % (self.tc.sdk_dir, machine))
+        self._run('cd %s/hello; cargo run --target %s-oesdk-linux-gnu' % (self.tc.sdk_dir, machine))
Signature · 1 line
2.42.0
#3 lore raw
In reply to Sean Nyekjaer

Hello,

This series causes those rust.RustHostCompileTest.test_cargo_build failures:

https://autobuilder.yoctoproject.org/typhoon/#/builders/53/builds/7879/steps/13/logs/stdio

RustCompileTest class: SDK doesn't contain a Rust cross-canadian toolchain
RustCompileTest class: SDK doesn't contain a Rust cross-canadian toolchain
EpoxyTest class: SDK doesn't contain Meson
GalculatorTest class: SDK don't support gtk+3
No perl package in the SDK
No python3 package in the SDK
RustCompileTest class: SDK doesn't contain a Rust cross-canadian toolchain
RustCompileTest class: SDK doesn't contain a Rust cross-canadian toolchain
Traceback (most recent call last):
File "/home/pokybuild/yocto-worker/qemuarm/build/meta/lib/oeqa/sdk/cases/rust.py", line 56, in test_cargo_build

    self._run('cd %s/hello; cargo build --target %s-oesdk-linux-gnu' % (self.tc.sdk_dir, machine))
  File "/home/pokybuild/yocto-worker/qemuarm/build/meta/lib/oeqa/sdk/case.py", line 14, in _run
    return subprocess.check_output(". %s > /dev/null; %s;" % \
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/lib64/python3.11/subprocess.py", line 466, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.11/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
oeqa.utils.subprocesstweak.OETestCalledProcessError: Command '. /home/pokybuild/yocto-worker/qemuarm/build/build/tmp/work/qemuarm-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk/environment-setup-cortexa15t2hf-neon-poky-linux-gnueabi > /dev/null; cd /home/pokybuild/yocto-worker/qemuarm/build/build/tmp/work/qemuarm-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk//hello; cargo build --target x86_64-oesdk-linux-gnu;' returned non-zero exit status 101 Standard Output: error: failed to run rustc to learn about target-specific information
Caused by:
process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --target x86_64-oesdk-linux-gnu --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit status: 1)
--- stderr
error: Error loading target specification: Could not find specification for target "x86_64-oesdk-linux-gnu". Run rustc --print target-list for a list of built-in targets

https://autobuilder.yoctoproject.org/typhoon/#/builders/47/builds/7858/steps/15/logs/stdio

Traceback (most recent call last):
File "/home/pokybuild/yocto-worker/qemuarm-oecore/build/meta/lib/oeqa/sdk/cases/rust.py", line 57, in test_cargo_build

    self._run('cd %s/hello; cargo run --target %s-oesdk-linux-gnu' % (self.tc.sdk_dir, machine))
  File "/home/pokybuild/yocto-worker/qemuarm-oecore/build/meta/lib/oeqa/sdk/case.py", line 14, in _run
    return subprocess.check_output(". %s > /dev/null; %s;" % \
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/lib64/python3.11/subprocess.py", line 466, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.11/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
oeqa.utils.subprocesstweak.OETestCalledProcessError: Command '. /home/pokybuild/yocto-worker/qemuarm-oecore/build/build/tmp-glibc/work/qemuarm-oe-linux-gnueabi/core-image-sato/1.0/testimage-sdk/environment-setup-cortexa15t2hf-neon-oe-linux-gnueabi > /dev/null; cd /home/pokybuild/yocto-worker/qemuarm-oecore/build/build/tmp-glibc/work/qemuarm-oe-linux-gnueabi/core-image-sato/1.0/testimage-sdk//hello; cargo run --target i686-oesdk-linux-gnu;' returned non-zero exit status 101
Standard Output: Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `/home/pokybuild/yocto-worker/qemuarm-oecore/build/build/tmp-glibc/work/qemuarm-oe-linux-gnueabi/core-image-sato/1.0/testimage-sdk/sysroots/i686-oesdk-linux/lib/ld-linux-i686.so.2 target/i686-oesdk-linux-gnu/debug/hello`
error: could not execute process `/home/pokybuild/yocto-worker/qemuarm-oecore/build/build/tmp-glibc/work/qemuarm-oe-linux-gnueabi/core-image-sato/1.0/testimage-sdk/sysroots/i686-oesdk-linux/lib/ld-linux-i686.so.2 target/i686-oesdk-linux-gnu/debug/hello` (never executed)
Caused by:
No such file or directory (os error 2)

Quoted 39 lines · Sean Nyekjaer

Avoid setting sdk-wide RUSTFLAGS as these flags only are valid when building for target.
This will enable building for different targets with different RUSTFLAGS.

---
 meta/recipes-devtools/rust/rust-cross-canadian.inc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
meta/recipes-devtools/rust/rust-cross-canadian.inc +3 -1
index d569ac59f5..d25646237c 100644
@@ -54,8 +54,10 @@ do_install () {
     mkdir "${ENV_SETUP_DIR}"
     RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh"
 
+    RUST_TARGET_TRIPLE=`echo ${RUST_TARGET_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
+
     cat <<- EOF > "${RUST_ENV_SETUP_SH}"
-	export RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr -C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT"
+	export CARGO_TARGET_${RUST_TARGET_TRIPLE}_RUSTFLAGS="--sysroot=\$OECORE_TARGET_SYSROOT/usr -C link-arg=--sysroot=\$OECORE_TARGET_SYSROOT"
 	export RUST_TARGET_PATH="\$OECORE_NATIVE_SYSROOT/usr/lib/${TARGET_SYS}/rustlib"
 	EOF
 
Signature · 11 lines
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#188399): https://lists.openembedded.org/g/openembedded-core/message/188399
Mute This Topic: https://lists.openembedded.org/mt/101654701/3617179
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com