-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider allowing reuse of metadata between cargo check
and cargo build
#3501
Comments
cc @nrc We discussed this a bit on the original PR and the implementation is quite non-trivial, but it'd definitely be a welcome improvement! |
Ideally, metadata would be shared between cargo check and cargo build, and even tools like cargo-clippy. But this might require significant changes in the underlying architecture. |
cargo check
to reuse metadata generated by cargo build
cargo check
and cargo build
Do you have a pointer to that discussion? That may be naive, but I kind of thought it couldn't be too hard to consider cargo an rlib as satisfying a dependency on an rmeta. I considered trying to implement this. However, I know nothing about the internal architecture of Cargo. EDIT: Ah, #3341 has some details. Sounds harder than I had expected indeed. |
Weird yeah I can't find what I thought was original-original discussion... But yeah it ends up being tricky due to how cargo is architected right now :( |
#4831 would potentially solve this by causing |
cargo doc: Generate rmeta files for dependencies instead of compiling rlibs This makes `cargo doc` require only metadata (`.rmeta` files) instead of compiled libraries (`.rlib` files) for dependencies. This makes `cargo doc` faster in cases where rlibs are not already built and/or metadata is already available. Unfortunately, this is not a win for every workflow. In the case where the user has already compiled but has not generated metadata, it makes `cargo doc` do extra work. This is probably a common case, though tools like RLS and `cargo check` mean that many developers *will* have up-to-date metadata available. It would become an unequivocal win if `cargo build` and `cargo check` re-used shared metadata (#3501). For now, starting from a clean working directory, the following sequences of commands will become: * `cargo doc`: faster * `cargo build; cargo doc`: slower * `cargo check; cargo doc`: faster * `cargo build --release; cargo doc`: faster * `cargo check; cargo build; cargo doc`: no change
I was recently surprised by the current behavior when compiling servo : I spent two hours compiling it (yes, in debug mode. I know my computer is getting old) and I was really disappointed when everything needed to be done again when I ran my first |
Ditto for the playground, where this is also an impact on file size. Clippy uses |
Does the recent efforts around pipelined compilation help here? Is or could the metadata file emitted by a pipelined |
The It may be possible for |
I wrote down some observations for real workspace on the Rust forum: Same non-duplicate dependency generates four metadata files and two |
As I understand it, objects generated by
cargo build
also contain metadata, since it's information required by rustc.Could it be possible for
cargo check
to reuse metadata generated bycargo build
?Currently, if you are using
cargo check
and have a large dependency chain, you effectively have to recompile it twice. Once for metadata-only, once for metadata+codegen. Even if we compile metadata-only, compiling a large dependency chain can still take a significant amount of time. Compilingconrod
and its dependencies withcargo check
takes more than 3.5 minutes on my system. Ifcargo check
was able to reusecargo build
artifacts, that would shave 3.5 minutes off when I had to recompile the dependency chain (nightly upgrade, etc.).As an aside, the old
cargo-check
crate worked this way. You didn't have to recompile dependencies twice in order to use it. But I understand that the new one is more sophisticated, so it doesn't necessarily have to be able to operate this way.I've also noticed thatcargo check
also recompiles dependencies betweendebug
andrelease
modes. I don't see why there should be separate metadata for debug and release. It should reuse the same metadata.EDIT: cfg(debug_assertions) is a thing
I think it's a worthy pursuit to redesign the underlying architecture in order to avoid recompiling as much as possible. After all, that's the whole point of
cargo check
: To quickly check things without having to wait for things to build.The text was updated successfully, but these errors were encountered: