Cache library deps on Windows

Besides the immediate performance improvement, reducing
the frequency of downloads should make spurious
failures (network, rate-limiting...) less bothersome.
This commit is contained in:
ISSOtm
2026-03-19 02:51:51 +01:00
committed by Eldred Habert
parent 91fdfcd179
commit 6b0658fb59
7 changed files with 70 additions and 53 deletions

View File

@@ -1,18 +0,0 @@
function getlibrary ([string] $URI, [string] $filename, [string] $hash, [string] $destdir) {
$wc = New-Object Net.WebClient
[string] $downloadhash = $null
try {
$wc.DownloadFile($URI, $filename)
$downloadhash = $(Get-FileHash $filename -Algorithm SHA256).Hash
} catch {
Write-Host "${filename}: failed to download"
exit 1
}
if ($hash -ne $downloadhash) {
Write-Host "${filename}: SHA256 mismatch ($downloadhash)"
exit 1
}
Expand-Archive -DestinationPath $destdir $filename
}
getlibrary 'https://github.com/lexxmark/winflexbison/releases/download/v2.5.25/win_flex_bison-2.5.25.zip' 'winflexbison.zip' '8d324b62be33604b2c45ad1dd34ab93d722534448f55a16ca7292de32b6ac135' bison

View File

@@ -20,11 +20,17 @@ case "${1%-*}" in
freebsd) freebsd)
pkg install -y bash bison cmake git png pkg install -y bash bison cmake git png
;; ;;
windows)
choco install -y winflexbison3
# The below expects the base name, not the Windows-specific name.
bison() { win_bison "$@"; } # An alias doesn't work, so we use a function instead.
;;
*) *)
echo "WARNING: Cannot install deps for OS '$1'" echo "WARNING: Cannot install deps for OS '$1'"
;; ;;
esac esac
echo "PATH=($PATH)" | sed 's/:/\n /g'
bison --version bison --version
make --version make --version
cmake --version cmake --version

View File

