@@ -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