Skip to content

Commit 74e739c

Browse files
committed
Cache library deps on Windows
Besides the immediate performance improvement, reducing the frequency of downloads should make spurious failures (network, rate-limiting...) less bothersome.
1 parent 7409a8c commit 74e739c

6 files changed

Lines changed: 60 additions & 48 deletions

File tree

.github/scripts/get_win_deps.ps1

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/scripts/install_deps.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ case "${1%-*}" in
77
sudo apt-get -qq update
88
sudo apt-get install -yq bison libpng-dev pkg-config
99
;;
10-
macos)
10+
macos)
1111
# macOS bundles GNU Make 3.81, which doesn't support synced output.
1212
# We leave it as the default in `PATH`, to test that our Makefile works with it.
1313
# However, CMake automatically uses Homebrew's `gmake`, so our CI has synced output.
@@ -20,11 +20,17 @@ case "${1%-*}" in
2020
freebsd)
2121
pkg install -y bash bison cmake git png
2222
;;
23+
windows)
24+
choco install -y winflexbison3
25+
# The below expects the base name, not the Windows-specific name.
26+
bison() { win_bison "$@"; } # An alias doesn't work, so we use a function instead.
27+
;;
2328
*)
2429
echo "WARNING: Cannot install deps for OS '$1'"
2530
;;
2631
esac
2732

33+
echo "PATH=($PATH)" | sed 's/:/\n /g'
2834
bison --version
2935
make --version
3036
cmake --version

.github/workflows/create-release-artifacts.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ env:
1414
CMAKE_BUILD_TYPE: Release # `cmake -S` now implies `-DCMAKE_BUILD_TYPE=Release`.
1515
CMAKE_CONFIG_TYPE: Release # `cmake --build` now implies `--config Release`.
1616