@@ -14,6 +14,10 @@ env:
CMAKE_BUILD_TYPE: Release # `cmake -S` now implies `-DCMAKE_BUILD_TYPE=Release`. CMAKE_BUILD_TYPE: Release # `cmake -S` now implies `-DCMAKE_BUILD_TYPE=Release`.
CMAKE_CONFIG_TYPE: Release # `cmake --build` now implies `--config Release`. CMAKE_CONFIG_TYPE: Release # `cmake --build` now implies `--config Release`.
# We instruct CMake to download and build third-party projects in the same place as in `testing.yml`
# for the sources cache to remain valid.
DEPS_ROOT_DIR: ~/_deps # Note that this needs to be used in a position where Bash will trigger tilde expansion!
jobs: jobs:
windows: windows:
runs-on: windows-2022 runs-on: windows-2022
@@ -35,17 +39,21 @@ jobs:
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Install deps - name: Install deps
run: .github/scripts/get_win_deps.ps1 run: .github/scripts/install_deps.sh windows
- name: Cache library deps
uses: actions/cache@v5
with:
path: ${{ env.DEPS_ROOT_DIR }}/*-tmp/
key: dep-srcs-${{ hashFiles('cmake/deps.cmake') }}
enableCrossOsArchive: true
- name: Build Windows binaries - name: Build Windows binaries
shell: bash shell: bash
# We instruct CMake to download and build third-party projects outside of our source tree,
# otherwise they can trigger `-Werror=dev` (from the `develop` preset).
run: | run: |
cmake -S . -B build --preset msvc${{ matrix.bits }} -DFETCHCONTENT_BASE_DIR="$TEMP/cmake-deps" -DBISON_EXECUTABLE=bison/win_bison.exe cmake -S . -B build --preset msvc${{ matrix.bits }} -DFETCHCONTENT_BASE_DIR="${{ env.DEPS_ROOT_DIR }}"
cmake --build build cmake --build build
cmake --install build --config Release --prefix install_dir --verbose
- name: Package binaries - name: Package binaries
run: | run: |
cmake --install build --config Release --prefix install_dir --verbose
Compress-Archive -LiteralPath @("install_dir/bin/rgbasm.exe", "install_dir/bin/rgblink.exe", "install_dir/bin/rgbfix.exe", "install_dir/bin/rgbgfx.exe", "install_dir/bin/z.dll", "install_dir/bin/libpng16.dll") "rgbds-win${{ matrix.bits }}.zip" Compress-Archive -LiteralPath @("install_dir/bin/rgbasm.exe", "install_dir/bin/rgblink.exe", "install_dir/bin/rgbfix.exe", "install_dir/bin/rgbgfx.exe", "install_dir/bin/z.dll", "install_dir/bin/libpng16.dll") "rgbds-win${{ matrix.bits }}.zip"
- name: Upload Windows binaries - name: Upload Windows binaries
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4

View File

@@ -12,6 +12,10 @@ env:
CMAKE_INSTALL_PARALLEL_LEVEL: 4 # `cmake --install` now implies `--parallel 4`. CMAKE_INSTALL_PARALLEL_LEVEL: 4 # `cmake --install` now implies `--parallel 4`.
CMAKE_CONFIG_TYPE: Debug # `cmake --build` now implies `--config Debug`. CMAKE_CONFIG_TYPE: Debug # `cmake --build` now implies `--config Debug`.
# We instruct CMake to download and build third-party projects outside of our source tree,
# otherwise they can trigger `-Werror=dev` (from the `develop` preset).
DEPS_ROOT_DIR: ~/_deps # Note that this needs to be used in a position where Bash will trigger tilde expansion!
jobs: jobs:
unix: unix:
strategy: strategy:
@@ -20,9 +24,7 @@ jobs:
cxx: [g++, clang++] cxx: [g++, clang++]
buildsys: [make, cmake] buildsys: [make, cmake]
exclude: exclude:
# Don't use `g++` on macOS; it's just an alias to `clang++`. - { os: macos-14, cxx: g++ } # Don't use `g++` on macOS; it's just an alias to `clang++`.
- os: macos-14
cxx: g++
fail-fast: false fail-fast: false
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
@@ -67,7 +69,7 @@ jobs:
tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT
- name: Check test dependency repositories cache - name: Check test dependency repositories cache
id: test-deps-cache id: test-deps-cache
uses: actions/cache@v4 uses: actions/cache@v5
with: with:
path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }} path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }}
key: ${{ matrix.os }}-${{ steps.test-deps-cache-params.outputs.hash }} key: ${{ matrix.os }}-${{ steps.test-deps-cache-params.outputs.hash }}
@@ -124,7 +126,7 @@ jobs:
tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT
- name: Check test dependency repositories cache - name: Check test dependency repositories cache
id: test-deps-cache id: test-deps-cache
uses: actions/cache@v4 uses: actions/cache@v5
with: with:
path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }} path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }}
key: ${{ matrix.os }}-${{ steps.test-deps-cache-params.outputs.hash }} key: ${{ matrix.os }}-${{ steps.test-deps-cache-params.outputs.hash }}
@@ -158,18 +160,23 @@ jobs:
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Install deps - name: Install deps
run: .github/scripts/get_win_deps.ps1 run: |
bash .github/scripts/install_deps.sh ${{ matrix.os }}
- name: Cache library deps
uses: actions/cache@v5
with:
path: ${{ env.DEPS_ROOT_DIR }}/*-tmp/
key: dep-srcs-${{ hashFiles('cmake/deps.cmake') }}
enableCrossOsArchive: true
- name: Build Windows binaries - name: Build Windows binaries
shell: bash shell: bash
# We instruct CMake to download and build third-party projects outside of our source tree,
# otherwise they can trigger `-Werror=dev` (from the `develop` preset).
run: | # ASan seems to be broken on Windows, so we disable it. run: | # ASan seems to be broken on Windows, so we disable it.
cmake -S . -B build --preset develop-msvc${{ matrix.bits }} -DFETCHCONTENT_BASE_DIR="$TEMP/cmake-deps" -DBISON_EXECUTABLE=bison/win_bison.exe -DSANITIZERS=OFF cmake -S . -B build --preset develop-msvc${{ matrix.bits }} -DFETCHCONTENT_BASE_DIR="${{ env.DEPS_ROOT_DIR }}" -DSANITIZERS=OFF
cmake --build build cmake --build build
cmake --install build --config Debug --prefix install_dir --verbose
- name: Package binaries - name: Package binaries
shell: bash shell: bash
run: | run: |
cmake --install build --config Debug --prefix install_dir --verbose
mkdir bins mkdir bins
cp -v install_dir/bin/{rgb*.exe,*.dll} bins cp -v install_dir/bin/{rgb*.exe,*.dll} bins
- name: Upload Windows binaries - name: Upload Windows binaries
@@ -187,7 +194,7 @@ jobs:
tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT
- name: Check test dependency repositories cache - name: Check test dependency repositories cache
id: test-deps-cache id: test-deps-cache
uses: actions/cache@v4 uses: actions/cache@v5
with: with:
path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }} path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }}
key: ${{ matrix.os }}-${{ matrix.bits }}-${{ steps.test-deps-cache-params.outputs.hash }} key: ${{ matrix.os }}-${{ matrix.bits }}-${{ steps.test-deps-cache-params.outputs.hash }}
@@ -296,7 +303,7 @@ jobs:
tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT tee -a <<<"hash=${hash%-}" $GITHUB_OUTPUT
- name: Check test dependency repositories cache - name: Check test dependency repositories cache
id: test-deps-cache id: test-deps-cache
uses: actions/cache@v4 uses: actions/cache@v5
with: with:
path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }} path: ${{ fromJSON(steps.test-deps-cache-params.outputs.paths) }}
key: mingw-${{ matrix.bits }}-${{ steps.test-deps-cache-params.outputs.hash }} key: mingw-${{ matrix.bits }}-${{ steps.test-deps-cache-params.outputs.hash }}

View File

@@ -28,6 +28,8 @@ rgbds/
│ │ └── ... │ │ └── ...
│ └── workflows/ │ └── workflows/
│ └── ... │ └── ...
├── cmake/
│ └── ...
├── contrib/ ├── contrib/
│ ├── bash_compl/ │ ├── bash_compl/
│ ├── zsh_compl/ │ ├── zsh_compl/
@@ -70,6 +72,8 @@ rgbds/
Scripts used by GitHub Actions workflow files. Scripts used by GitHub Actions workflow files.
* **`workflows/`:** * **`workflows/`:**
GitHub Actions CI workflow description files. Used for automated testing, deployment, etc. GitHub Actions CI workflow description files. Used for automated testing, deployment, etc.
- **`cmake/`**:
Files relevant to our CMake build system that are not required to be somewhere else (e.g. `CMakePresets.json` *has* to be at the root).
- **`contrib/`:** - **`contrib/`:**
Scripts and other resources which may be useful to RGBDS users and developers. Scripts and other resources which may be useful to RGBDS users and developers.
* **`bash_compl/`:** * **`bash_compl/`:**

View File

@@ -140,26 +140,13 @@ endif()
## Dependencies. ## Dependencies.
include(FetchContent) include(FetchContent)
FetchContent_Declare(PNG include(cmake/deps.cmake)
URL https://download.sourceforge.net/libpng/libpng-1.6.55.tar.xz
URL_HASH SHA256=d925722864837ad5ae2a82070d4b2e0603dc72af44bd457c3962298258b8e82d
FIND_PACKAGE_ARGS 1.5.4)
FetchContent_Declare(ZLIB
URL https://www.zlib.net/zlib-1.3.2.tar.xz
URL_HASH SHA256=d7a0654783a4da529d1bb793b7ad9c3318020af77667bcae35f95d0e42a792f3
# libpng documents requiring "zlib 1.0.4 or later (1.2.13 or later recommended for performance and security reasons)".
# We thus enforce 1.0.4, but note that the libpng source code mentions that "it may work with versions as old as zlib 0.95".
FIND_PACKAGE_ARGS 1.0.4)
set(ZLIB_BUILD_SHARED ON CACHE INTERNAL "")
set(ZLIB_BUILD_STATIC OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(ZLIB) FetchContent_MakeAvailable(ZLIB)
if(NOT DEFINED ZLIB_INCLUDE_DIRS) if(NOT DEFINED ZLIB_INCLUDE_DIRS)
set(ZLIB_INCLUDE_DIRS "${zlib_BINARY_DIR};${zlib_SOURCE_DIR}") # libpng's `genout` script relies on this variable to be set. set(ZLIB_INCLUDE_DIRS "${zlib_BINARY_DIR};${zlib_SOURCE_DIR}") # libpng's `genout` script relies on this variable to be set.
endif() endif()
set(PNG_TESTS OFF CACHE INTERNAL "") # We do not care for these two (and they can even cause compile errors!)
set(PNG_TOOLS OFF CACHE INTERNAL "")
set(PNG_SHARED ON CACHE INTERNAL "") # Upstream seems to favour the dynamic lib over the static one?
set(PNG_STATIC OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(PNG) FetchContent_MakeAvailable(PNG)
if(NOT TARGET PNG::PNG) if(NOT TARGET PNG::PNG)
if(PNG_SHARED) if(PNG_SHARED)

23
cmake/deps.cmake Normal file
View File

@@ -0,0 +1,23 @@
# This file declares the dependencies we use, using `FetchContent`.
# https://cmake.org/cmake.help/latest/guide/using-dependencies/index.html#downloading-and-building-from-source-with-fetchcontent
# These are kept in a separate file so that it can be hashed as a key for our CI's `actions/cache`.
FetchContent_Declare(PNG
URL https://download.sourceforge.net/libpng/libpng-1.6.55.tar.xz
URL_HASH SHA256=d925722864837ad5ae2a82070d4b2e0603dc72af44bd457c3962298258b8e82d
FIND_PACKAGE_ARGS 1.5.4)
set(PNG_TESTS OFF CACHE INTERNAL "") # We do not care for these two (and they can even cause compile errors!)
set(PNG_TOOLS OFF CACHE INTERNAL "")
set(PNG_SHARED ON CACHE INTERNAL "") # Upstream seems to favour the dynamic lib over the static one?
set(PNG_STATIC OFF CACHE INTERNAL "")
FetchContent_Declare(ZLIB
URL https://www.zlib.net/zlib-1.3.2.tar.xz
URL_HASH SHA256=d7a0654783a4da529d1bb793b7ad9c3318020af77667bcae35f95d0e42a792f3
# libpng documents requiring "zlib 1.0.4 or later (1.2.13 or later recommended for performance and security reasons)".
# We thus enforce 1.0.4, but note that the libpng source code mentions that "it may work with versions as old as zlib 0.95".
FIND_PACKAGE_ARGS 1.0.4)
set(ZLIB_BUILD_SHARED ON CACHE INTERNAL "")
set(ZLIB_BUILD_STATIC OFF CACHE INTERNAL "")