CARGO(1)

๐Ÿ“ฆ version 1.97.1, in ubuntu stonking

๐Ÿ’… CARGO(1) โ€” the Rust package manager, but make it a group chat

okay bestie, welcome to CARGO(1), the manual page for cargo, aka The Rust package manager. She's in the General Commands Manual section and she is iconic. Sit down, hydrate, and let's get into it ๐Ÿซถ


โœจ NAME โœจ

cargo โ€” The Rust package manager ๐ŸŒธ


๐Ÿ“œ SYNOPSIS ๐Ÿ“œ

cargo [options] command [args]
cargo [options] --version
cargo [options] --list
cargo [options] --help
cargo [options] --explain code

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So this program is a package manager and a build tool for the Rust language, and it lives at <https://rust-lang.org>. She does it all, no cap.

The command you pass in may be one of these three vibes:


๐Ÿ› ๏ธ COMMANDS ๐Ÿ› ๏ธ

๐Ÿ—๏ธ Build Commands

  • cargo-bench(1) โ€” Execute benchmarks of a package. ๐Ÿ“Š
  • cargo-build(1) โ€” Compile a package.
  • cargo-check(1) โ€” Check a local package and all of its dependencies for errors. ๐Ÿ‘€
  • cargo-clean(1) โ€” Remove artifacts that Cargo has generated in the past. ๐Ÿงน
  • cargo-doc(1) โ€” Build a packageโ€™s documentation. ๐Ÿ“š
  • cargo-fetch(1) โ€” Fetch dependencies of a package from the network. ๐ŸŒ
  • cargo-fix(1) โ€” Automatically fix lint warnings reported by rustc. ๐Ÿ”ง
  • cargo-run(1) โ€” Run a binary or example of the local package. ๐Ÿƒ
  • cargo-rustc(1) โ€” Compile a package, and pass extra options to the compiler.
  • cargo-rustdoc(1) โ€” Build a packageโ€™s documentation, using specified custom flags.
  • cargo-test(1) โ€” Execute unit and integration tests of a package. โœ…

๐Ÿ“‹ Manifest Commands

  • cargo-add(1) โ€” Add dependencies to a Cargo.toml manifest file.
  • cargo-generate-lockfile(1) โ€” Generate Cargo.lock for a project.
  • cargo-info(1) โ€” Display information about a package in the registry. Default registry is crates.io.
  • cargo-locate-project(1) โ€” Print a JSON representation of a Cargo.toml fileโ€™s location.
  • cargo-metadata(1) โ€” Output the resolved dependencies of a package in machine-readable format. ๐Ÿค–
  • cargo-pkgid(1) โ€” Print a fully qualified package specification.
  • cargo-remove(1) โ€” Remove dependencies from a Cargo.toml manifest file.
  • cargo-tree(1) โ€” Display a tree visualization of a dependency graph. ๐ŸŒณ
  • cargo-update(1) โ€” Update dependencies as recorded in the local lock file.
  • cargo-vendor(1) โ€” Vendor all dependencies locally.

๐Ÿ“ฆ Package Commands

๐Ÿš€ Publishing Commands

๐Ÿ“ˆ Report Commands

๐Ÿงญ General Commands


โš™๏ธ OPTIONS โš™๏ธ

๐ŸŒŸ Special Options

  • -V, --version โ€” Print version info and exit. If used with --verbose, prints extra information.
  • --list โ€” List all installed Cargo subcommands. If used with --verbose, prints extra information.
  • --explain code โ€” Run rustc --explain CODE which will print out a detailed explanation of an error message (for example, E0004). ๐Ÿง 

๐ŸŽจ Display Options

  • -v, --verbose โ€” Use verbose output. May be specified twice for โ€œvery verboseโ€ output which includes extra output such as dependency warnings and build script output. May also be specified with the term.verbose config value <https://doc.rust-lang.org/cargo/reference/config.html>. ๐Ÿ—ฃ๏ธ
  • -q, --quiet โ€” Do not print cargo log messages. May also be specified with the term.quiet config value <https://doc.rust-lang.org/cargo/reference/config.html>. ๐Ÿคซ
  • --color when โ€” Control when colored output is used. Valid values:
    • auto (default): Automatically detect if color support is available on the terminal.
    • always: Always display colors. ๐ŸŒˆ
    • never: Never display colors.

May also be specified with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.

