new file mode 100644
@@ -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"
new file mode 100644
@@ -0,0 +1,5 @@
+version = 3
+
+[[package]]
+name = "cargo-example"
+version = "0.1.0"
new file mode 100644
@@ -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 = []
new file mode 100644
@@ -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",
+ );
+}
new file mode 100644
@@ -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));
+}
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(+)