Cargo is Rust’s build system and package manager.
Quick links:
Building
Cargo’s build system assumes that source files are in the src
folder, and the executable will be created in the target
folder (/debug
by default, /release
in release mode).
The Cargo.toml
file specifies which dependencies projects rely on and has fuzzy version numbers (i.e., it works with what is compatible with your code).
The Cargo.lock
file ensures project builds are reproducible. It essentially functions as a requirements.txt
that manages package conflicts.
CLI commands
Assume commands are prefixed with cargo
.
build
: to build an application, by default in debug mode.--release
: to compile with optimisations in release mode.
run
: to run the executable.check
: to make sure it compiles (but doesn’t product an executable).update
: figures out the latest versions that match the specifications inCargo.toml
, ignoring theCargo.lock
file.