mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 22:30:03 +00:00
ci: Switch to Swatinem/rust-cache@v2
(#1113)
Fixed #1038 sccache is not very effective at caching dependencies, the external C/C++ is recompiled in every ci and it takes a lot of time. Compilation of other Rust dependencies also takes quite some time and sccache is not helping at all, so I decided to switch to `Swatinem/rust-cache@v2`. The downside of the new caching method is that a new cache conntaining part of the `.cargo/` and `target/` will be created whenver `Cargo.lock`/`Cargo.toml` changes, but it can still reuse the old cache to create new caching. This is acceptable given that `sccache` often fails to reuse cache due to rate limiting from GHA, since it is not designed for use like a s3 object pool, and `sccache` will create a lot of new cache artifacts for a given branch that cannot be reused in main and would have to cleanup via a cronjob. Edit: rust 1.70 uses llvm 16.0, however ubuntu-latest still uses llvm 15.0 As such, during release-build, cross-lang-lto failed due to llvm is too old. Temporarily disable linker-plugin-lto to fix this. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
9ecfce4104
commit
b69c082160
4 changed files with 22 additions and 55 deletions
55
.github/actions/just-setup/action.yml
vendored
55
.github/actions/just-setup/action.yml
vendored
|
@ -14,10 +14,6 @@ inputs:
|
||||||
required: true
|
required: true
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
cache-suffix:
|
|
||||||
description: Suffix for cache key
|
|
||||||
required: false
|
|
||||||
default: ""
|
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
|
@ -26,11 +22,6 @@ runs:
|
||||||
run: echo "tools=just" >>$GITHUB_ENV
|
run: echo "tools=just" >>$GITHUB_ENV
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- if: inputs.buildcache
|
|
||||||
name: Add sccache to tools to install
|
|
||||||
run: echo "tools=$tools,sccache" >>$GITHUB_ENV
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Add inputs.tools to tools to install
|
- name: Add inputs.tools to tools to install
|
||||||
if: inputs.tools != ''
|
if: inputs.tools != ''
|
||||||
env:
|
env:
|
||||||
|
@ -43,44 +34,26 @@ runs:
|
||||||
with:
|
with:
|
||||||
tool: ${{ env.tools }}
|
tool: ${{ env.tools }}
|
||||||
|
|
||||||
- if: inputs.indexcache
|
|
||||||
name: Configure index cache
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.cargo/registry/index/
|
|
||||||
~/.cargo/registry/cache/
|
|
||||||
~/.cargo/git/db/
|
|
||||||
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}-${{ inputs.cache-suffix }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}-
|
|
||||||
${{ runner.os }}-cargo-index-
|
|
||||||
|
|
||||||
- name: Install rust toolchains
|
- name: Install rust toolchains
|
||||||
run: just toolchain
|
run: just toolchain
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: rustc version
|
- name: rustc version
|
||||||
run: rustc -vV | tee rustc-version
|
run: rustc -vV
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- if: inputs.buildcache
|
- name: Retrieve RUSTFLAGS for caching
|
||||||
name: Configure sccache
|
if: inputs.indexcache || inputs.buildcache
|
||||||
uses: actions/github-script@v6
|
id: retrieve-rustflags
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
|
|
||||||
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
|
|
||||||
|
|
||||||
- if: inputs.buildcache
|
|
||||||
name: Export env for sccache to work
|
|
||||||
shell: bash
|
|
||||||
run: |
|
run: |
|
||||||
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
|
if [ -n "${{ inputs.buildcache }}" ]; then
|
||||||
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
|
echo RUSTFLAGS="$(just print-rustflags)" >> "$GITHUB_OUTPUT"
|
||||||
echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV
|
else
|
||||||
|
echo RUSTFLAGS= >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
- uses: webiny/action-post-run@3.0.0
|
- if: inputs.indexcache || inputs.buildcache
|
||||||
id: post-run-command
|
uses: Swatinem/rust-cache@v2
|
||||||
with:
|
env:
|
||||||
run: sccache --show-stats
|
RUSTFLAGS: ${{ steps.retrieve-rustflags.outputs.RUSTFLAGS }}
|
||||||
|
|
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
|
@ -47,8 +47,6 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: ./.github/actions/just-setup
|
- uses: ./.github/actions/just-setup
|
||||||
with:
|
|
||||||
cache-suffix: ${{ env.CARGO_BUILD_TARGET }}
|
|
||||||
env:
|
env:
|
||||||
# just-setup use binstall to install sccache,
|
# just-setup use binstall to install sccache,
|
||||||
# which works better when we provide it with GITHUB_TOKEN.
|
# which works better when we provide it with GITHUB_TOKEN.
|
||||||
|
@ -78,8 +76,6 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: ./.github/actions/just-setup
|
- uses: ./.github/actions/just-setup
|
||||||
with:
|
|
||||||
cache-suffix: ${{ env.CARGO_BUILD_TARGET }}
|
|
||||||
env:
|
env:
|
||||||
# just-setup use binstall to install sccache,
|
# just-setup use binstall to install sccache,
|
||||||
# which works better when we provide it with GITHUB_TOKEN.
|
# which works better when we provide it with GITHUB_TOKEN.
|
||||||
|
@ -97,8 +93,6 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: ./.github/actions/just-setup
|
- uses: ./.github/actions/just-setup
|
||||||
with:
|
|
||||||
cache-suffix: ${{ env.CARGO_BUILD_TARGET }}
|
|
||||||
env:
|
env:
|
||||||
# just-setup use binstall to install sccache,
|
# just-setup use binstall to install sccache,
|
||||||
# which works better when we provide it with GITHUB_TOKEN.
|
# which works better when we provide it with GITHUB_TOKEN.
|
||||||
|
@ -115,8 +109,6 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: ./.github/actions/just-setup
|
- uses: ./.github/actions/just-setup
|
||||||
with:
|
|
||||||
cache-suffix: ${{ env.CARGO_BUILD_TARGET }}
|
|
||||||
env:
|
env:
|
||||||
# just-setup use binstall to install sccache,
|
# just-setup use binstall to install sccache,
|
||||||
# which works better when we provide it with GITHUB_TOKEN.
|
# which works better when we provide it with GITHUB_TOKEN.
|
||||||
|
@ -141,8 +133,6 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: ./.github/actions/just-setup
|
- uses: ./.github/actions/just-setup
|
||||||
with:
|
|
||||||
cache-suffix: ${{ matrix.target }}
|
|
||||||
|
|
||||||
- run: just toolchain rustfmt,clippy
|
- run: just toolchain rustfmt,clippy
|
||||||
- run: just ci-install-deps
|
- run: just ci-install-deps
|
||||||
|
|
1
.github/workflows/release-build.yml
vendored
1
.github/workflows/release-build.yml
vendored
|
@ -52,7 +52,6 @@ jobs:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: ./.github/actions/just-setup
|
- uses: ./.github/actions/just-setup
|
||||||
with:
|
with:
|
||||||
cache-suffix: release-${{ matrix.t }}
|
|
||||||
tools: cargo-auditable
|
tools: cargo-auditable
|
||||||
env:
|
env:
|
||||||
# just-setup use binstall to install sccache and cargo-auditable,
|
# just-setup use binstall to install sccache and cargo-auditable,
|
||||||
|
|
11
justfile
11
justfile
|
@ -128,10 +128,12 @@ rustc-icf := if for-release != "" {
|
||||||
|
|
||||||
# Only enable linker-plugin-lto for release
|
# Only enable linker-plugin-lto for release
|
||||||
# Also disable this on windows since it uses msvc.
|
# Also disable this on windows since it uses msvc.
|
||||||
|
#
|
||||||
|
# Temporarily disable this on linux due to mismatch llvm version
|
||||||
|
# } else if target-os == "linux" {
|
||||||
|
# "-C linker-plugin-lto "
|
||||||
linker-plugin-lto := if for-release == "" {
|
linker-plugin-lto := if for-release == "" {
|
||||||
""
|
""
|
||||||
} else if target-os == "linux" {
|
|
||||||
"-C linker-plugin-lto "
|
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
@ -169,7 +171,10 @@ toolchain components="":
|
||||||
{{ if target != "" { "rustup target add " + target } else { "" } }}
|
{{ if target != "" { "rustup target add " + target } else { "" } }}
|
||||||
|
|
||||||
print-env:
|
print-env:
|
||||||
echo "env RUSTFLAGS='$RUSTFLAGS', CARGO='$CARGO'"
|
@echo "env RUSTFLAGS='$RUSTFLAGS', CARGO='$CARGO'"
|
||||||
|
|
||||||
|
print-rustflags:
|
||||||
|
@echo "$RUSTFLAGS"
|
||||||
|
|
||||||
build: print-env
|
build: print-env
|
||||||
{{cargo-bin}} build {{cargo-build-args}}
|
{{cargo-bin}} build {{cargo-build-args}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue