cargo build should have --force option

Created on 29 Dec 2014  路  6Comments  路  Source: rust-lang/cargo

Sometimes I need to force a rebuild of a target, because it compiled successfully but I want to see the generated warnings. It would be convenient if cargo build accepted a --force flag that makes it consider the current target to be dirty even if it's not. This should not force the recompilation of any dependencies.

A-features

Most helpful comment

I also think it would be worth reopening this, as others have pointed out, this should be more accessible to beginners ("Where have my compiler warnings / clippy lints gone?").

I think the key thing here is to inform the user that some targets are not being compiled at all, explicitly (i.e. as opposed to just not outputting Compiling xyz ...), something like:

Reusing up-to-date compiled targets, run `cargo clean -p <local-pkg> && cargo build`
(`cargo clean && cargo build`) to force recompilation of project (and dependencies).

Whether the message points to the already available solution, or whether a new flag should be added ("run with --force (--force-all)"), is an issue of lesser importance, though personally I would also welcome a less verbose way of achieving this :)

All 6 comments

We do have cargo clean -p <local-pkg> && cargo build, would that suffice for this?

@kballard what do you think about @alexcrichton 's suggestion?

I suppose that's an acceptable workaround. Since nobody else has requested this, I'll go ahead and close it.

This isn't particularly discoverable - I didn't try --force (to me that's not quite right for this) but I was looking through cargo build --help for some option to achieve this behaviour.

Has having an alias, such as cargo build --clean, been considered?

My use case isn't regenerating warnings, but developing a compiler plugin, and just wanting to 'run' it again.

I second this. It's hard, especially for a new user when filing bug reports to figure out how to re-compile everything to show the warnings again.

I also think it would be worth reopening this, as others have pointed out, this should be more accessible to beginners ("Where have my compiler warnings / clippy lints gone?").

I think the key thing here is to inform the user that some targets are not being compiled at all, explicitly (i.e. as opposed to just not outputting Compiling xyz ...), something like:

Reusing up-to-date compiled targets, run `cargo clean -p <local-pkg> && cargo build`
(`cargo clean && cargo build`) to force recompilation of project (and dependencies).

Whether the message points to the already available solution, or whether a new flag should be added ("run with --force (--force-all)"), is an issue of lesser importance, though personally I would also welcome a less verbose way of achieving this :)

Was this page helpful?
0 / 5 - 0 ratings