rust-lang / rust-lang/cargo

Consider allowing reuse of metadata between `cargo check` and `cargo build`

Open
#3,501 12 comments 32 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-caching C-feature-request Command-build Command-check E-hard Performance S-blocked-external
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

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 by cargo 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. Compiling conrod and its dependencies with cargo check takes more than 3.5 minutes on my system. If cargo check was able to reuse cargo 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 that cargo check also recompiles dependencies between debug and release 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining how cargo check and cargo build produce and select dependency artifacts, especially metadata-only versus metadata-plus-codegen outputs. Determine the architecture needed to reuse compatible build artifacts across the two commands and configurations. Done means cargo check avoids unnecessary dependency recompilation without changing correctness or respecting configuration-dependent metadata such as cfg(debug_assertions).

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.