Add caching for submodules and CMake to Windows CI. (#11906)
This uses GitHub's [actions/cache](https://github.com/actions/cache)
together with [ccache](https://ccache.dev/) to speed up our
`build_test_all_windows` GitHub Actions CI job. I also tested caching
with the `build_test_runtime_windows` job, but benefits were negligible
there.
We use ccache for our CMake Linux jobs, but those jobs are running on
self-hosted runners and not GitHub-managed runners. The self-hosted
runners have write access to the GCS bucket we store our remote cache
in, while the GitHub-managed runners do not. The
[actions/cache](https://github.com/actions/cache) action can be used to
similarly store a remote cache, though with more steps in the job
definitions.
Git submodules have been taking much longer to update on Windows than on
Linux (6-10 minutes vs 1-2 minutes). We can similarly use the cache
action to start the `.git/modules/` directory with an initial set of
files, at least until git or
[actions/checkout](https://github.com/actions/checkout) improves
behavior on Windows.
This uses two caches: one for git submodules and one for ccache. The
caches are always read/restored, and they are only written/saved when
`needs.setup.outputs.write-caches` is true (currently only when running
workflows on postsubmit).
Note: we have 10GB of cache per repository, which is space for about 4
commits worth of cache entries at current sizes (2.4GB). I'm using
`ccache_all_windows_${{ github.sha }}` as the primary key for immutable
cache entries, then `ccache_all_windows` as the "restore" key pattern,
which will match the most recently added cache entry. Cache entries can
be managed at https://github.com/iree-org/iree/actions/caches.
Progress on https://github.com/iree-org/iree/issues/11009. Once this
lands we can probably move the `build_test_all_windows` job to run on
presubmit.
## Experimental results:
Note: these are best-case results. I've also observed many cache misses
where hits would be expected, so more analysis will be needed.
### `build_test_runtime_windows`
cache size: 27MB (git) + 59MB (ccache) = 86MB (total)
Configuration | Logs | total time | submodule checkout timing | build
timing
------------- | ---- | ---------- | ------------------------- |
------------
baseline |
[logs](https://github.com/iree-org/iree/actions/runs/3956450018/jobs/6775683130)
| 4m 20s | 35s | 1m 13s
new (cache miss) |
[logs](https://github.com/iree-org/iree/actions/runs/3963023407/jobs/6790395857)
| 5m 26s | 39s | 1m50s
new (cache hit) |
[logs](https://github.com/iree-org/iree/actions/runs/3963233498/jobs/6790837992)
| 4m 5s | 20s | 42s
### `build_test_all_windows`
cache size: 230MB (git) + 2167MB (ccache) = 2397MB (total)
Configuration | Logs | total time | submodule checkout timing | build
timing
------------- | ---- | ---------- | ------------------------- |
------------
baseline |
[logs](https://github.com/iree-org/iree/actions/runs/3956450018/jobs/6775681967)
| 31m 16s | 5m 58s | 22m 46s
new (cache miss) |
[logs](https://github.com/iree-org/iree/actions/runs/3963023407/jobs/6790395752)
| 30m 8s | 6m 30s | 14m 55s
new (cache hit) |
[logs](https://github.com/iree-org/iree/actions/runs/3963233498/jobs/6790837849)
| 14m 9s | 1m15s | 4m34s
Note: 5 minutes of the total time is spent uploading cache data, which
will only happen on postsubmit.diff --git a/build_tools/cmake/build_android.sh b/build_tools/cmake/build_android.sh
index cb4d271..c444386 100755
--- a/build_tools/cmake/build_android.sh
+++ b/build_tools/cmake/build_android.sh
@@ -94,6 +94,6 @@
echo "------------------"
"${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-sample-deps -- -k 0
-if (( IREE_READ_REMOTE_CCACHE == 1 )); then
+if (( IREE_USE_CCACHE == 1 )); then
ccache --show-stats
fi