Tooling#
Rust’s toolchain is famously tightly integrated; most things ship in a
single rustup install.
Toolchain Manager#
rustup, installs and updates the Rust toolchain(s).
$ rustup install stable
$ rustup update
$ rustup target add wasm32-unknown-unknown
$ rustup component add rustfmt clippy rust-analyzer
Compiler#
rustc, the compiler. You’ll rarely call it directly;cargodrives it.
$ rustc --version
Cargo#
The verb every Rust developer types. Cargo bootstraps
projects, fetches dependencies, builds, runs, tests,
benchmarks, and produces documentation. cargo add,
cargo build --release, cargo test, and cargo doc
cover most of an everyday workflow.
The build tool, package manager, test runner, and project bootstrapper.
$ cargo new myproj
$ cargo build
$ cargo build --release
$ cargo run -- --flag value
$ cargo add anyhow tokio --features rt-multi-thread
$ cargo update
$ cargo doc --open
Formatter#
rustfmt, ships with the toolchain.
$ cargo fmt
$ cargo fmt --check
Linter#
clippy, the standard linter; ships with the toolchain.
$ cargo clippy --all-targets -- -D warnings
Testing#
The standard library’s #[test] and #[cfg(test)] form the core. cargo
test discovers tests in src/ (unit) and tests/ (integration).
$ cargo test
$ cargo test --doc
$ cargo test -- --nocapture
Companions.
proptest / quickcheck, property-based testing.
criterion, statistically-sound benchmarks.
insta, snapshot testing.
cargo-nextest, faster test runner.
Debugging#
rust-gdb / rust-lldb, pretty-printed wrappers.
cargo-flamegraph, profiling.
tokio-console, async runtime introspection.
Documentation#
rustdoc, ships with cargo; generates docs from///doc comments.
$ cargo doc --no-deps --open
Triple-slash comments are interpreted as Markdown and tested by cargo
test --doc.
Editor Support#
rust-analyzer, the official LSP. Auto-installs in most IDEs.
Useful Cargo Subcommands#
cargo-edit,cargo add,rm,upgrade.cargo-watch, re-run on file changes.cargo-expand, show macro-expanded source.cargo-audit, scan dependencies for known CVEs.cargo-deny, license / security policy enforcement.cargo-outdated, check for newer versions.cargo-tree, visualize the dependency graph.
Cross-Compilation#
$ rustup target add aarch64-unknown-linux-gnu
$ cargo build --target aarch64-unknown-linux-gnu
For complex targets, cross runs the build inside a Docker container with the right toolchain.