Skip to content
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

Add an example enabling Rust incremental builds #1185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jorendorff
Copy link
Contributor

@jorendorff jorendorff commented Jun 12, 2023

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 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)
  • Documentation (add or update README or docs)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • 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.
  • All new and existing tests passed.

Changes to rust-toolchain.toml should invalidate the cache.
Also, add an example with incremental builds.
@jorendorff jorendorff requested a review from a team as a code owner June 12, 2023 16:32
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml') }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-cargo-${{ hashFiles(**/'Cargo.lock', 'rust-toolchain.toml') }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first apostrophe in **/'Cargo.lock' seems out of place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants