CARGO(1)

πŸ“¦ version 1.85.1, in ubuntu jammy, ubuntu noble, ubuntu questing

CARGO(1) β€” General Commands Manual, and bestie, it's the Rust package manager πŸ’…

πŸŽ€ NAME πŸŽ€

cargo β€” the Rust package manager, aka your new bestie who handles literally everything πŸ’–


✨ SYNOPSIS ✨

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

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so. this program is a package manager and a build tool for the Rust language, and it lives at <https://rust-lang.org>. that's it, that's the vibe. it's giving "I do it all and I make it look easy" πŸ‘‘


πŸ’œ COMMANDS πŸ’œ

🌸 Build Commands

  • cargo-bench(1) β€” runs the benchmarks of a package. numbers go brrr πŸ“Š
  • cargo-build(1) β€” compiles a package. the classic.
  • cargo-check(1) β€” checks a local package and all its dependencies for errors, without doing the whole compile thing.
  • cargo-clean(1) β€” deletes the artifacts Cargo made earlier. clearing the cache, literally.
  • cargo-doc(1) β€” builds a package's documentation πŸ“š
  • cargo-fetch(1) β€” goes and fetches a package's dependencies from the network.
  • cargo-fix(1) β€” automatically fixes lint warnings that rustc reported. glow up, but automated ✨
  • cargo-run(1) β€” runs a binary or example from the local package πŸƒ
  • cargo-rustc(1) β€” compiles a package, but also passes extra options to the compiler.
  • cargo-rustdoc(1) β€” builds a package's documentation using whatever custom flags you specify.
  • cargo-test(1) β€” runs a package's unit and integration tests. the moment of truth 🫣

🧚 Manifest Commands

πŸ“ Package Commands

πŸ‘‘ Publishing Commands

  • cargo-login(1) β€” saves an API token from the registry locally.
  • cargo-logout(1) β€” removes an API token from the registry locally.
  • cargo-owner(1) β€” manages the owners of a crate on the registry.
  • cargo-package(1) β€” assembles the local package into a distributable tarball πŸ“¦
  • cargo-publish(1) β€” uploads a package to the registry. main character moment, fr fr.
  • cargo-yank(1) β€” removes a pushed crate from the index.

🌈 General Commands


πŸ’– OPTIONS πŸ’–

⭐ Special Options

  • -V, --version β€” prints version info and exits. if you use it with --verbose, it prints extra information.
  • --list β€” lists all installed Cargo subcommands. if you use it with --verbose, it prints extra information.
  • --explain code β€” runs rustc --explain CODE, which prints out a detailed explanation of an error message (for example, E0004).

πŸŽ€ Display Options

  • -v, --verbose β€” use verbose output. you can specify it 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>.
  • -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 β€” controls when colored output is used. valid values are:
    • auto (the 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 these 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 at <https://doc.rust-lang.org/cargo/reference/config.html>.

  • --frozen β€” equivalent to specifying both --locked and --offline at the same time. two-for-one πŸ’…

🫢 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 the environment variables that Cargo reads. iykyk 🌱


πŸ’… EXIT STATUS πŸ’…

  • 0: Cargo succeeded. we love to see it πŸŽ‰
  • 101: Cargo failed to complete. 😭

πŸŽ€ FILES πŸŽ€

  • ~/.cargo/ β€” the 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 you're 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.
heads up bestie: please note that the internal structure of the $CARGO_HOME directory is not stable yet and may be subject to change. don't get too attached πŸ™ˆ

⭐ 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. (not me manifesting a bug-free build πŸ•―οΈ)


🌈 SEE ALSO 🌈

rustc(1), rustdoc(1)


and that's the whole page, bestie β€” this was CARGO(1) from the General Commands Manual section, closing out with its very own CARGO(1) footer tag. go build something iconic πŸ«ΆπŸ’–

πŸ“¦ where this page comes from