Add an example enabling Rust incremental builds #1185
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.
Description
Add an example of how to get the most out of Rust incremental builds.
Also, changes to rust-toolchain.toml should invalidate the cache.
Motivation and Context
Our Rust builds were taking too long. Rust has a notoriously slow compiler, and we expect many users have the same problem.
Rust's compiler has a feature to help in this situation: incremental builds.
actions/cache
does not directly support having each job start with the build directory produced by the previous successful build. But Rust's compiler can save a significant amount of work if you do things this way. In each build, it only has to compile the code that has actually changed.With a typical
actions/cache
configuration, Rust ends up doing more and more work with each push, as the changes between the cached build and the current build accumulate. With the example added in this PR, the cached build will be the latest. Incremental builds will then kick in automatically (you don't have to pass any special flags tocargo
).The only downside is that this produces more cache entries. It creates a new cache entry after every successful run, not just when the cache is invalidated. I don't know if that's likely to make problems for anyone. If so, let's talk about it.
Adding
rust-toolchain.toml
is an independent, minor change. If your project has that file, it selects which version of the Rust compiler you're using and which components of Rust to install. When you change versions, Rust will recompile all your code anyway, so there's little point using the cache.How Has This Been Tested?
We've been using this technique in @github/blackbird for months now.
Types of changes
Checklist: