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_rlibistrue. Fully static executables can only be produced for bionic targets. For non-bionic targets, this implies only thatprefer_rlibistrue, but it still linkslibcandlibdldynamically. - prefer_rlib: Changes the
rustlibslinkage to select therliblinkage by default for device targets, and linkslibstdas anrlibon 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.