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
istrue
. Fully static executables can only be produced for bionic targets. For non-bionic targets, this implies only thatprefer_rlib
istrue
, but it still linkslibc
andlibdl
dynamically. - prefer_rlib: Changes the
rustlibs
linkage to select therlib
linkage by default for device targets, and linkslibstd
as anrlib
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
.