Rules rust


This repository provides rules for building Rust projects with Bazel.


To use the Rust rules, add the following to your WORKSPACE file to add the external repositories for the Rust toolchain:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

    name = "rules_rust",
    sha256 = "531bdd470728b61ce41cf7604dc4f9a115983e455d46ac1d0c1632f613ab9fc3",
    strip_prefix = "rules_rust-d8238877c0e552639d3e057aadd6bfcf37592408",
    urls = [
        # `main` branch as of 2021-08-23

load("@rules_rust//rust:repositories.bzl", "rust_repositories")


The rules are under active development, as such the lastest commit on the main branch should be used. main is only tested against 4.0.0 as the minimum supported version of Bazel. Though previous versions may still be functional in certain environments.


You can also browse the full API in one page.

Experimental rules

Specifying Rust version

To build with a particular version of the Rust compiler, pass that version to rust_repositories:

rust_repositories(version = "1.53.0", edition="2018")

As well as an exact version, version can be set to "nightly" or "beta". If set to these values, iso_date must also be set:

rust_repositories(version = "nightly", iso_date = "2021-06-16", edition="2018")

Similarly, rustfmt_version may also be configured:

rust_repositories(rustfmt_version = "1.53.0")

External Dependencies

Currently, the most common approach to managing external dependencies is using cargo-raze to generate BUILD files for Cargo crates.