Binary modules

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.