Skip to content

Commit b909f87

Browse files
committed
Don't share target-cpu=native cache between github runners with different hardware
1 parent 8f1d4a7 commit b909f87

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,22 @@ jobs:
302302
- name: Checkout sources
303303
uses: actions/checkout@v4
304304

305+
# Cargo doesn't know when to rebuild a target-cpu=native cache when it's
306+
# migrated across machines, so a CI node must not be exposed to the target
307+
# directory generated by another CI node in target-cpu=native mode.
308+
- name: Avoid abusive caching with target-cpu=native
309+
run: |
310+
if [[ ${RUSTFLAGS} =~ '-C target-cpu=native' ]]; then
311+
cp /proc/cpuinfo cpuinfo.key
312+
else
313+
echo "Generic x86_64" >cpuinfo.key
314+
fi
315+
305316
- name: Set up toolchain
306317
uses: actions-rust-lang/setup-rust-toolchain@v1
307318
with:
308319
toolchain: ${{ matrix.toolchain }}
320+
cache-key: ${{ hashFiles(cpuinfo.key) }}
309321

310322
- name: Run tests
311323
run: cargo test --workspace ${{ matrix.cargo-flags }}

0 commit comments

Comments
 (0)