tree: 5e2c182df57f1e4e6d7e2c20ad5921e6a4de7cda [path history] [tgz]
  1. crates.md
  2. editors.md
  3. README.md
  4. syslog.md
  5. testing.md
  6. third_party.md
  7. unsafe.md
  8. unstable.md
docs/development/languages/rust/README.md

Rust

Build

There are two GN target templates which should be used for Rust projects:

The garnet/examples/rust directory has some examples of Rust packages that use these targets, as do the Rust FIDL examples.

Building with a custom toolchain

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 core.x64 --release --args "rustc_prefix=\"/path/to/bin/dir\""

Cargo.toml

Fuchsia Rust targets are not built with Cargo during a normal build, and as such, do not require Cargo.toml files. However, having a Cargo.toml file for your target 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.

A Cargo.toml file can be automatically generated for rustc_library and rustc_binary targets based on their .gn file definitions by running:

fx gen-cargo path/from/fuchsia/root/to/target:label

Or, if you're already in a directory with a single Rust target, fx gen-cargo alone should work too.

You must build the target via a regular Fuchsia build before running this command.

Autogenerated docs

You can generate and browse HTML documentation for your target and its dependencies by running:

fx rustdoc path/from/fuchsia/root/to/target:label --open

Tests

You can run unit tests on connected devices using fx, with the fx run-test {package name} command, assuming your package in BUILD.gn has with_unit_tests = true.

Note that in order to use fx run-test, you can't override package_name="..." in your package or test_package declaration. This issue is tracked by BLD-338.

Style

We don't currently have a style guide for Rust, but you should run fx rustfmt or fx format-code before submitting. We mostly use the rustfmt defaults, but have a couple custom settings.

Rust Idiomatic Usage Review

If you're new to Rust, and would like someone to review your changes to validate that your usage of Rust is idiomatic, contact one of the following (or add them as a reviewer to your change.)

(To volunteer for this, please add yourself to the list above and upload the change with one of the above as the reviewer).

Communication channels

Public discussion happens on the rust@fuchsia.com mailing list. For Googler-only channels, see go/fuchsia-rust-googlers.

Existing Fuchsia Rust libraries

Going further