๐Ÿ”’ Manifest Options

  • --locked โ€” Asserts that the exact same dependencies and versions are used as when the existing Cargo.lock file was originally generated. Cargo will exit with an error when either of the following scenarios arises:
    • The lock file is missing.
    • Cargo attempted to change the lock file due to a different dependency resolution.

It may be used in environments where deterministic builds are desired, such as in CI pipelines. ๐ŸŽฏ

  • --offline โ€” Prevents Cargo from accessing the network for any reason. Without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. With this flag, Cargo will attempt to proceed without the network if possible.
Beware bestie โš ๏ธ this may result in different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. See the cargo-fetch(1) command to download dependencies before going offline.

May also be specified with the net.offline config value <https://doc.rust-lang.org/cargo/reference/config.html>.

  • --frozen โ€” Equivalent to specifying both --locked and --offline. โ„๏ธ

๐Ÿซถ Common Options

  • +toolchain โ€” If Cargo has been installed with rustup, and the first argument to cargo begins with +, it will be interpreted as a rustup toolchain name (such as +stable or +nightly). See the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more information about how toolchain overrides work.
  • --config KEY=VALUE or PATH โ€” Overrides a Cargo configuration value. The argument should be in TOML syntax of KEY=VALUE, or provided as a path to an extra configuration file. This flag may be specified multiple times. See the command-line overrides section <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more information.
  • -C PATH โ€” Changes the current working directory before executing any specified operations. This affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering .cargo/config.toml, for example. This option must appear before the command name, for example cargo -C path/to/my-project build.
heads up ๐Ÿ™ˆ This option is only available on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z unstable-options flag to enable (see #10098 <https://github.com/rust-lang/cargo/issues/10098>).
  • -h, --help โ€” Prints help information. ๐Ÿ†˜
  • -Z flag โ€” Unstable (nightly-only) flags to Cargo. Run cargo -Z help for details. ๐ŸŒ™

๐ŸŒ ENVIRONMENT ๐ŸŒ

See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on environment variables that Cargo reads. ๐Ÿ‘€


๐Ÿšฆ EXIT STATUS ๐Ÿšฆ

  • 0: Cargo succeeded. ๐ŸŽ‰
  • 101: Cargo failed to complete. ๐Ÿ’€

๐Ÿ“ FILES ๐Ÿ“

  • ~/.cargo/ โ€” Default location for Cargoโ€™s โ€œhomeโ€ directory where it stores various files. The location can be changed with the CARGO_HOME environment variable.
  • $CARGO_HOME/bin/ โ€” Binaries installed by cargo-install(1) will be located here. If using rustup <https://rust-lang.github.io/rustup/>, executables distributed with Rust are also located here.
  • $CARGO_HOME/config.toml โ€” The global configuration file. See the reference <https://doc.rust-lang.org/cargo/reference/config.html> for more information about configuration files.
  • .cargo/config.toml โ€” Cargo automatically searches for a file named .cargo/config.toml in the current directory, and all parent directories. These configuration files will be merged with the global configuration file.
  • $CARGO_HOME/credentials.toml โ€” Private authentication information for logging in to a registry. ๐Ÿ”
  • $CARGO_HOME/registry/ โ€” This directory contains cached downloads of the registry index and any downloaded dependencies.
  • $CARGO_HOME/git/ โ€” This directory contains cached downloads of git dependencies.
Please note that the internal structure of the $CARGO_HOME directory is not stable yet and may be subject to change. ๐Ÿซ 

๐ŸŒธ EXAMPLES ๐ŸŒธ

  1. Build a local package and all of its dependencies:
cargo build
  1. Build a package with optimizations:
cargo build --release
  1. Run tests for a cross-compiled target:
cargo test --target i686-unknown-linux-gnu
  1. Create a new package that builds an executable:
cargo new foobar
  1. Create a package in the current directory:
mkdir foo && cd foo
cargo init .
  1. Learn about a commandโ€™s options and usage:
cargo help clean

๐Ÿ› BUGS ๐Ÿ›

See <https://github.com/rust-lang/cargo/issues> for issues. fr fr, if something's broken, that's the place ๐Ÿซก


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

rustc(1), rustdoc(1)


and that's the whole page bestie ๐Ÿ’– this was the CARGO(1) page from the General Commands Manual โ€” footer says CARGO(1) too, so yeah, she's got main character energy from top to bottom ๐Ÿ‘‘ go build something cute, mwah ๐ŸŽ€โœจ

๐Ÿ“ฆ where this page comes from