CARGO(1)

πŸ’– CARGO(1) πŸ’–

okay bestie, welcome to the General Commands Manual, this is the CARGO(1) page and honestly? it's the main character of the whole Rust ecosystem. buckle up, we're reading a manpage and we're gonna enjoy it πŸŽ€


✨ NAME ✨

cargo β€” The Rust package manager. that's it, that's the vibe. πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

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

like. it's giving "one binary, infinite possibilities". ✨


🌸 DESCRIPTION 🌸

okay so real talk: this program is a package manager and a build tool for the Rust language, and you can find it at <https://rust-lang.org>. it literally does your dependency wrangling, your compiling, your testing, your publishing. everything. iconic behaviour, no notes. πŸ’…


πŸ”₯ COMMANDS πŸ”₯

πŸ› οΈ Build Commands

  • cargo-bench(1) β€” Execute benchmarks of a package. yes queen, time your code. ⏱️
  • cargo-build(1) β€” Compile a package. the classic. the blueprint. πŸ’–
  • cargo-check(1) β€” Check a local package and all of its dependencies for errors. faster than a full build, less drama. ✨
  • cargo-clean(1) β€” Remove artifacts that Cargo has generated in the past. spring cleaning but for your target dir. 🧹
  • cargo-doc(1) β€” Build a package's documentation. give the people docs. πŸŽ€
  • cargo-fetch(1) β€” Fetch dependencies of a package from the network. go get 'em. 🌐
  • cargo-fix(1) β€” Automatically fix lint warnings reported by rustc. rustc complains, cargo says "i got u bestie". 🩹
  • cargo-run(1) β€” Run a binary or example of the local package. hit play. ▢️
  • cargo-rustc(1) β€” Compile a package, and pass extra options to the compiler. for when you wanna talk directly to the compiler. πŸ—£οΈ
  • cargo-rustdoc(1) β€” Build a package's documentation, using specified custom flags. same energy, custom flags. 🚩
  • cargo-test(1) β€” Execute unit and integration tests of a package. trust but verify. βœ…

πŸ“œ 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. it's giving "we don't need that anymore". πŸ—‘οΈ
  • cargo-tree(1) β€” Display a tree visualization of a dependency graph. pretty little dependency forest 🌳
  • cargo-update(1) β€” Update dependencies as recorded in the local lock file. πŸ”„
  • cargo-vendor(1) β€” Vendor all dependencies locally. bring them all home. 🏠

πŸ“¦ Package Commands

  • cargo-init(1) β€” Create a new Cargo package in an existing directory. glow-up an existing folder ✨
  • cargo-install(1) β€” Build and install a Rust binary. ⬇️
  • cargo-new(1) β€” Create a new Cargo package. baby's first crate 🍼
  • cargo-search(1) β€” Search packages in crates.io. πŸ’«
  • cargo-uninstall(1) β€” Remove a Rust binary. bye bestie πŸ‘‹

πŸš€ Publishing Commands

  • cargo-login(1) β€” Save an API token from the registry locally. πŸ”‘
  • cargo-logout(1) β€” Remove an API token from the registry locally. log off, log off πŸšͺ
  • cargo-owner(1) β€” Manage the owners of a crate on the registry. πŸ‘₯
  • cargo-package(1) β€” Assemble the local package into a distributable tarball. πŸ“
  • cargo-publish(1) β€” Upload a package to the registry. the moment we've all been waiting for πŸŽ‰
  • cargo-yank(1) β€” Remove a pushed crate from the index. rip bozo πŸ’€

🧚 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). like a translator for cryptic compiler yelling 🫢

🌈 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 at <https://doc.rust-lang.org/cargo/reference/config.html>. (yes, very verbose is a real thing, it's a whole mood πŸ—£οΈ)
  • -q, --quiet β€” Do not print cargo log messages. May also be specified with the term.quiet config value at <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 at <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. (fr fr, your CI will thank u) 🧷

  • --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 that 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 at <https://doc.rust-lang.org/cargo/reference/config.html>. ✈️

  • --frozen β€” Equivalent to specifying both --locked and --offline. the combo meal πŸ”

πŸŽ€ 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 at <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 at <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.
πŸ™ˆ This option is only available on the nightly channel at <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z unstable-options flag to enable (see #10098 at <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 at <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on environment variables that Cargo reads. πŸ‘€


βœ… EXIT STATUS βœ…

  • 0: Cargo succeeded. slay πŸŽ‰
  • 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 at <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 at <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

like. the range. the versatility. obsessed. πŸ’–


πŸ› BUGS πŸ›

See <https://github.com/rust-lang/cargo/issues> for issues. found a bug? tell the maintainers, they're nice, no cap. 🫢


πŸ‘€ SEE ALSO πŸ‘€

rustc(1), rustdoc(1)


and that's the whole page bestie!! πŸŽ€ this was the CARGO(1) page from the General Commands Manual β€” the last line just says CARGO(1) again, because the footer is literally just the page name, and honestly? iconic of it to be that self-confident. go forth and cargo build something beautiful. πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from