Back to Comprehensive Rust

Rust Binaries

src/android/build-rules/binary.md

latest942 B
Original Source
<!-- Copyright 2022 Google LLC SPDX-License-Identifier: CC-BY-4.0 -->

Rust Binaries

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

hello_rust/Android.bp:

javascript
{{#include binary/Android.bp}}

hello_rust/src/main.rs:

rust
# // Copyright 2022 Google LLC
# // SPDX-License-Identifier: Apache-2.0
#
{{#include binary/src/main.rs:main}}

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

shell
{{#include ../build_all.sh:hello_rust}}
text
Hello from Rust!
<details>
  • Go through the build steps and demonstrate them running in your emulator.

  • Notice the extensive documentation comments? The Android build rules enforce that all modules have documentation. Try removing it and see what error you get.

  • Stress that the Rust build rules look like the other Soong rules. This is by design, to make using Rust as easy as C++ or Java.

</details>