diff mbox series

[01/20] cargo-example: add minimal selftest fixture

Message ID 20261026-devtool-ide-sdk-cargo-v1-1-d4504e124d07@savoirfairelinux.com
State New
Headers show
Series devtool: ide-sdk: add support for Rust recipes | expand

Commit Message

Enguerrand de Ribaucourt Oct. 26, 2026, 8:55 a.m. UTC
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 <enguerrand.de-ribaucourt@savoirfairelinux.com>
---
 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 mbox series

Patch

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));
+}