Add a minimal cargo recipe to demonstrate the ide-sdk configuration for Rust
in the selftests.

AI-Generated: Uses GitHub Copilot
Signed-off-by: Enguerrand de Ribaucourt 
<[email protected]>
---
 meta-selftest/recipes-test/rust/cargo-example.bb     | 15 +++++++++++++++
 .../recipes-test/rust/cargo-example/Cargo.lock       |  5 +++++
 .../recipes-test/rust/cargo-example/Cargo.toml       |  8 ++++++++
 .../recipes-test/rust/cargo-example/build.rs         | 20 ++++++++++++++++++++
 .../recipes-test/rust/cargo-example/src/main.rs      | 11 +++++++++++
 5 files changed, 59 insertions(+)

diff --git a/meta-selftest/recipes-test/rust/cargo-example.bb 
b/meta-selftest/recipes-test/rust/cargo-example.bb
new file mode 100644
index 0000000000..cca56d8d81
--- /dev/null
+++ b/meta-selftest/recipes-test/rust/cargo-example.bb
@@ -0,0 +1,15 @@
+SUMMARY = "Minimal Cargo application for devtool ide-sdk selftests"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = 
"file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
+
+SRC_URI = "file://Cargo.toml \
+           file://Cargo.lock \
+           file://build.rs \
+           file://src/main.rs \
+          "
+
+S = "${UNPACKDIR}"
+
+inherit cargo
+
+CARGO_BUILD_FLAGS:append = " --features ide-sdk-selftest"
diff --git a/meta-selftest/recipes-test/rust/cargo-example/Cargo.lock 
b/meta-selftest/recipes-test/rust/cargo-example/Cargo.lock
new file mode 100644
index 0000000000..27cb8ffd40
--- /dev/null
+++ b/meta-selftest/recipes-test/rust/cargo-example/Cargo.lock
@@ -0,0 +1,5 @@
+version = 3
+
+[[package]]
+name = "cargo-example"
+version = "0.1.0"
diff --git a/meta-selftest/recipes-test/rust/cargo-example/Cargo.toml 
b/meta-selftest/recipes-test/rust/cargo-example/Cargo.toml
new file mode 100644
index 0000000000..e8a2e1dde4
--- /dev/null
+++ b/meta-selftest/recipes-test/rust/cargo-example/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "cargo-example"
+version = "0.1.0"
+edition = "2021"
+
+[features]
+# Used only to verify that ide-sdk forwards recipe Cargo features to its task.
+ide-sdk-selftest = []
diff --git a/meta-selftest/recipes-test/rust/cargo-example/build.rs 
b/meta-selftest/recipes-test/rust/cargo-example/build.rs
new file mode 100644
index 0000000000..f0733b3d38
--- /dev/null
+++ b/meta-selftest/recipes-test/rust/cargo-example/build.rs
@@ -0,0 +1,20 @@
+use std::env;
+
+// Fail the selftest build if Cargo does not receive BitBake's cross 
environment.
+fn main() {
+    let target_cc = env::var("CC").expect("Cargo config should set target CC");
+    assert!(target_cc.ends_with("/target-rust-cc"), "unexpected CC: 
{target_cc}");
+
+    let host_cc = env::var("HOST_CC").expect("Cargo config should set host 
CC");
+    assert!(host_cc.ends_with("/build-rust-cc"), "unexpected HOST_CC: 
{host_cc}");
+
+    assert!(
+        env::var_os("RUST_TARGET_PATH").is_some(),
+        "Cargo config should set the OE Rust target path",
+    );
+    assert_eq!(
+        env::var("PKG_CONFIG_ALLOW_CROSS").as_deref(),
+        Ok("1"),
+        "Cargo config should allow cross pkg-config",
+    );
+}
diff --git a/meta-selftest/recipes-test/rust/cargo-example/src/main.rs 
b/meta-selftest/recipes-test/rust/cargo-example/src/main.rs
new file mode 100644
index 0000000000..7066010f51
--- /dev/null
+++ b/meta-selftest/recipes-test/rust/cargo-example/src/main.rs
@@ -0,0 +1,11 @@
+fn fibonacci(n: u32) -> u32 {
+    match n {
+        0 => 0,
+        1 => 1,
+        _ => fibonacci(n - 1) + fibonacci(n - 2),
+    }
+}
+
+fn main() {
+    println!("fibonacci={}", fibonacci(4));
+}

-- 
2.53.0

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

Reply via email to