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; cargo drives 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.

Debugging#

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#

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.