Skip to content

Commit 0172a2a

Browse files
Try smarter FFI cache
1 parent bcb5bf0 commit 0172a2a

2 files changed

Lines changed: 77 additions & 9 deletions

File tree

.github/workflows/builds.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ jobs:
145145
fi
146146
147147
# ---------- Cache Cargo ----------
148+
# The Rust FFI is built from the pinned client-sdk-rust submodule. Its
149+
# compiled output only changes when the submodule commit changes, so we
150+
# key the target cache on the submodule SHA (not Cargo.lock, which is
151+
# pinned inside the submodule and effectively immutable -- that froze the
152+
# old cache permanently). Resolve it once here for the restore/save steps.
153+
- name: Resolve Rust submodule SHA
154+
id: rust_sha
155+
shell: bash
156+
run: echo "sha=$(git -C client-sdk-rust rev-parse HEAD)" >> "$GITHUB_OUTPUT"
157+
148158
- name: Cache cargo registry
149159
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
150160
with:
@@ -156,11 +166,17 @@ jobs:
156166
restore-keys: |
157167
${{ runner.os }}-${{ matrix.name }}-cargo-registry-
158168
159-
- name: Cache cargo target
160-
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
169+
# Restore-only here; the matching save runs after a successful build (see
170+
# "Save cargo target" below). A combined actions/cache saves in a post-job
171+
# step that runs AFTER the "Clean after build" cleanup wipes target/debug
172+
# and target/release, which is why the old cache was always ~empty. The
173+
# restore/save split lets us snapshot the populated target/ before cleanup.
174+
- name: Restore cargo target
175+
id: cache-cargo-target
176+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
161177
with:
162178
path: client-sdk-rust/target/
163-
key: ${{ runner.os }}-${{ matrix.name }}-cargo-target-${{ hashFiles('client-sdk-rust/Cargo.lock') }}
179+
key: ${{ runner.os }}-${{ matrix.name }}-cargo-target-${{ steps.rust_sha.outputs.sha }}
164180
restore-keys: |
165181
${{ runner.os }}-${{ matrix.name }}-cargo-target-
166182
@@ -191,6 +207,18 @@ jobs:
191207
shell: bash
192208
run: sccache --show-stats || true
193209

210+
# Save the populated target/ now, while the build output still exists and
211+
# before the "Clean after build" step runs clean-all. Only on a miss --
212+
# an exact-key hit means the cache already holds this submodule's output.
213+
# A restore-keys prefix hit still counts as a miss (cache-hit != 'true'),
214+
# so a submodule bump always refreshes the cache under the new SHA.
215+
- name: Save cargo target
216+
if: steps.cache-cargo-target.outputs.cache-hit != 'true'
217+
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
218+
with:
219+
path: client-sdk-rust/target/
220+
key: ${{ runner.os }}-${{ matrix.name }}-cargo-target-${{ steps.rust_sha.outputs.sha }}
221+
194222
# ---------- Smoke test cpp-example-collection binaries ----------
195223
# Built under cpp-example-collection-build/ (not build-dir/bin). Visual Studio
196224
# multi-config places executables in per-target Release/ (or Debug/) subdirs.

.github/workflows/tests.yml

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ jobs:
143143
fi
144144
145145
# ---------- Cache Cargo ----------
146+
# See builds.yml for the rationale: the Rust FFI output only changes with
147+
# the client-sdk-rust submodule commit, so key the target cache on the
148+
# submodule SHA (Cargo.lock is pinned inside the submodule and froze the
149+
# old cache). Restore/save split so the populated target/ is snapshotted
150+
# right after the build instead of in a post-job step.
151+
- name: Resolve Rust submodule SHA
152+
id: rust_sha
153+
shell: bash
154+
run: echo "sha=$(git -C client-sdk-rust rev-parse HEAD)" >> "$GITHUB_OUTPUT"
155+
146156
- name: Cache cargo registry
147157
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
148158
with:
@@ -154,11 +164,12 @@ jobs:
154164
restore-keys: |
155165
${{ runner.os }}-${{ matrix.name }}-cargo-registry-
156166
157-
- name: Cache cargo target
158-
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
167+
- name: Restore cargo target
168+
id: cache-cargo-target
169+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
159170
with:
160171
path: client-sdk-rust/target/
161-
key: ${{ runner.os }}-${{ matrix.name }}-cargo-target-${{ hashFiles('client-sdk-rust/Cargo.lock') }}
172+
key: ${{ runner.os }}-${{ matrix.name }}-cargo-target-${{ steps.rust_sha.outputs.sha }}
162173
restore-keys: |
163174
${{ runner.os }}-${{ matrix.name }}-cargo-target-
164175
@@ -189,6 +200,18 @@ jobs:
189200
shell: bash
190201
run: sccache --show-stats || true
191202

203+
# Snapshot the populated target/ after a successful build. Placed before
204+
# the test steps so the Rust FFI output is cached regardless of whether
205+
# the unit/integration tests pass. Only on a miss (exact-key hit means the
206+
# cache already holds this submodule's output; a restore-keys prefix hit
207+
# still counts as a miss and refreshes under the new SHA).
208+
- name: Save cargo target
209+
if: steps.cache-cargo-target.outputs.cache-hit != 'true'
210+
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
211+
with:
212+
path: client-sdk-rust/target/
213+
key: ${{ runner.os }}-${{ matrix.name }}-cargo-target-${{ steps.rust_sha.outputs.sha }}
214+
192215
# ---------- Run unit tests ----------
193216
- name: Run unit tests (Unix)
194217
if: runner.os != 'Windows'
@@ -366,6 +389,14 @@ jobs:
366389
fi
367390
368391
# ---------- Cache Cargo ----------
392+
# Key the target cache on the client-sdk-rust submodule SHA (see builds.yml
393+
# rationale). Restore/save split so the populated target/ is captured right
394+
# after the build.
395+
- name: Resolve Rust submodule SHA
396+
id: rust_sha
397+
shell: bash
398+
run: echo "sha=$(git -C client-sdk-rust rev-parse HEAD)" >> "$GITHUB_OUTPUT"
399+
369400
- name: Cache cargo registry
370401
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
371402
with:
@@ -377,11 +408,12 @@ jobs:
377408
restore-keys: |
378409
${{ runner.os }}-coverage-cargo-registry-
379410
380-
- name: Cache cargo target
381-
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
411+
- name: Restore cargo target
412+
id: cache-cargo-target
413+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
382414
with:
383415
path: client-sdk-rust/target/
384-
key: ${{ runner.os }}-coverage-cargo-target-${{ hashFiles('client-sdk-rust/Cargo.lock') }}
416+
key: ${{ runner.os }}-coverage-cargo-target-${{ steps.rust_sha.outputs.sha }}
385417
restore-keys: |
386418
${{ runner.os }}-coverage-cargo-target-
387419
@@ -410,6 +442,14 @@ jobs:
410442
- name: Build
411443
run: cmake --build build-debug --parallel 2
412444

445+
# Snapshot the populated target/ after the build succeeds, only on a miss.
446+
- name: Save cargo target
447+
if: steps.cache-cargo-target.outputs.cache-hit != 'true'
448+
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
449+
with:
450+
path: client-sdk-rust/target/
451+
key: ${{ runner.os }}-coverage-cargo-target-${{ steps.rust_sha.outputs.sha }}
452+
413453
# ---------- Run unit tests ----------
414454
- name: Run unit tests
415455
timeout-minutes: 5

0 commit comments

Comments
 (0)