CARGO-CLEAN(1)

πŸ“¦ version 1.79.0, in ubuntu jammy, ubuntu noble

πŸ’… NAME πŸ’…

cargo-clean β€” the moment you finally clear out all the generated artifacts, no cap ✨

This one lives in the General Commands Manual, section 1, so you already know it's a certified banger of a page.


✨ SYNOPSIS ✨

cargo clean [options]

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so bestie, picture this: your target directory has been collecting artifacts that Cargo generated in the past like it's a hoarder with main character energy. cargo clean is here to Remove generated artifacts. The girl cleans. 🧹✨

And if you pass no options at all? She's not being subtle. cargo clean will delete the entire target directory. Whole thing. Gone. Periodt. πŸ’€


πŸŽ€ OPTIONS πŸŽ€

Package Selection

Heads up, queen: when no packages are selected, all packages and all dependencies in the workspace are cleaned. Everybody gets the treatment. 😌

  • -p spec…, --package spec… β€” Clean only the specified packages. You can drop this flag multiple times if you're feeling extra. The SPEC format lives over in cargo-pkgid(1), iykyk.

Clean Options

  • --dry-run β€” Shows you a lil summary of what would get deleted, without deleting a single thing. It's giving window shopping πŸ›οΈ. Pair it with --verbose if you want to see the actual files that would be deleted β€” the receipts, basically.
  • --doc β€” Makes cargo clean remove only the doc directory inside the target directory. Just the docs, nothing else, she's being selective.
  • --release β€” Removes all artifacts in the release directory. Bye girl πŸ‘‹
  • --profile name β€” Removes all artifacts in the directory with that given profile name.
  • --target-dir directory β€” Where all the generated artifacts and intermediate files go. You can also set this with the CARGO_TARGET_DIR environment variable, or the build.target-dir config value at https://doc.rust-lang.org/cargo/reference/config.html. Defaults to target in the root of the workspace. 🏠
  • --target triple β€” Clean for the given architecture. Default is the host architecture. The general format of the triple is <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for a list of supported targets. This flag may be specified multiple times. 🌈

This may also be specified with the build.target config value at https://doc.rust-lang.org/cargo/reference/config.html.

Heads up though: specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. Check the build cache docs at https://doc.rust-lang.org/cargo/guide/build-cache.html for more details. πŸ‘€

Display Options

  • -v, --verbose β€” Use verbose output. Specify it twice for "very verbose" output, which includes extra stuff like dependency warnings and build script output. May also be set with the term.verbose config value at https://doc.rust-lang.org/cargo/reference/config.html. She's chatty and we love that πŸ’¬
  • -q, --quiet β€” Do not print cargo log messages. May also be set with the term.quiet config value at https://doc.rust-lang.org/cargo/reference/config.html. Silence is golden ✨
  • --color when β€” Controls when colored output is used. Valid values, bestie:
    • auto (default): Automatically detect if color support is available on the terminal. πŸ€–
    • always: Always display colors. 🌈
    • never: Never display colors. 🚫

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

Manifest Options

  • --manifest-path path β€” Path to the Cargo.toml file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory. πŸ”
  • --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. Fr fr, your CI will thank you.

  • --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 set with the net.offline config value at https://doc.rust-lang.org/cargo/reference/config.html.

  • --frozen β€” Equivalent to specifying both --locked and --offline. Two-for-one deal, iconic. πŸ‘‘

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 info on 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). Nightly girlies only, sorry πŸ’…
  • -h, --help β€” Prints help information. The classic. πŸŽ€
  • -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 the details on environment variables that Cargo reads. All the tea is there 🍡


⭐ EXIT STATUS ⭐

  • 0: Cargo succeeded. πŸ₯³ Slay.
  • 101: Cargo failed to complete. 😭 It's giving not today.

🌸 EXAMPLES 🌸

  1. Remove the entire target directory:
cargo clean
  1. Remove only the release artifacts:
cargo clean --release

πŸ‘‘ SEE ALSO πŸ‘‘

cargo(1), cargo-build(1)


And that's the whole page, bestie β€” straight from the General Commands Manual, this is cargo-clean(1), section 1. Go forth and clean your target directory, you absolute icon. πŸ«Άβœ¨πŸŽ€

πŸ“¦ where this page comes from