CARGO-CLEAN(1)

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

✨ CARGO-CLEAN(1) ✨

okay bestie, welcome to the General Commands Manual section 1, where we're talking about cargo-clean β€” the little command that yeets your build artifacts into the void πŸ’…


πŸŽ€ NAME πŸŽ€

cargo-clean β€” Remove generated artifacts 🧹✨


πŸ¦‹ SYNOPSIS πŸ¦‹

cargo clean [options]

πŸ’– DESCRIPTION πŸ’–

So basically, this deletes the artifacts that Cargo made for you in the past, out of the target directory. Like, the stuff it generated. Gone. Bye 🫢

And listen, with no options at all, cargo clean will delete the entire target directory. The whole thing. Not a drill, not a drill πŸ˜­πŸ’€


🌸 OPTIONS 🌸

πŸ’œ Package Selection πŸ’œ

Real talk: when no packages are selected, all packages and all dependencies in the workspace get cleaned. Everyone's coming to the party whether they like it or not ✨

  • -p spec…, --package spec… β€” clean only the packages you name. You can drop this flag as many times as you want (multiple times = multiple packages). Wanna know what the SPEC format even is? Run to cargo-pkgid(1), she explains it πŸ‘‘

🧼 Clean Options 🧼

  • --dry-run β€” shows you a lil summary of what would get deleted, without actually deleting anything. Very "window shopping" of it πŸ›οΈ Pro tip from the page: pair it with --verbose and it'll show you the actual files that would be deleted.
  • --doc β€” this makes cargo clean remove only the doc directory inside the target directory. Just the docs, nothing else, she's selective πŸ’…
  • --release β€” removes all artifacts sitting in the release directory πŸ”₯
  • --profile name β€” removes all artifacts in the directory with the profile name you give it.
  • --target-dir directory β€” the directory for all generated artifacts and intermediate files. You can also set this with the CARGO_TARGET_DIR environment variable, or with the build.target-dir config value <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, obvi. The general format of the triple is <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for a whole list of supported targets. This flag may be specified multiple times 🎯

You can also set this with the build.target config value <https://doc.rust-lang.org/cargo/reference/config.html>.

Heads up bestie ⚠️: specifying this flag makes Cargo run in a different mode, where the target artifacts get placed in a separate directory. See the build cache docs <https://doc.rust-lang.org/cargo/guide/build-cache.html> for more details.

🌈 Display Options 🌈

  • -v, --verbose β€” verbose output. You can specify it twice for "very verbose" output, which throws in extra output like dependency warnings and build script output. Also settable with the term.verbose config value <https://doc.rust-lang.org/cargo/reference/config.html>.
  • -q, --quiet β€” do not print cargo log messages. Also settable with the term.quiet config value <https://doc.rust-lang.org/cargo/reference/config.html>.
  • --color when β€” controls when colored output is used. Valid values are:
    • auto (default): automatically detect if color support is available on the terminal.
    • always: always display colors.
    • never: never display colors.

Also settable with the term.color config value <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 Cargo.toml in the current directory or any parent directory.
  • --frozen, --locked β€” either one of these flags requires that the Cargo.lock file is up-to-date. If the lock file is missing, or it needs updating, Cargo will exit with an error. The --frozen flag also stops Cargo from trying to access the network to figure out if it's out-of-date. Use these in environments where you want to assert that Cargo.lock is up-to-date (like a CI build), or where you want to avoid network access entirely πŸ”’
  • --offline β€” prevents Cargo from accessing the network for any reason. Without this flag, Cargo will stop with an error if it needs the network and the network isn't there. With this flag, Cargo will try to proceed without the network if it possibly can.
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.

Also settable with the net.offline config value <https://doc.rust-lang.org/cargo/reference/config.html>.

πŸ‘‘ Common Options πŸ‘‘

  • +toolchain β€” if Cargo was installed with rustup, and the first argument to cargo begins with +, it gets interpreted as a rustup toolchain name (like +stable or +nightly). See the rustup documentation <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 given 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 info.
  • -C PATH β€” changes the current working directory before executing any specified operations. This affects stuff like where cargo looks by default for the project manifest (Cargo.toml), and also the directories it searches for discovering .cargo/config.toml, for example. This option must appear before the command name, like cargo -C path/to/my-project build.
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 ⭐

  1. 0: Cargo succeeded πŸŽ‰
  2. 101: Cargo failed to complete 😭

πŸ“ 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 πŸ’– it's from the General Commands Manual, page CARGO-CLEAN(1), and the footer's just sitting down there echoing CARGO-CLEAN(1) one more time like the icon it is. no cap. periodt πŸŽ€βœ¨πŸ«Ά

πŸ“¦ where this page comes from