17+
# We instruct CMake to download and build third-party projects in the same place as in `testing.yml`
18+
# for the sources cache to remain valid.
19+
DEPS_ROOT_DIR: ~/_deps # Note that this needs to be used in a position where Bash will trigger tilde expansion!
20+
1721
jobs:
1822
windows:
1923
runs-on: windows-2022
@@ -35,11 +39,15 @@ jobs:
3539
- name: Checkout repo
3640
uses: actions/checkout@v4
3741
- name: Install deps
38-
run: .github/scripts/get_win_deps.ps1
42+
run: .github/scripts/install_deps.sh windows
43+
- name: Cache library deps
44+
uses: actions/cache@v5
45+
with:
46+
path: ${{ env.DEPS_ROOT_DIR }}/*-tmp/
47+
key: dep-srcs-${{ hashFiles('cmake/deps.cmake') }}
48+
enableCrossOsArchive: true
3949
- name: Build Windows binaries
4050
shell: bash
41-
# We instruct CMake to download and build third-party projects outside of our source tree,
42-
# otherwise they can trigger `-Werror=dev` (from the `develop` preset).
4351
run: |
4452
cmake -S . -B build -A ${{ matrix.platform }} --preset develop -DFETCHCONTENT_BASE_DIR="$TEMP/cmake-deps" -DBISON_EXECUTABLE=bison/win_bison.exe -DSANITIZERS=OFF
4553
cmake --build build --config Release

.github/workflows/testing.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ env:
1212
CMAKE_INSTALL_PARALLEL_LEVEL: 4 # `cmake --install` now implies `--parallel 4`.
1313
CMAKE_BUILD_TYPE: Debug # `cmake -S` now implies `-DCMAKE_BUILD_TYPE=Debug`.
1414
CMAKE_CONFIG_TYPE: Debug # `cmake --build` now implies `--config Debug`.
15+
16+
# We instruct CMake to download and build third-party projects outside of our source tree,
17+
# otherwise they can trigger `-Werror=dev` (from the `develop` preset).
18+
DEPS_ROOT_DIR: ~/_deps # Note that this needs to be used in a position where Bash will trigger tilde expansion!
1519

1620
jobs:
1721
unix:
@@ -21,9 +25,7 @@ jobs:
2125
cxx: [g++, clang++]
2226
buildsys: [make, cmake]
2327
exclude:
24-
# Don't use `g++` on macOS; it's just an alias to `clang++`.
25-
- os: macos-14
26-
cxx: g++
28+
- {os: macos-14, cxx: g++} # Don't use `g++` on macOS; it's just an alias to `clang++`.
2729
fail-fast: false
2830
runs-on: ${{ matrix.os }}
2931
steps:
@@ -68,7 +70,7 @@ jobs:
6870
tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT
6971
- name: Check test dependency repositories cache
7072
id: test-deps-cache
71-
uses: actions/cache@v4
73+
uses: actions/cache@v5
7274
with:
7375
path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }}
7476
key: ${{ matrix.os }}-${{ steps.test-deps-cache-params.outputs.hash }}
@@ -125,7 +127,7 @@ jobs:
125127
tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT
126128
- name: Check test dependency repositories cache
127129
id: test-deps-cache
128-
uses: actions/cache@v4
130+
uses: actions/cache@v5
129131
with:
130132
path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }}
131133
key: ${{ matrix.os }}-${{ steps.test-deps-cache-params.outputs.hash }}
@@ -159,18 +161,22 @@ jobs:
159161
- name: Checkout repo
160162
uses: actions/checkout@v4
161163
- name: Install deps
162-
run: .github/scripts/get_win_deps.ps1
164+
run: bash .github/scripts/install_deps.sh ${{ matrix.os }}
165+
- name: Cache library deps
166+
uses: actions/cache@v5
167+
with:
168+
path: ${{ env.DEPS_ROOT_DIR }}/*-tmp/
169+
key: dep-srcs-${{ hashFiles('cmake/deps.cmake') }}
170+
enableCrossOsArchive: true
163171
- name: Build Windows binaries
164172
shell: bash
165-
# We instruct CMake to download and build third-party projects outside of our source tree,
166-
# otherwise they can trigger `-Werror=dev` (from the `develop` preset).
167173
run: | # ASan seems to be broken on Windows, so we disable it.
168-
cmake -S . -B build --preset develop-msvc${{ matrix.bits }} -DFETCHCONTENT_BASE_DIR="$TEMP/cmake-deps" -DBISON_EXECUTABLE=bison/win_bison.exe -DSANITIZERS=OFF
174+
cmake -S . -B build --preset develop-msvc${{ matrix.bits }} -DFETCHCONTENT_BASE_DIR="$(echo "${{ env.DEPS_ROOT_DIR }}")" -DSANITIZERS=OFF
169175
cmake --build build
170-
cmake --install build --prefix install_dir --config Debug --verbose
171176
- name: Package binaries
172177
shell: bash
173178
run: |
179+
cmake --install build --prefix install_dir --config Debug --verbose
174180
mkdir bins
175181
cp -v install_dir/bin/{rgb*.exe,*.dll} bins
176182
- name: Upload Windows binaries
@@ -188,7 +194,7 @@ jobs:
188194
tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT
189195
- name: Check test dependency repositories cache
190196
id: test-deps-cache
191-
uses: actions/cache@v4
197+
uses: actions/cache@v5
192198
with:
193199
path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }}
194200
key: ${{ matrix.os }}-${{ matrix.bits }}-${{ steps.test-deps-cache-params.outputs.hash }}
@@ -297,7 +303,7 @@ jobs:
297303
tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT
298304
- name: Check test dependency repositories cache
299305
id: test-deps-cache
300-
uses: actions/cache@v4
306+
uses: actions/cache@v5
301307
with:
302308
path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }}
303309
key: mingw-${{ matrix.bits }}-${{ steps.test-deps-cache-params.outputs.hash }}

CMakeLists.txt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,13 @@ endif()
137137
## Dependencies.
138138

139139
include(FetchContent)
140-
FetchContent_Declare(PNG
141-
URL https://download.sourceforge.net/libpng/libpng-1.6.55.tar.xz
142-
URL_HASH SHA256=d925722864837ad5ae2a82070d4b2e0603dc72af44bd457c3962298258b8e82d
143-
FIND_PACKAGE_ARGS 1.5.4)
144-
FetchContent_Declare(ZLIB
145-
URL https://www.zlib.net/zlib-1.3.2.tar.xz
146-
URL_HASH SHA256=d7a0654783a4da529d1bb793b7ad9c3318020af77667bcae35f95d0e42a792f3
147-
FIND_PACKAGE_ARGS)
148-
set(ZLIB_BUILD_SHARED ON CACHE INTERNAL "")
149-
set(ZLIB_BUILD_STATIC OFF CACHE INTERNAL "")
140+
include(cmake/deps.cmake)
141+
150142
FetchContent_MakeAvailable(ZLIB)
151143
if(NOT DEFINED ZLIB_INCLUDE_DIRS)
152144
set(ZLIB_INCLUDE_DIRS "${zlib_BINARY_DIR};${zlib_SOURCE_DIR}") # libpng's `genout` script relies on this variable to be set.
153145
endif()
154-
set(PNG_TESTS OFF CACHE INTERNAL "") # We do not care for these two (and they can even cause compile errors!)
155-
set(PNG_TOOLS OFF CACHE INTERNAL "")
156-
set(PNG_SHARED ON CACHE INTERNAL "") # Upstream seems to favour the dynamic lib over the static one?
157-
set(PNG_STATIC OFF CACHE INTERNAL "")
146+
158147
FetchContent_MakeAvailable(PNG)
159148
if(NOT TARGET PNG::PNG)
160149
if(PNG_SHARED)

cmake/deps.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file declares the dependencies we use, using `FetchContent`.
2+
# https://cmake.org/cmake.help/latest/guide/using-dependencies/index.html#downloading-and-building-from-source-with-fetchcontent
3+
# This is offloaded to a separate file so that it can be hashed, the hash serving as a cache key.
4+
5+
FetchContent_Declare(PNG
6+
URL https://download.sourceforge.net/libpng/libpng-1.6.55.tar.xz
7+
URL_HASH SHA256=d925722864837ad5ae2a82070d4b2e0603dc72af44bd457c3962298258b8e82d
8+
FIND_PACKAGE_ARGS 1.5.4)
9+
10+
set(PNG_TESTS OFF CACHE INTERNAL "") # We do not care for these two (and they can even cause compile errors!)
11+
set(PNG_TOOLS OFF CACHE INTERNAL "")
12+
set(PNG_SHARED ON CACHE INTERNAL "") # Upstream seems to favour the dynamic lib over the static one?
13+
set(PNG_STATIC OFF CACHE INTERNAL "")
14+
15+
FetchContent_Declare(ZLIB
16+
URL https://www.zlib.net/zlib-1.3.2.tar.xz
17+
URL_HASH SHA256=d7a0654783a4da529d1bb793b7ad9c3318020af77667bcae35f95d0e42a792f3
18+
FIND_PACKAGE_ARGS)
19+
20+
set(ZLIB_BUILD_SHARED ON CACHE INTERNAL "")
21+
set(ZLIB_BUILD_STATIC OFF CACHE INTERNAL "")

0 commit comments

Comments
 (0)