-
Notifications
You must be signed in to change notification settings - Fork 59
Added cargo cache improvements 2025H2 goal #317
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
Open
ranger-ross
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
ranger-ross:better-cargo-caching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Cargo Caching Improvements | ||
|
||
| Metadata | | | ||
|:-----------------|----------------------------------------------------------------------------------| | ||
| Point of contact | @ranger-ross | | ||
| Teams | <!-- TEAMS WITH ASKS --> | | ||
| Task owners | <!-- TASK OWNERS --> | | ||
| Status | Proposed | | ||
| Tracking issue | *if this is a continuing goal, add the old tracking issue, else leave blank* | | ||
| Zulip channel | N/A (an existing stream can be re-used or new streams can be created on request) | | ||
|
||
## Summary | ||
|
||
Rework the Cargo build directory layout to enable a shared build cache across multiple workspaces. | ||
|
||
|
||
## Motivation | ||
|
||
The primary goal of this effort is to improve build times by reusing builds across projects. | ||
|
||
Secondary goals are | ||
|
||
* Reduce disk usage of build artifacts | ||
* More precise cross-job caching in CI | ||
|
||
### The status quo | ||
|
||
When Cargo performs a build, it will build the package you requested and all | ||
dependencies individually, linking them in the end. | ||
These build results (intermediate build artifacts) and the linked result (final | ||
build artifact) are stored in the target-dir, which is per-workspace by | ||
default. | ||
|
||
Ways cargo will try to reuse builds today: | ||
- On a subsequent build, Cargo tries to reuse these build results by | ||
"fingerprinting" the inputs to the prior build and checking if that | ||
fingerprint has changed. | ||
- When dependencies are shared by host (`build.rs`, proc-macros) and | ||
platform-target and the platform-target is the host, Cargo will attempt to | ||
share host/target builds | ||
|
||
Some users try to get extra cache reuse by assigning all workspaces to use the same target-dir. | ||
- Cross-project conflicts occur because this shares both intermediate (generally unique) and final build artifacts (might not be unique) | ||
- `cargo clean` will clear the entire cache for every project | ||
- Rebuild churn from build inputs, like `RUSTFLAGS`, that cause a rebuild but aren't hashed into the file path | ||
|
||
In CI, users generally have to declare what directory should be cached between jobs. | ||
This directory will be compressed and uploaded at the end of the job. | ||
If the next job's cache key matches, the tarball will be downloaded and decompressed. | ||
If too much is cached, the time for managing the cache can dwarf the benefits of the cache. | ||
Some third-party projects exist to help manage cache size. | ||
|
||
### The next 6 months | ||
|
||
* Stabilize Cargo `build-dir` which allows users to move intermediate build artifacts out of `target` (rust-lang/cargo#14125) | ||
* Rework the build directory layout so that we have more easily cacheable "units" (rust-lang/cargo#15010) | ||
* Work towards a user wide build cache that can be reused across projects/workspaces. (rust-lang/cargo#5931) | ||
* Explore possibilities of extending this build cache to support remote storage enabling continuous integration use cases. | ||
|
||
### The "shiny future" we are working towards | ||
|
||
The cache lookup will be extended with plugins to read and/or write to different sources. Open source projects and companies can have their CI read from and write to their cache. Individuals who trust the CI can then configure their plugin to read from the CI cache. | ||
|
||
A cooperating CI service could provide their own plugin that, instead of caching everything used in the last job and unpacking it in the next, their plugin could download only the entries that will be needed for the current build (e.g. say a dependency changed) and only upload the cache entries that were freshly built. Fine-grained caching like this would save the CI service on bandwidth, storage, and the compute time from copying, decompressing, and compressing the cache. Users would have faster CI time and save money on their CI service, minus any induced demand that faster builds creates. | ||
|
||
|
||
## Ownership and team asks | ||
|
||
| Task | Owner(s) or team(s) | Notes | | ||
|------------------------------|---------------------|-------| | ||
| Standard reviews | ![Team][] [cargo] | | | ||
| Implementation | @ranger-ross | | | ||
|
||
|
||
### Definitions | ||
|
||
For definitions for terms used above, see the [About > Team Asks](https://rust-lang.github.io/rust-project-goals/about/team_asks.html) page. | ||
|
||
* *Discussion and moral support* is the lowest level offering, basically committing the team to nothing but good vibes and general support for this endeavor. | ||
* *Author RFC* and *Implementation* means actually writing the code, document, whatever. | ||
* *Design meeting* means holding a synchronous meeting to review a proposal and provide feedback (no decision expected). | ||
* *RFC decisions* means reviewing an RFC and deciding whether to accept. | ||
* *Org decisions* means reaching a decision on an organizational or policy matter. | ||
* *Secondary review* of an RFC means that the team is "tangentially" involved in the RFC and should be expected to briefly review. | ||
* *Stabilizations* means reviewing a stabilization and report and deciding whether to stabilize. | ||
* *Standard reviews* refers to reviews for PRs against the repository; these PRs are not expected to be unduly large or complicated. | ||
* *Prioritized nominations* refers to prioritized lang-team response to nominated issues, with the expectation that there will be *some* response from the next weekly triage meeting. | ||
* *Dedicated review* means identifying an individual (or group of individuals) who will review the changes, as they're expected to require significant context. | ||
* Other kinds of decisions: | ||
* [Lang team experiments](https://lang-team.rust-lang.org/how_to/experiment.html) are used to add nightly features that do not yet have an RFC. They are limited to trusted contributors and are used to resolve design details such that an RFC can be written. | ||
* Compiler [Major Change Proposal (MCP)](https://forge.rust-lang.org/compiler/mcp.html) is used to propose a 'larger than average' change and get feedback from the compiler team. | ||
* Library [API Change Proposal (ACP)](https://std-dev-guide.rust-lang.org/development/feature-lifecycle.html) describes a change to the standard library. | ||
|
||
## Frequently asked questions | ||
|
||
### Why not pre-built packages? | ||
|
||
Pre-built packages requires guessing | ||
- CPU Architecture | ||
- Feature flags | ||
- RUSTFLAGS | ||
- Dependency versions | ||
|
||
If there are any mismatches there, then the pre-built package can't be used. | ||
|
||
A build cache can be populated with pre-built packages and react to the unique circumstances of the user. | ||
|
||
### Why not sccache? | ||
|
||
Tools like sccache try to infer inputs for hashing a cache key from command-line arguments. | ||
This has us reusing the extra knowledge Cargo has to get more accurate cache key generation. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something we discussed today in the cargo team meeting is that this seems a little ambitious for a 6-month goal. I'm not sure what changes would be appropriate, but maybe @epage has some ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought was to scale this down to the build directory layout re-work + experiments with an alternative locking scheme to try to help with r-a today and inform the locking scheme we use on the shared cache.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, seems reasonable. I suppose nothing is stopping us from continuing towards the shared cache if things go quicker than expected.
I'll update this goal later this week.