cargo icon indicating copy to clipboard operation
cargo copied to clipboard

cargo clean --bin ... does not work

Open vporton opened this issue 2 years ago • 1 comments

Problem

I have

[[bin]]
name = "migrate"

in my Cargo.toml.

When I try to delete this target, it does not work:

$ cargo clean --bin migrate
error: Found argument '--bin' which wasn't expected, or isn't valid in this context

Steps

  1. Create a package with [[bin]].
  2. Compile it.
  3. Try to remove.

Possible Solution(s)

cargo clean --bin ... should remove the binary.

Notes

No response

Version

cargo 1.61.0 (a028ae4 2022-04-29)
release: 1.61.0
commit-hash: a028ae42fc1376571de836be702e840ca8e060c2
commit-date: 2022-04-29
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1m)
os: Ubuntu 22.04 (jammy) [64-bit]

vporton avatar Jul 24 '22 17:07 vporton

As the error message conveys, there is no --bin flag for cargo clean.

Could you elaborate more on what "remove the binary" means? My current understanding is that you want to remove all the compilation outputs associated with your binary target. AFAIK, cargo clean doesn't provide such ability at this moment. Those outputs are not tracked with the Cargo target as which they are built.

Actually, files under target dir are hardly tracked where they come. Some outputs might be shared between different targets or crates, making it even more difficult to know their origin.

weihanglo avatar Jul 24 '22 18:07 weihanglo