Skip to content

Cache toolchain, dependencies in PR/CI #3158

@heaths

Description

@heaths

Rust builds seem to be taking longer lately, presumably to set up older toolchains the agents may not have since we target older versions by design. But caching certain directories can help a lot. I use the following in nearly all my Rust repos and it makes a significant improvement in build time.

https://github.com/heaths/akv-cli-rs/blob/241c9ccc84be7ba277c5483192ba3f0714215c64/.github/workflows/ci.yml#L36-L45

    - name: Cache
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/bin/
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
          target/
        key: ${{ runner.os }}-${{ runner.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }}

Using the right cache key - including the toolchain (version), platform, and a hash of Cargo.lock - we can handle all the variations we have.

Metadata

Metadata

Assignees

Labels

EngSysThis issue is impacting the engineering system.

Projects

Status

Untriaged

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions