다음은 Rust 라이브러리에 종속된 Rust 바이너리를 구성하는 예시입니다.
현재 Rust 모듈은 build/soong/rust/config/allowed_list.go에 정의된 특정 디렉터리로 제한됩니다. 다음 helloWorld 모듈은 이 목록이 수정되지 않도록 external/rust 디렉터리를 사용합니다.
AOSP 소스 루트에서
mkdir -p external/rust/hello_rust/src/mkdir -p external/rust/libsimple_printer/src/
다음 콘텐츠로 external/rust/hello_rust/src/hello_rust.rs를 만듭니다.
use simple_printer;
fn main() {
 simple_printer::print_hello_rust();
}
다음 콘텐츠로 external/rust/libsimple_printer/src/lib.rs 파일을 만듭니다.
pub fn print_hello_rust() {
  println!("Hello Rust!");
}
다음 콘텐츠로 external/rust/hello_rust/Android.bp 파일을 만듭니다.
rust_binary {
    name: "hello_rust",
    // srcs must contain a single source file, the entry point source.
    srcs: ["src/hello_rust.rs"],
    // rustlibs are Rust library dependencies. The type, rlib (static) or dylib
    // (dynamic), are chosen automatically based on module type and target
    // to avoid linkage issues.
    rustlibs: ["libsimple_printer"],
    // define any additional compilation flags
    flags: [
        "-C debug-assertions=yes",
    ],
    // cc libraries can be linked in to rust binaries and libraries through the
    // shared_libs and static_libs properties. These are not needed for this
    // simple example, so they are not included.
}
다음 콘텐츠로 external/rust/libsimple_printer/Android.bp 파일을 만듭니다.
// rust_library provides dylib and rlib variants.
rust_library {
    //name or stem properties must be of the form lib<crate_name><any_suffix>
    name: "libsimple_printer",
    //crate_name must match the name used in source (e.g. extern crate <name>)
    crate_name: "simple_printer",
    //srcs must contain a single source file, the entry point source
    srcs: ["src/lib.rs"],
}
마지막으로, hello_rust 모듈을 빌드합니다.
source build/envsetup.shlunch aosp_arm64-engm hello_rust