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 to cargo).
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
[ ] Bug fix (non-breaking change which fixes an issue)
[ ] New feature (non-breaking change which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to change)
[x] Documentation (add or update README or docs)
Checklist:
[x] My code follows the code style of this project.
[x] My change requires a change to the documentation.
[x] I have updated the documentation accordingly.
[x] I have read the CONTRIBUTING document.
[ ] I have added tests to cover my changes. - I don't think there are tests for the examples file.
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: