Skip to content

Commit 1d9336c

Browse files
Enable more persistent caches in CI
1 parent 954ae93 commit 1d9336c

File tree

4 files changed

+78
-33
lines changed

4 files changed

+78
-33
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,29 @@ jobs:
8787
- { env: almalinux:8 --gts_version=12, vcpkg_arg: use_vcpkg=true }
8888
steps:
8989
- *checkout
90+
- name: Prepare Caches
91+
uses: actions/cache@v4
92+
with:
93+
path: _build/.cache
94+
key: linux-${{matrix.env}}
9095
- name: Environment Prep
9196
run: |
92-
bash tools/earthly.sh +init \
93-
--env=${{matrix.env}} \
94-
--${{matrix.vcpkg_arg}}
97+
# Set Earthly args in the .arg file, which will persist across subsequent
98+
# steps, ensuring each step uses the same argument set
99+
echo "env=${{matrix.env}}" > .arg
100+
echo "${{matrix.vcpkg_arg}}" >> .arg
101+
# Persist caches into a host directory to be persisted between runs
102+
echo "host_cache=_build/.cache" >> .arg
103+
# Enable unity builds in CI for faster compilation
104+
echo "unity_build=true" >> .arg
105+
106+
bash tools/earthly.sh +init
95107
- name: Build
96-
run: |
97-
bash tools/earthly.sh +build \
98-
--env=${{matrix.env}} \
99-
--${{matrix.vcpkg_arg}} \
100-
--unity_build=true
108+
run: bash tools/earthly.sh +build
101109
# This step will use the same cached +build results as long as all Earthly
102-
# build arguments are equivalent. Make sure of that!
110+
# build arguments are equivalent.
103111
- name: Test
104-
run: |
105-
bash tools/earthly.sh -a +test/results.xml results.xml \
106-
--env=${{matrix.env}} \
107-
--${{matrix.vcpkg_arg}} \
108-
--unity_build=true
112+
run: bash tools/earthly.sh -a +test/results.xml results.xml
109113

110114
build-macos:
111115
name: Build & Test (macOS)
@@ -121,7 +125,7 @@ jobs:
121125
- name: Prepare Caches
122126
uses: actions/cache@v4
123127
with:
124-
path: _build/_cache
128+
path: _build/.cache
125129
key: macos-15
126130
- name: Prepare uv Environment
127131
run: uv run --group=build true
@@ -151,15 +155,15 @@ jobs:
151155
export CMAKE_OSX_ARCHITECTURES="${{matrix.target_arch}}"
152156
153157
# Create a directory for vcpkg binary caches
154-
export VCPKG_DEFAULT_BINARY_CACHE=$PWD/_build/_cache
158+
export VCPKG_DEFAULT_BINARY_CACHE=$PWD/_build/.cache/vcpkg
155159
mkdir -p "$VCPKG_DEFAULT_BINARY_CACHE"
156160
157161
# Do the build
158162
uv run --group=build \
159163
make build \
160164
CONFIGS="Debug;RelWithDebInfo" \
161165
USE_PMM=TRUE \
162-
WARNINGS_AS_ERRORS=TRUE \
166+
WARNINGS_AS_ERRORS=FALSE \
163167
BUILD_TESTING=TRUE \
164168
UNITY_BUILD=TRUE
165169
@@ -175,7 +179,7 @@ jobs:
175179
- name: Prepare Caches
176180
uses: actions/cache@v4
177181
with:
178-
path: _build/_cache
182+
path: _build/.cache
179183
key: msvc-${{matrix.arch}}
180184
# This step only warms up the uv cache for the `build` group used by the
181185
# main build process
@@ -188,4 +192,9 @@ jobs:
188192
shell: pwsh
189193
# 17.* selects VS 2022
190194
run: |
191-
tools/ci.ps1 -VSVersion 17.* -TargetArch ${{matrix.arch}} -UseVcpkg -BuildTesting -UnityBuild
195+
tools/ci.ps1 -VSVersion 17.* `
196+
-TargetArch ${{matrix.arch}} `
197+
-VcpkgBinaryCachePath "_build/.cache/vcpkg"
198+
-UseVcpkg `
199+
-BuildTesting `
200+
-UnityBuild

Earthfile

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ VERSION 0.8
33
# Tweak the default container registry used for pulling system images.
44
ARG --global default_container_registry = "docker.io"
55

6+
# Directory on the host where we will copy in/out cache files. If unset/falsey, then
7+
# caches will not be persisted on the host, only within the containers
8+
ARG --global host_cache
9+
610
init:
711
ARG --required env
812
# Toggle the building of test programs
@@ -138,21 +142,33 @@ INSTALL_DEPS:
138142

139143
RUN __install $pkgs
140144

141-
DO +ADD_CCACHE
145+
DO +CCACHE_INIT
142146

143-
ADD_CCACHE:
147+
CCACHE_INIT:
144148
FUNCTION
145149
IF ! ccache --version && __can_install ccache
146150
RUN __install ccache
147151
END
152+
ARG host_cache = false
148153
IF ccache --version
149154
ENV CCACHE_DIR = /run/ccache
150-
CACHE /run/ccache
151155
ENV CMAKE_C_COMPILER_LAUNCHER=ccache
152156
ENV CMAKE_CXX_COMPILER_LAUNCHER=ccache
157+
158+
IF __bool $host_cache
159+
COPY --if-exists $host_cache/ccache $CCACHE_DIR
160+
ELSE
161+
CACHE $CCACHE_DIR
162+
END
163+
END
164+
165+
CCACHE_FINISH:
166+
FUNCTION
167+
IF __bool $host_cache
168+
SAVE ARTIFACT $CCACHE_DIR AS LOCAL $host_cache/ccache
153169
END
154170

155-
VCPKG_SETUP:
171+
VCPKG_INIT:
156172
FUNCTION
157173
# Toggle whether this function actually does anything
158174
ARG --required use_vcpkg
@@ -163,8 +179,20 @@ VCPKG_SETUP:
163179
ENV VCPKG_DEFAULT_BINARY_CACHE = "/run/cache/vcpkg/binary"
164180
# Prepare the area
165181
RUN mkdir -p $VCPKG_DEFAULT_BINARY_CACHE
166-
# Persist that directory between target executions
167-
CACHE $VCPKG_DEFAULT_BINARY_CACHE
182+
IF __bool $host_cache
183+
# We are going to copy in/out caches from the host
184+
COPY --if-exists $host_cache/vcpkg $VCPKG_DEFAULT_BINARY_CACHE
185+
ELSE
186+
# Don't use a host directory, use Earthly's caching volume instead
187+
CACHE $VCPKG_DEFAULT_BINARY_CACHE
188+
END
189+
END
190+
191+
VCPKG_FINISH:
192+
FUNCTION
193+
ARG --required use_vcpkg
194+
IF __bool $use_vcpkg && __bool $host_cache
195+
SAVE ARTIFACT $VCPKG_DEFAULT_BINARY_CACHE AS LOCAL $host_cache/vcpkg
168196
END
169197

170198
COPY_SRC:
@@ -177,9 +205,9 @@ BUILD:
177205
FUNCTION
178206
# Enable vcpkg
179207
ARG --required use_vcpkg
180-
DO --pass-args +VCPKG_SETUP
208+
DO --pass-args +VCPKG_INIT
181209
# Enable Ccache caching between container runs
182-
DO +ADD_CCACHE
210+
DO --pass-args +CCACHE_INIT
183211

184212
ARG install_prefix
185213
ARG cpack_out
@@ -209,3 +237,6 @@ BUILD:
209237
CPACK_OUT="$cpack_out" \
210238
PACKAGE_CONFIGS="$configs"
211239
END
240+
241+
DO --pass-args +VCPKG_FINISH
242+
DO --pass-args +CCACHE_FINISH

tools/__tool

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ __alias() {
7979
}
8080

8181
__bool() {
82-
bool=$(printf "%s" "$1" | tr '[:lower:]' '[:upper:]')
82+
bool=$(printf "%s" "${1-}" | tr '[:lower:]' '[:upper:]')
8383
case "$bool" in
8484
0|OFF|NO|FALSE|N|IGNORE|NOTFOUND|""|*-NOTFOUND)
8585
return 1;;

tools/ci.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ param(
1515
[switch]$BuildTesting,
1616
[switch]$WarningsAsErrors,
1717
[switch]$Test,
18-
[switch]$UnityBuild
18+
[switch]$UnityBuild,
19+
# Directory where vcpkg will stores its binary caches
20+
[string]$VcpkgBinaryCachePath
1921
)
2022

2123
$ErrorActionPreference = "Stop"
@@ -28,10 +30,13 @@ $this_dir = $PSScriptRoot
2830

2931
$root = Split-Path -Parent $this_dir
3032

31-
# Set the directory where vcpkg will store its binary cache artifacts. This can
32-
# be persisted between CI runs
33-
$env:VCPKG_DEFAULT_BINARY_CACHE = "$root/_build/_cache/vcpkg"
34-
[void](New-Item -ItemType Directory $env:VCPKG_DEFAULT_BINARY_CACHE -Force)
33+
if (-not [string]::IsNullOrEmpty($VcpkgBinaryCachePath)) {
34+
# Set the directory where vcpkg will store its binary cache artifacts. This can
35+
# be persisted between CI runs
36+
$VcpkgBinaryCachePath = [IO.Path]::GetFullPath($VcpkgBinaryCachePath)
37+
$env:VCPKG_DEFAULT_BINARY_CACHE = "$VcpkgBinaryCachePath"
38+
[void](New-Item -ItemType Directory $env:VCPKG_DEFAULT_BINARY_CACHE -Force)
39+
}
3540

3641
Write-Verbose "Loading uv environment..."
3742
$uv_env = Get-UvEnvironment -ArgumentList "--group=build"

0 commit comments

Comments
 (0)