CARGO-CLEAN(1)

πŸ“¦ version 1.93.1, in ubuntu resolute

✨ cargo-clean β€” Remove Generated Artifacts ✨

Okay bestie, welcome to cargo-clean(1) from the General Commands Manual β€” the page that tells you how to yeet your build junk into the void πŸ—‘οΈπŸ’–


🌸 SYNOPSIS 🌸

cargo clean [options]

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically, this removes artifacts from the target directory that Cargo has generated in the past. Spring cleaning, but for target/ πŸ’…

With no options, cargo clean will delete the entire target directory. Like, the whole thing. Iconic but also terrifying. 🫢


πŸŽ€ OPTIONS πŸŽ€

πŸ‘‘ Package Selection

When no packages are selected, all packages and all dependencies in the workspace are cleaned. No crumbs left, fr fr.

  • -p *spec*…, --package *spec*… β€” Clean only the specified packages. This flag may be specified multiple times (yes, stack 'em, she's flexible). See cargo-pkgid(1) for the SPEC format.
  • --workspace β€” Clean artifacts of the workspace members. Just the members, bestie, nothing extra.

🧚 Clean Options

  • --dry-run β€” Displays a summary of what would be deleted without deleting anything. Use with --verbose to display the actual files that would be deleted. The responsible queen behavior πŸ‘‘
  • --doc β€” This option will cause cargo clean to remove only the doc directory in the target directory. Just the docs, ma'am.
  • --release β€” Remove all artifacts in the release directory.
  • --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: 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: https://doc.rust-lang.org/cargo/reference/config.html.

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. ⚠️

🌈 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: https://doc.rust-lang.org/cargo/reference/config.html. Double it for the drama.
  • -q, --quiet β€” Do not print cargo log messages. May also be specified with the term.quiet config value: https://doc.rust-lang.org/cargo/reference/config.html. Shhh 🀫
  • --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: 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. She will find it, she always does πŸ”
  • --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. CI girlies, this one's for 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 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: https://doc.rust-lang.org/cargo/reference/config.html.

⚠️ Heads up bestie: offline mode can give you different dependency resolution than online mode. Not a bug, just the vibe. Do your cargo-fetch(1) first, okay? 🫢
  • --frozen β€” Equivalent to specifying both --locked and --offline. Two-for-one deal πŸ’…
  • --lockfile-path PATH β€” Changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock (e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that providing --lockfile-path will ignore existing lockfile at the default path, and instead will either use the lockfile from PATH, or write a new lockfile into the provided PATH if it doesn't exist. This flag can be used to run most commands in read-only directories, writing lockfile into the provided PATH.
πŸŒ™ 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 #14421: https://github.com/rust-lang/cargo/issues/14421). Nightly girlies only, sorry πŸŽ€

πŸ’œ 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 (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. Your bestie when you forget everything πŸ₯Ί
  • -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. Yes she reads your env vars. She's nosy like that. πŸ’œ


πŸ”₯ EXIT STATUS πŸ”₯

  • 0: Cargo succeeded. πŸŽ‰ slay
  • 101: Cargo failed to complete. 😭 it's giving tragedy

⭐ 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 bestie, you ate it πŸ’…βœ¨ This was cargo-clean(1) from the General Commands Manual β€” no cap, that's the whole footer: just CARGO-CLEAN(1). Go forth and clean responsibly πŸ§ΌπŸŽ€πŸ«Ά

πŸ“¦ where this page comes from