name: 'Install Rust toolchain' description: 'Install a rust toolchain and cache the crates index' inputs: toolchain: description: 'Default toolchan to install' required: false default: 'stable' lockfiles: description: 'Path glob for Cargo.lock files to use as cache keys' required: false default: '**/Cargo.lock' runs: using: composite steps: - name: Install Rust shell: bash run: | rustup set profile minimal rustup update "${{ inputs.toolchain }}" --no-self-update rustup default "${{ inputs.toolchain }}" # Save disk space by avoiding incremental compilation. Also turn down # debuginfo from 2 to 1 to help save disk space. cat >> "$GITHUB_ENV" <> "$GITHUB_ENV" fi if [[ "${{ runner.os }}" = "macOS" ]]; then cat >> "$GITHUB_ENV" <> $GITHUB_ENV - name: Cache Cargo registry index uses: actions/cache@v3 with: path: ~/.cargo/registry/index/ key: cargo-registry-${{ env.CARGO_REGISTRY_CACHE_KEY }} # Any older registry-index cache is still valid. It's a git clone, so # cargo only has to pull down the changes since the index was cached. restore-keys: cargo-registry- - name: Cache crate sources for dependencies uses: actions/cache@v3 with: path: | ~/.cargo/registry/cache/ ~/.cargo/git/db/ key: cargo-crates-${{ inputs.lockfiles }}-${{ hashFiles(inputs.lockfiles) }} # If Cargo.lock has changed, we probably will need to get the source # code for some crates we don't already have. But any crates we have # source cached for are still valid. The only problem is nothing # removes old crate sources from the cache, so using `restore-keys` # this way may use more of our GitHub cache quota than we'd like. # # Also, scope this cache by which Cargo.lock we're building from. # Otherwise, whichever job writes the cache first will get its # dependencies cached, and that cache will be used as the basis for the # next job, even though odds are pretty good the cache is useless. restore-keys: cargo-crates-${{ inputs.lockfiles }}- # TODO: on cache miss, after cargo has updated the registry index, run `git gc`