mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
CI: Cache zig global_cache to speedup build (#1481)
* CI: Cache zig global_cache to speedup build This can be helpful in two situations: - If `cc` is bumped to a new release, then all the `*-sys` crates will be rebuilt even if their source doesn't change. Caching zig global_cache would avoid expensive rebuilds. - For target `x86_64h-apple-darwin`, it uses build-std which means the rust cache is quite ineffective (only build-dependencies are cached), so we would also need zig global_cache to avoid rebuilding c dependencies in CI. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix missing `shell: bash` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix CI: Create symlink to `zig` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * CI: Fix getting output from prev step in just-setup Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * CI: Include job_id `github.job` in zig cache key Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> --------- Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
8dff97a0a2
commit
5064e4e188
1 changed files with 39 additions and 2 deletions
41
.github/actions/just-setup/action.yml
vendored
41
.github/actions/just-setup/action.yml
vendored
|
@ -19,14 +19,14 @@ runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- name: Add just to tools to install
|
- name: Add just to tools to install
|
||||||
run: echo "tools=just" >>$GITHUB_ENV
|
run: echo "tools=just" >>"$GITHUB_ENV"
|
||||||
shell: bash
|
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:
|
||||||
inputs_tools: ${{ inputs.tools }}
|
inputs_tools: ${{ inputs.tools }}
|
||||||
run: echo "tools=$tools,$inputs_tools" >>$GITHUB_ENV
|
run: echo "tools=$tools,$inputs_tools" >>"$GITHUB_ENV"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Install tools
|
- name: Install tools
|
||||||
|
@ -62,3 +62,40 @@ runs:
|
||||||
env-vars: "CARGO CC CFLAGS CXX CMAKE RUST JUST"
|
env-vars: "CARGO CC CFLAGS CXX CMAKE RUST JUST"
|
||||||
env:
|
env:
|
||||||
RUSTFLAGS: ${{ steps.retrieve-rustflags.outputs.RUSTFLAGS }}
|
RUSTFLAGS: ${{ steps.retrieve-rustflags.outputs.RUSTFLAGS }}
|
||||||
|
|
||||||
|
- name: Find zig location and create symlink to it in ~/.local/bin
|
||||||
|
if: env.JUST_USE_CARGO_ZIGBUILD
|
||||||
|
run: |
|
||||||
|
python_package_path=$(python3 -m site --user-site)
|
||||||
|
ln -s "${python_package_path}/ziglang/zig" "$HOME/.local/bin/zig"
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Calculate zig cache key
|
||||||
|
if: env.JUST_USE_CARGO_ZIGBUILD
|
||||||
|
run: |
|
||||||
|
ZIG_VERSION=$(zig version)
|
||||||
|
SYS_CRATE_HASHSUM=$(cargo tree --all-features --prefix none --no-dedupe --target "$CARGO_BUILD_TARGET" | grep -e '-sys' -e '^ring' | sort -u | sha1sum | sed 's/[ -]*//g')
|
||||||
|
PREFIX=v0-${JOB_ID}-zig-${ZIG_VERSION}-${CARGO_BUILD_TARGET}-
|
||||||
|
echo "ZIG_CACHE_KEY=${PREFIX}${SYS_CRATE_HASHSUM}" >> "$GITHUB_ENV"
|
||||||
|
echo -e "ZIG_CACHE_RESTORE_KEY=$PREFIX" >> "$GITHUB_ENV"
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: ${{ steps.retrieve-rustflags.outputs.RUSTFLAGS }}
|
||||||
|
JOB_ID: ${{ github.job }}
|
||||||
|
|
||||||
|
- name: Get zig global cache dir
|
||||||
|
if: env.JUST_USE_CARGO_ZIGBUILD
|
||||||
|
id: zig_global_cache_dir_path
|
||||||
|
run: |
|
||||||
|
cache_dir=$(zig env | jq -r '.global_cache_dir')
|
||||||
|
echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT"
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Cache zig compilation
|
||||||
|
if: env.JUST_USE_CARGO_ZIGBUILD
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ${{ steps.zig_global_cache_dir_path.outputs.cache_dir }}
|
||||||
|
key: ${{ env.ZIG_CACHE_KEY }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ env.ZIG_CACHE_RESTORE_KEY }}
|
||||||
|
|
Loading…
Add table
Reference in a new issue