Rust cargo

From wikinotes
Revision as of 00:20, 8 September 2021 by Will (talk | contribs) (→‎Usage)

cargo is rust's build system, package manager, test-runner, and lots more.
it's sort of rust's swiss army knife.

Documentation

man cargo https://man.archlinux.org/man/extra/rust/cargo.1.en
official docs https://doc.rust-lang.org/cargo/

Global Locations

~/.cargo/bin/* cargo installed executables
~/.config/registry/* cached cargo registry indexes
~/.cargo/config.toml global config
~/.config/credentials.toml cargo registry credentials

Project Locations

${PROJECT}/Cargo.toml project config
${PROJECT}/Cargo.lock frozen package versions

Usage

cargo new my_project   # create project

# build
cargo build            # compile project (for testing)
cargo run              # compile/run executable
cargo check            # check project can build, without building
cargo build --release  # build w/ optimizations (more performant)
cargo test             # run tests

# dependencies
cargo update           # update all packages
cargo update -p regex  # update only 'regex' package

Project Configuration

[package]
name = "hello_cargo"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"

[dependencies]
time = "0.1.12"
regex = "0.1.41"
rand = { git = "https://github.com/rust-lang-nursery/rand.git", rev = "9f35b8e" }