docs/rust/README.md
Welcome! If you're interested in learning more about how to use Rust as a Chromium developer, you're in the right place.
Rust support in Chromium is still growing, so your best resource is the Rust-in-Chrome team (internal link). We're the folks responsible for building and maintaining Chromium's Rust infrastructure, and we're always happy to help out people who want to use Rust in their work -- it is quite literally our job to make your lives easier.
[TOC]
If you have questions or an idea about how to use Rust in your work, we'd be more than happy to provide advice and support.
The best ways to reach us are at
[email protected],
or in the #rust channel
on the Chromium Slack.
For Google employees, there are several internal resources you can use as well. If you want to contact the team as a whole, feel free to send a message to [email protected] or join the Chrome + Rust chatroom. However, we also have spaces dedicated to getting started with Rust:
unsafe Rust?
allow_unsafe = true to your build target. See
//docs/rust/unsafe.md for
more information.gtest for Rust code, using the
//testing/rust_gtest_interop
library to integrate into existing testing binaries
(example). Unlike most Rust project, we
do not support #[cfg(test)]-style testing.If you want to create your own Rust library inside of Chromium, use the
rust_static_library
GN template (not the built-in rust_library) to integrate properly into the
Chromium build and get the correct compiler options
(example).
Internally, this will generate a Rust crate with a mangled name based on the
name of the GN target (to ensure crate names are globally unique).
To use that crate from Chromium code, import it using the
chromium::import! macro, which is
automatically available in all Chromium code
(example).
The standard library and crates from //third_party/rust do not use mangled
names, so chromium::import! is not necessary for them.
Your IDE (or coding agent) may suggest use mangled_crate_name::foo;, but
please use chromium::import! instead to avoid depending on the mangling scheme.
See
//third_party/rust/README-importing-new-crates.md
for instructions on how to import a crate from https://crates.io into Chromium.
The crates will get updated semi-automatically through the process described in
//tools/crates/create_update_cl.md.
These libraries use the
cargo_crate
GN template.
Third-party Rust libraries that are not distributed through crates.io should live outside of //third_party/rust.
Such libraries will typically depend on //third_party/rust crates
and use //build/rust/*.gni templates, but there is no other Chromium
tooling to import such libraries or keep them updated.
For examples, see //third_party/crabbyavif or
//third_party/cloud_authenticator.
The other documents in this folder (//docs/rust) contain a variety of
information about using Rust in Chromium, including both advice and our
policies. However, they are more useful as a reference once you're familiar
with the language.
If you want to learn more about Rust on your own, Google maintains a free Rust course. The course outline and "slides" are available to everyone, and they alone can be very helpful. If you're a Google employee, you can also see if there are any instructor-led courses scheduled (go/comprehensive-rust).