Toolchains
A Rust build in Bazel selects its compiler, standard library, and companion tools
through a set of registered Bazel toolchains. rules_rust
ships one toolchain type per companion tool so that Rust, rust-analyzer,
rustfmt, and cargo can be resolved independently.
Most users register toolchains via the rust module extension (see
Bzlmod) rather than declaring these rules directly. The rules
below exist for users who need to define custom toolchains — for example, to point
at a locally built rustc or to add a target triple that the extension doesn't
cover.
Toolchain rules
- rust_toolchain — Declare a Rust compilation toolchain: the
rustcbinary, standard library, linker, and per-target compilation settings. - rustfmt_toolchain — Declare a toolchain providing the
rustfmtbinary used by rustfmt rules. - rust_analyzer_toolchain — Declare a toolchain
providing the
rust-analyzerbinary and proc-macro server used by the rust_analyzer integration. - cargo_toolchain — Declare a toolchain providing the
cargobinary used by rules which run Cargo, such as cargo_build_script and crates_vendor. Therustmodule extension declares one in the repository of everyrust_toolchainit registers and registers the two together, so Cargo always comes from the same release asrustc; the toolchain carries the sameversion,iso_dateandchannelidentifiers andcargo_build_scriptfails when they differ. Thecargoattribute ofrust_toolchainis deprecated in its favor and is only consulted when nocargo_toolchainis registered.
Data rules
- rust_stdlib_filegroup — Group the files of a Rust
standard library archive into a target that can be attached to a
rust_toolchainvia therust_stdattribute.