The core Rust rules for building and testing libraries, binaries, and procedural macros. Each rule is documented on its own page; this page is an overview of what each rule does and when to use it.
All rules are loadable from @rules_rust//rust:defs.bzl or from their individual .bzl file (e.g. @rules_rust//rust:rust_binary.bzl). Loading from the individual file is preferred for new code.
The rules below are the primary entry points for compiling Rust code. They map directly to the crate types Cargo produces.
--crate-type=bin).rlib (--crate-type=lib) that other Rust targets can depend on.staticlib (--crate-type=staticlib) for linking Rust code into a C/C++ binary.cdylib (--crate-type=cdylib) for use as a shared library from C/C++ or other languages.dylib (--crate-type=dylib) for use as a shared library with the unstable Rust ABI.rust_cdylib_library.--crate-type=proc-macro) that other Rust targets can consume as a compile-time plugin.rust_library/rust_binary (via crate = ...) to run its inline #[test]s, or compile a standalone test binary from its own srcs.Non-core rules that ship in the same ruleset:
rust_library targets so they can be depended on as a single unit without generating an intermediate rlib.rustc, clippy, and rustdoc lint levels that can be attached to other rules via their lint_config attribute.rust_test per source file, sharing a common set of dependencies. Useful for tests/**.rs layouts that mirror Cargo's integration-test directory.Rules that layer on top of the core rules live on their own pages:
rustc -Zunpretty=... output for a crate.cargo_build_script and related Cargo-compatibility rules.rust-project.json file for the rust-analyzer IDE server.