Terms follow The Rust Book, The Rust Reference and The Cargo Book. Terms that are not official are marked informal.
Code units
Smallest first.
| Function |
An item with a name, parameters, a return type and a body (fn) |
| Item |
A component of a crate, such as a function, struct or module |
| Module |
A container for zero or more items |
| Crate |
The smallest amount of code the compiler considers at a time. Cargo calls the same thing a target; they are one and the same |
| Binary crate |
A crate with a main function that compiles to an executable |
| Library crate |
A crate with no main that defines code for other crates to use |
| Package |
A bundle of one or more crates, described by a Cargo.toml; at most one library crate |
| Workspace |
A set of packages that share one Cargo.lock and one output directory |
Steps
Steps have no command of their own; they run inside a command.
| Compile |
Turn one crate into an artifact |
rustc |
| Link |
Combine compiled code into the final artifact |
The linker |
Commands
cargo build |
Compile local packages and all their dependencies |
Compile, link |
cargo test |
Compile and run a package’s unit and integration tests |
Compile, link, run tests |
Scope flags
Both commands take these, so they can run on a subset of the workspace.
| Workspace |
--workspace |
All packages |
| Package |
-p <name> |
One package |
| Crate |
--lib, --bin <name>, --test <name> |
One crate in a package |
| Test name |
cargo test <filter> |
Tests matching a name (cargo test only) |
Outputs
| Artifact |
Any file a build produces |
| Crate type |
The form a compiled crate takes, such as bin, rlib, dylib, cdylib or staticlib |
bin |
An executable (.exe on Windows, no extension on Linux/macOS) |
rlib |
A Rust library file (.rlib), an intermediate artifact used by later builds |
dylib |
A dynamic Rust library (.dll/.so/.dylib) |
cdylib |
A dynamic library other languages can load; used for .wasm libraries |
.wasm |
A WebAssembly file, built for a wasm32-* target triple; a bin or a cdylib |
| Target triple |
The platform being compiled for, such as x86_64-pc-windows-msvc or wasm32-unknown-unknown |
Portability
Where each artifact can be used after it is built.
bin (executable) |
Its target triple only (one OS and chip) |
cdylib |
Its target triple only |
dylib |
Its target triple, with the same rustc version |
rlib |
Its target triple, with the same rustc version |
.wasm |
Any OS with a WebAssembly runtime, such as a browser |
Caching
| Target directory |
Where Cargo stores build output (target/ by default); also called the build cache |
| Fresh |
A unit whose cached output is up to date, so Cargo skips it |
| Dirty |
A unit that changed, so Cargo rebuilds it |
| Incremental compilation |
rustc reuses work from the last compile of the same crate |
| Cold / warm build |
Informal. A build with an empty vs. populated target directory |
rustc wrapper |
A program Cargo runs in place of rustc (build.rustc-wrapper) |
| sccache |
Third-party. A rustc wrapper that caches compile output across directories |