Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
Binary modules
Stay organized with collections
Save and categorize content based on your preferences.
Rust binaries can be produced using the rust_binary
module type; for example:
rust_binary {
name: "hello_rust",
srcs: ["src/hello_rust.rs"],
}
Similarly, you can use rust_binary_host
to provide a host-only
module.
Notable rust_binary properties
In addition to the Important common properties,
the following properties are also either important, or exhibit unique behavior
specific to the rust_binary
module type:
- static_executable: Builds this binary as a static binary, and implies
prefer_rlib
is true
. Fully static executables can only be produced for
bionic targets. For non-bionic targets, this implies only that prefer_rlib
is true
, but it still links libc
and libdl
dynamically.
- prefer_rlib: Changes the
rustlibs
linkage to select the rlib
linkage
by default for device targets, and links libstd
as an rlib
on device
targets. Note that this is the default behavior for host targets, and
has no impact on them.
Linkage
By default, rust_binary
modules that are targeting devices are always linked
dynamically against libstd
and by default will prefer dylib
libraries for
dependencies listed in rustlibs
unless prefer_rlib
is true
. If fully
static binaries are required, see the static_executable
property.
Host modules are always linked statically against libstd
and
by default prefer rlib
libraries for dependencies that are listed in
rustlibs
.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-06-12 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-12 UTC."],[],[],null,["# Binary modules\n\nRust binaries can be produced using the `rust_binary` module type; for example: \n\n rust_binary {\n name: \"hello_rust\",\n srcs: [\"src/hello_rust.rs\"],\n }\n\nSimilarly, you can use `rust_binary_host` to provide a host-only\nmodule.\n\nNotable rust_binary properties\n------------------------------\n\nIn addition to the [Important common properties](/docs/setup/build/rust/building-rust-modules/android-rust-modules#important-common-properties),\nthe following properties are also either important, or exhibit unique behavior\nspecific to the `rust_binary` module type:\n\n- **static_executable** : Builds this binary as a static binary, and implies `prefer_rlib` is `true`. Fully static executables can only be produced for bionic targets. For non-bionic targets, this implies only that `prefer_rlib` is `true`, but it still links `libc` and `libdl` dynamically.\n- **prefer_rlib** : Changes the `rustlibs` linkage to select the `rlib` linkage by default for device targets, and links `libstd` as an `rlib` on device targets. Note that this is the default behavior for host targets, and has no impact on them.\n\nLinkage\n-------\n\nBy default, `rust_binary` modules that are targeting devices are always linked\ndynamically against `libstd` and by default will prefer `dylib` libraries for\ndependencies listed in `rustlibs` unless `prefer_rlib` is `true`. If fully\nstatic binaries are required, see the `static_executable` property.\n\nHost modules are always linked statically against `libstd` and\nby default prefer `rlib` libraries for dependencies that are listed in\n`rustlibs`."]]