CARGO-CLEAN(1)

🧹✨ CARGO-CLEAN ✨🧹

General Commands Manual energy, but make it a group chat πŸ’…

okay so bestie, you know how your target/ directory slowly turns into a landfill of build junk? this is the page for that. it's the cargo clean manual, it lives in the General Commands Manual, and honestly deleting things is self-care. periodt. 🫢


🌸 NAME 🌸

cargo-clean β€” Remove generated artifacts πŸ—‘οΈβœ¨


πŸ¦‹ SYNOPSIS πŸ¦‹

cargo clean [options]

πŸ’– DESCRIPTION πŸ’–

So what it does is: it removes the artifacts from the target directory that Cargo has generated in the past. bye bye build junk πŸ‘‹

And here's the main character moment β€” with no options, cargo clean will delete the entire target directory. all of it. every last crumb. iconic behavior fr fr πŸ”₯


πŸ‘‘ OPTIONS πŸ‘‘

πŸ“¦ Package Selection πŸ“¦

Quick vibe check: when no packages are selected, all packages and all dependencies in the workspace get cleaned. everybody's getting a glow-up, no exceptions πŸ’…

  • -p, --package spec… β€” clean only the specified packages. this flag may be specified multiple times. for the SPEC format, go peek at cargo-pkgid(1) πŸ“–
  • --workspace β€” clean artifacts of the workspace members. just the members, bestie 🧚

🧼 Clean Options 🧼

  • --dry-run β€” displays a summary of what would be deleted, without deleting anything. use it with --verbose to display the actual files that would be deleted. it's giving "window shopping" πŸ›οΈ
  • --doc β€” this option will cause cargo clean to remove only the doc directory in the target directory. docs only, no touchy the rest πŸ™ˆ
  • --release β€” remove all artifacts in the release directory. production girlies, this one's for you πŸ’œ
  • --profile name β€” remove all artifacts in the directory with the given profile name.
  • --target-dir directory β€” directory for all generated artifacts and intermediate files. may also be specified 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 specified target architecture. flag may be specified multiple times. the default is the host architecture. the general format of the triple is <arch><sub>-<vendor>-<sys>-<abi>.

Possible values:

  • Any supported target in rustc --print target-list.
  • "host-tuple", which will internally be substituted by the host's target. this can be particularly useful if you're cross-compiling some crates, and don't want to specify your host's machine as a target (for instance, an xtask in a shared project that may be worked on by many hosts). πŸ–₯️
  • A path to a custom target specification. see Custom Target Lookup Path at https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path for more information.

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

heads up bestie: note that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. see the build cache documentation at https://doc.rust-lang.org/cargo/reference/build-cache.html for more details. don't say I didn't warn you πŸ’€

πŸ—£οΈ 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. spill the tea β˜•
  • -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 πŸ“œ

  • --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. it'll find it, she's resourceful πŸ”
  • --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. no surprises allowed, we love a predictable queen πŸ‘‘

  • --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. two for one, slay πŸ’…

🌈 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. order matters, bestie πŸ“Œ
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 πŸ’œ
  • -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. that's where the lore lives πŸ“šβœ¨


⭐ EXIT STATUS ⭐

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


okay that's the whole page, you ate that 🫢 this was CARGO-CLEAN(1) straight out of the General Commands Manual β€” same title at the top and at the bottom, that's the whole footer, no extra version or date to report, just vibes and a very clean target/ directory. go forth and delete responsibly bestie πŸ’–βœ¨πŸ§Ή

πŸ“¦ where this page comes from