Skip to content

Commit 16ce719

Browse files
authored
Use ccache for emscripten library build (#25392)
Use ccache to cache the output of clang when building the emscripten libraries. When building on the main branch, save the ccache directory to the CircleCI cache affter building, using the clang version as the key. When building from other branches (including PRs, where the branch will appear as 'pull/12345') restore the cache before building.
1 parent b761b9e commit 16ce719

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

.circleci/config.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ commands:
142142
cd ~/emsdk
143143
./emsdk install tot
144144
./emsdk activate tot
145+
# Write the version of clang into a file for use in the ccache key
146+
./upstream/bin/clang --version > clang_version.txt
147+
echo "clang version:"
148+
cat ~/emsdk/clang_version.txt
145149
# Remove the emsdk version of emscripten to save space in the
146150
# persistent workspace and to avoid any confusion with the version
147151
# we are trying to test.
@@ -171,7 +175,7 @@ commands:
171175
command: |
172176
./emcc --clear-cache
173177
- pip-install
174-
- run: apt-get install -q -y ninja-build
178+
- run: apt-get install -q -y ninja-build ccache
175179
- run:
176180
name: embuilder build ALL
177181
command: |
@@ -196,6 +200,12 @@ commands:
196200
command: |
197201
./embuilder build MINIMAL --pic --lto
198202
./test/runner test_hello_world
203+
- run:
204+
name: "Ccache stats"
205+
command: |
206+
ccache --print-stats
207+
ccache --zero-stats
208+
199209
persist:
200210
description: "Persist the emsdk, libraries, and engines"
201211
steps:
@@ -209,6 +219,19 @@ commands:
209219
- vms/
210220
- wasi-sdk/
211221
- .jsvu/
222+
- when:
223+
# Only the main branch will store its cache results, and only the non-main branches
224+
# will use cached results. This prevents untrusted PRs from polluting caches used
225+
# by other branches.
226+
condition:
227+
equal: [ "main", << pipeline.git.branch >> ]
228+
steps:
229+
- save_cache:
230+
name: "Save Ccache cache"
231+
paths:
232+
- ~/.ccache
233+
key: clang-{{ checksum "~/emsdk/clang_version.txt" }}
234+
212235
prepare-for-tests:
213236
description: "Setup emscripten tests"
214237
steps:
@@ -543,6 +566,7 @@ jobs:
543566
environment:
544567
EMCC_CORES: 16
545568
EMCC_USE_NINJA: 1
569+
EM_COMPILER_WRAPPER: "ccache"
546570
steps:
547571
- checkout
548572
- run:
@@ -570,6 +594,14 @@ jobs:
570594
tar xvf wasi-sysroot-11.0.tar.gz -C ~/wasi-sdk/
571595
- install-v8
572596
- install-emsdk
597+
- when:
598+
condition:
599+
not:
600+
equal: [ "main", << pipeline.git.branch >> ]
601+
steps:
602+
- restore_cache:
603+
name: "Restore Ccache cache"
604+
key: clang-{{ checksum "~/emsdk/clang_version.txt" }}
573605
- build-libs
574606
- run:
575607
name: Clean build directory

0 commit comments

Comments
 (0)