There are two GN targets which should be used for Rust projects:
rustc_library
defines a library which can be used by other targets.rustc_binary
defines an executable.
The garnet/examples/rust directory has some examples of Rust packages that use these targets, as do the Rust FIDL examples.
These GN targets do not require a Cargo.toml
file, as they are not built with
Cargo during a normal build of Fuchsia. However, a Cargo.toml
file can be
created for these targets by running
fx gen-cargo path/from/fuchsia/root/to/target:label
. In order to generate a
Cargo.toml, there must have first been a successful build of Fuchsia which
included the target. Generating Cargo.toml
files is useful for integration with
IDEs such as Intellij and VSCode, and for using the fargo
tool to build
and test targets without going through a full GN build and run cycle each time.
You can also run unit tests on connected devices using fx
, with the
fx run-test {package name}_{bin or lib}_test_rustc
command, assuming your
package in BUILD.gn
has with_unit_tests = true
.
We don't currently have a style guide for Rust, but you should
run rustfmt
before submitting. We mostly use the rustfmt
defaults, but have a couple custom settings.
If you want to test out Fuchsia with your own custom-built versions of rustc or cargo,
you can set the rustc_prefix
argument to fx set
, like this:
fx set x64 --release --args "rustc_prefix=\"/path/to/bin/dir\""
Public discussion happens on the [email protected] mailing list. For Googler-only channels, see go/fuchsia-rust-googlers.