Skip to content

Commit 5e78260

Browse files
authored
Consolidate release artefacts (#329)
Brings in the previously wasm.yml into python.yml and the new file is renamed as build.yml. python.yml already had a version and pre-release jobs. These jobs downloaded artefacts from prior ran jobs (python wheel builds). The newly attached emscripten build now uploads artefacts of a WebAssembly binary and javascript file which are fed into the release and pre-release jobs in addition to the existing python builds.
1 parent 91b2e06 commit 5e78260

File tree

2 files changed

+161
-129
lines changed

2 files changed

+161
-129
lines changed
Lines changed: 161 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Python Bindings"
1+
name: "Build"
22
'on':
33
push:
44
branches:
@@ -11,6 +11,7 @@ name: "Python Bindings"
1111
- '**'
1212
env:
1313
qt_version: "6.2.1" # only used by build-macos
14+
emsdk_version: 2.0.9 # For use in emscripten build
1415
ccache_basedir: ${{ github.workspace }}
1516
ccache_dir: "${{ github.workspace }}/.ccache"
1617
ccache_compilercheck: content
@@ -230,16 +231,161 @@ jobs:
230231
with:
231232
path: ${{github.workspace}}/dist/bergamot-*.whl
232233

234+
build-wasm:
235+
name: "emscripten"
236+
runs-on: ubuntu-latest
237+
steps:
238+
239+
- name: Checkout
240+
uses: actions/checkout@v2
241+
with:
242+
submodules: recursive
243+
244+
- name: Set ccache environment for emcc
245+
run: |
246+
# We are hardcoding this to mtime instead of env pickup. Rest use content.
247+
echo "CCACHE_COMPILER_CHECK=mtime" >> $GITHUB_ENV
248+
249+
echo "CCACHE_BASEDIR=${{ env.ccache_basedir }}" >> $GITHUB_ENV
250+
echo "CCACHE_COMPRESS=${{ env.ccache_compress }}" >> $GITHUB_ENV
251+
echo "CCACHE_COMPRESSLEVEL=${{ env.ccache_compresslevel }}" >> $GITHUB_ENV
252+
echo "CCACHE_DIR=${{ env.ccache_dir }}" >> $GITHUB_ENV
253+
echo "CCACHE_MAXSIZE=${{ env.ccache_maxsize }}" >> $GITHUB_ENV
254+
# https://emscripten.org/docs/compiling/Building-Projects.html#using-a-compiler-wrapper
255+
echo "EM_COMPILER_WRAPPER=ccache" >> $GITHUB_ENV
256+
257+
# This need to be run before setup, so ccache build caching doesn't complain.
258+
- name: Obtain emsdk sources
259+
run: |
260+
git clone --depth 1 https://github.com/emscripten-core/emsdk.git
261+
262+
- name: Cache-op for build-cache through ccache
263+
uses: actions/cache@v2
264+
with:
265+
path: |
266+
${{ env.ccache_dir }}
267+
${{ github.workspace }}/emsdk/ccache/git-emscripten_64bit/
268+
key: ccache-${{ github.job }}-${{ env.emsdk_version }}-${{ steps.ccache_vars.outputs.hash }}-${{ github.ref }}-${{ steps.ccache_vars.outputs.timestamp }}
269+
restore-keys: |-
270+
ccache-${{ github.job }}-${{ env.emsdk_version }}-${{ steps.ccache_vars.outputs.hash }}-${{ github.ref }}
271+
ccache-${{ github.job }}-${{ env.emsdk_version }}-${{ steps.ccache_vars.outputs.hash }}
272+
ccache-${{ github.job }}-${{ env.emsdk_version }}
273+
274+
- name: Setup Emscripten toolchain
275+
run: |
276+
(cd emsdk && ./emsdk install ${{ env.emsdk_version }} ccache-git-emscripten-64bit)
277+
(cd emsdk && ./emsdk activate ${{ env.emsdk_version }} ccache-git-emscripten-64bit)
278+
# mtime of this file is checked by ccache, we set it to avoid cache misses.
279+
touch -m -d '1 Jan 2021 12:00' emsdk/.emscripten
280+
281+
# These needs to be done in the activated shell.
282+
eval $(./emsdk/emsdk construct_env \
283+
| sed 's/export PATH=\(.*\);/echo \1 >> $GITHUB_PATH;/' \
284+
| sed 's/export \(.*\);/echo \1 >> $GITHUB_ENV;/' );
285+
286+
# This looks more permanent than version pinned, so keeping temporarily to avoid failures.
287+
echo "${{ github.workspace }}/emsdk/ccache/git-emscripten_64bit/bin" >> $GITHUB_PATH
288+
289+
- name: Generate ccache_vars for ccache based on machine
290+
shell: bash
291+
id: ccache_vars
292+
run: |-
293+
echo "::set-output name=hash::$(echo ${{ env.ccache_compilercheck }})"
294+
echo "::set-output name=timestamp::$(date '+%Y-%m-%dT%H.%M.%S')"
295+
296+
- name: Verify Emscripten setup
297+
run: |
298+
emcc --version
299+
emcmake cmake --version
300+
emmake make --version
301+
302+
- name: ccache prolog
303+
run: |-
304+
ccache -s # Print current cache stats
305+
ccache -z # Zero cache entry
306+
307+
# WORMHOLE=off
308+
- name: "Configure builds for WORMHOLE=off"
309+
run: |
310+
mkdir -p build-wasm-without-wormhole
311+
cd build-wasm-without-wormhole
312+
emcmake cmake -DCOMPILE_WASM=on -DWORMHOLE=off ..
313+
314+
315+
- name: "Compile with WORMHOLE=off"
316+
working-directory: build-wasm-without-wormhole
317+
run: |
318+
emmake make -j2
319+
320+
- name: ccache epilog
321+
run: |
322+
ccache -s # Print current cache stats
323+
324+
- name: Import GEMM library from a separate wasm module
325+
working-directory: build-wasm-without-wormhole
326+
run: bash ../wasm/patch-artifacts-import-gemm-module.sh
327+
328+
329+
# WORMHOLE=on
330+
- name: "Configure builds for WORMHOLE=on"
331+
run: |
332+
mkdir -p build-wasm-with-wormhole
333+
cd build-wasm-with-wormhole
334+
emcmake cmake -DCOMPILE_WASM=on -DWORMHOLE=on ..
335+
336+
337+
- name: "Compile with WORMHOLE=on"
338+
working-directory: build-wasm-with-wormhole
339+
run: |
340+
emmake make -j2
341+
342+
- name: ccache epilog
343+
run: |
344+
ccache -s # Print current cache stats
345+
346+
- name: Instantiate simd wormhole
347+
working-directory: build-wasm-with-wormhole
348+
run: bash ../wasm/patch-artifacts-enable-wormhole.sh
349+
350+
- name: Import GEMM library from a separate wasm module
351+
working-directory: build-wasm-with-wormhole
352+
run: bash ../wasm/patch-artifacts-import-gemm-module.sh
353+
354+
# Rename the wormhole on builds
355+
- name: Rename artefacts with wormhole
356+
working-directory: build-wasm-with-wormhole
357+
run: |
358+
mv bergamot-translator-worker{,-with-wormhole}.js
359+
mv bergamot-translator-worker{,-with-wormhole}.js.bak
360+
mv bergamot-translator-worker{,-with-wormhole}.wasm
361+
362+
363+
# Upload both together.
364+
- name: Upload wasm artifact
365+
uses: actions/upload-artifact@v2
366+
with:
367+
name: wasm-artefacts
368+
if-no-files-found: error
369+
path: |
370+
# Without wormhole
371+
${{github.workspace}}/build-wasm-without-wormhole/bergamot-translator-worker.js
372+
${{github.workspace}}/build-wasm-without-wormhole/bergamot-translator-worker.wasm
373+
${{github.workspace}}/build-wasm-without-wormhole/bergamot-translator-worker.js.bak
374+
375+
${{github.workspace}}/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.js
376+
${{github.workspace}}/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.wasm
377+
${{github.workspace}}/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.js.bak
378+
233379
# Try to upload a release using https://github.com/marvinpinto/actions/issues/177#issuecomment-917605585 as a model
234380
release-latest:
235381
name: Release Latest Build
236382
runs-on: ubuntu-latest
237-
needs: [python-ubuntu, python-macos]
383+
needs: [python-ubuntu, python-macos, build-wasm]
238384
if: github.ref == 'refs/heads/main'
239385
steps:
240386
- name: Download artifacts
241387
uses: actions/download-artifact@v2
242-
388+
243389
- name: Update GitHub prerelease
244390
uses: marvinpinto/action-automatic-releases@latest
245391
with:
@@ -248,12 +394,16 @@ jobs:
248394
prerelease: true
249395
title: "Latest Build"
250396
files: |
251-
${{github.workspace}}/artifact/*.whl
397+
artifact/*.whl
398+
wasm-artefacts/build-wasm-without-wormhole/bergamot-translator-worker.js
399+
wasm-artefacts/build-wasm-without-wormhole/bergamot-translator-worker.wasm
400+
wasm-artefacts/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.js
401+
wasm-artefacts/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.wasm
252402
253403
release-version:
254404
name: Release version
255405
runs-on: ubuntu-latest
256-
needs: [python-ubuntu, python-macos]
406+
needs: [python-ubuntu, python-macos, build-wasm]
257407
permissions:
258408
contents: "write"
259409
packages: "write"
@@ -271,7 +421,12 @@ jobs:
271421
prerelease: false
272422
title: "${{ github.ref_name }}"
273423
files: |
274-
${{github.workspace}}/artifact/*.whl
424+
artifact/*.whl
425+
wasm-artefacts/build-wasm-without-wormhole/bergamot-translator-worker.js
426+
wasm-artefacts/build-wasm-without-wormhole/bergamot-translator-worker.wasm
427+
wasm-artefacts/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.js
428+
wasm-artefacts/build-wasm-with-wormhole/bergamot-translator-worker-with-wormhole.wasm
429+
275430
276431
python-checks:
277432
name: "formatting and typechecks"

.github/workflows/wasm.yml

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

0 commit comments

Comments
 (0)