rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.72k stars 2.42k forks source link

Support for custom drivers #6356

Open oli-obk opened 5 years ago

oli-obk commented 5 years ago

Describe the problem you are trying to solve

Currently tools like clippy, miri and rls run cargo via the command line and then try to reconstruct the rustc invocation for the final crate in order to run custom code just for the final crate. Clippy and miri inject a custom driver via the RUSTC env var. During execution of the driver, the driver decides whether it is being invoked for a dependency or for the final crate and then either runs rustc or its own code. Rls runs the full cargo command with rustc, but keeps reinvoking rustc on the final crate.

Futhermore, running cargo check && cargo clippy && cargo check will rebuild all dependencies and the final crate 3 times, even though the latter two calls should just be fetching data from the incremental cache and essentially be nops.

Describe the solution you'd like

I'm currently considering the following two options:

  1. add a flag that one can pass to any cargo subcommand which will, instead of running the compiler, just emit the commands to be invoked in the order in which they are supposed to be invoked.
  2. add a flag that allows cargo check and cargo rustc to replace only the final rustc invocations with a custom driver without causing a rebuild of all dependencies when switching from regular cargo check invocations.

Notes

I'm fine with doing this experimentally by only allowing it on nightly cargo.

killercup commented 5 years ago

Quick note that cargo-fix also uses that mechanism – acting as a custom RUSTC that collects fixes – but since it's part of cargo has different options: It supports "only act on final crate" and "always rebuild final crate", for example.

Edit: relevant discussion on discord

fpoli commented 5 years ago
  1. add a flag that one can pass to any cargo subcommand which will, instead of running the compiler, just emit the commands to be invoked in the order in which they are supposed to be invoked.

I think that this is not enough for crates with multiple binaries or libraries, because they use more than one rustc command for the final crate.