Rust Binaries

Let us start with a simple application. At the root of an AOSP checkout, create the following files:

hello_rust/Android.bp:

rust_binary { name: "hello_rust", crate_name: "hello_rust", srcs: ["src/main.rs"], }

hello_rust/src/main.rs:

  1. //! Rust demo.
  2. /// Prints a greeting to standard output.
  3. fn main() {
  4. println!("Hello from Rust!");
  5. }

You can now build, push, and run the binary:

$ m hello_rust $ adb push $ANDROID_PRODUCT_OUT/system/bin/hello_rust /data/local/tmp $ adb shell /data/local/tmp/hello_rust Hello from Rust!