Skip to content

Commit

Permalink
Add options to build release and nightly wasm versions from kiwix-bui…
Browse files Browse the repository at this point in the history
…ld binaries #12 (#37)
  • Loading branch information
Jaifroid authored Dec 12, 2022
1 parent 5f0f280 commit 7d17061
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
53 changes: 49 additions & 4 deletions .github/workflows/build_libzim_wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
name: Build and publish release artefacts (Docker)

on:
schedule:
# Nightly run at 02:21 UTC
- cron: '21 02 * * *'
push:
branches: [ main ]
tags:
Expand All @@ -19,12 +22,26 @@ on:
If left blank or incorrect format, archives will be archived instead of being uploaded to Releases.
required: false
default: ''

buildtype:
description: |
Choose the build type - 'source' (from source code, i.e., built from scratch - this takes a long time),
'release' (from libzim released binary and dependencies - recommended), or 'nightly' (from the latest libzim
nightly release)
type: choice
options:
- source
- release
- nightly
default: 'release'
required: true

# Define top-level environment vars we can refer to below
env:
VERSION: ${{ github.ref_name }}
DISPATCH_VERSION: ${{ github.event.inputs.version }}
DISPATCH_TYPE: ${{ github.event.inputs.buildtype }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SSH_KEY: ${{ secrets.SSH_KEY }}

jobs:
build:
Expand All @@ -35,8 +52,21 @@ jobs:
# Customizes the Emscripten docker container via the Dockerfile in this repo
- name: Build the Docker image
run: docker build -t "docker-emscripten-libzim:v3" ./docker
# If we're building release version
- name: Build release from libzim binaries
if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event.inputs.buildtype == 'release'
run: |
make libzim_release
docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) docker-emscripten-libzim:v3 make release
# If we're building nightly version
- name: Build nightly from libzim binaries
if: github.event.schedule || github.event.inputs.buildtype == 'nightly'
run: |
make libzim_nightly
docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) docker-emscripten-libzim:v3 make nightly
# Creates the ASM and WASM artefacts, and the JS wrappers, using the Makefile in this repo
- name: Compile the libzim WASM artefacts
- name: Compile the libzim WASM artefacts from source
if: github.event.inputs.buildtype == 'source'
run: docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) docker-emscripten-libzim:v3 make
- name: List directories with updated archives
run: |
Expand All @@ -50,15 +80,15 @@ jobs:
- name: Archive build artefacts
if: |
github.event_name == 'pull_request' || github.event_name == 'push' && ! startsWith(github.ref_name, 'v')
|| ! startsWith(github.event.inputs.version, 'v')
|| github.event.inputs.buildtype != 'nightly' && ! github.event.schedule && ! startsWith(github.event.inputs.version, 'v')
uses: actions/upload-artifact@v3
with:
name: libzim-wasm-artefacts
path: |
libzim-wasm.*
libzim-asm.*
tests/test_large_file_access/large_file_access.*
# Otherwise, zip the artefacts into respective packages (asm and wasm), create and upload releases
# If it's a release, zip the artefacts into respective packages (asm and wasm), create and upload releases
- name: Zip the artefacts and create draft release
id: zip-release
if: github.event_name == 'push' && startsWith(github.ref_name, 'v') || startsWith(github.event.inputs.version, 'v')
Expand All @@ -69,3 +99,18 @@ jobs:
# Create a draft release and upload zipped artefacts as release assets
chmod +x ./scripts/create_draft_release.sh
./scripts/create_draft_release.sh
# If it's a nightly build, zip artefacts and upload releases
- name: Zip the artefacts and upload to nightly
if: github.event.schedule || github.event.inputs.buildtype == 'nightly'
run: |
echo "$SSH_KEY" > ./scripts/ssh_key
chmod 600 ./scripts/ssh_key
CURRENT_DATE=$(date +'%Y-%m-%d')
target="/data/openzim/nightly/$CURRENT_DATE"
zip libzim-javascript_wasm_$CURRENT_DATE.zip libzim-wasm.*
zip libzim-javascript_asm_$CURRENT_DATE.zip libzim-asm.*
for FILE in "libzim-javascript_wasm_$CURRENT_DATE.zip" "libzim-javascript_asm_$CURRENT_DATE.zip"
do
echo "Copying $FILE to $target"
scp -P 30022 -o StrictHostKeyChecking=no -i ./scripts/ssh_key "$FILE" [email protected]:$target
done
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
/icu4c-*.tgz
/xapian-core-*.tar.xz
/libzim-*
/libzim_wasm-*.tar.gz
ssh_key
github_token
github_token
32 changes: 27 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
all: libzim-wasm.dev.js libzim-asm.dev.js libzim-wasm.js libzim-asm.js large_file_access.js
SHELL := /bin/bash

all: build/lib/libzim.a libzim-wasm.dev.js libzim-asm.dev.js libzim-wasm.js libzim-asm.js large_file_access.js

release: libzim-asm.js libzim-wasm.js libzim-asm.dev.js libzim-wasm.dev.js large_file_access.js

nightly: libzim-asm.js libzim-wasm.js libzim-asm.dev.js libzim-wasm.dev.js large_file_access.js

libzim_release:
wget -N $$(wget -q https://download.openzim.org/release/libzim/feed.xml -O - | grep -E -o -m1 "<link>[^<]+wasm-emscripten[^<]+</link>" | sed -E "s:</?link>::g")
tar xf libzim_wasm-emscripten-*.tar.gz
mkdir build
mkdir build/lib
cp -r libzim_wasm-emscripten-*/include/ build/include/
cp -r libzim_wasm-emscripten-*/lib/x86_64-linux-gnu/*.* build/lib/

libzim_nightly:
wget -N https://download.openzim.org/nightly/$$(date +'%Y-%m-%d')/$$(wget -q https://download.openzim.org/nightly/$$(date +'%Y-%m-%d') -O - | grep -E -o -m1 '"libzim_wasm-emscripten[^"]+"' | sed -E 's/"//g')
tar xf libzim_wasm-emscripten-$$(date +'%Y-%m-%d').tar.gz
mkdir build
mkdir build/lib
cp -r libzim_wasm-emscripten-$$(date +'%Y-%m-%d')/include/ build/include/
cp -r libzim_wasm-emscripten-$$(date +'%Y-%m-%d')/lib/x86_64-linux-gnu/*.* build/lib/

build/lib/liblzma.so :
# Origin: https://tukaani.org/xz/xz-5.2.4.tar.gz
Expand Down Expand Up @@ -56,20 +78,20 @@ build/lib/libzim.a : build/lib/liblzma.so build/lib/libz.a build/lib/libzstd.a b
cd libzim-8.1.0; ninja -C build install

# Development WASM version for testing, completely unoptimized
libzim-wasm.dev.js: build/lib/libzim.a libzim_bindings.cpp prejs_file_api.js postjs_file_api.js
libzim-wasm.dev.js: libzim_bindings.cpp prejs_file_api.js postjs_file_api.js
em++ -o libzim-wasm.dev.js --bind libzim_bindings.cpp -I/src/build/include -L/src/build/lib -lzim -llzma -lzstd -lxapian -lz -licui18n -licuuc -licudata -lpthread -lm -fdiagnostics-color=always -pipe -Wall -Winvalid-pch -Wnon-virtual-dtor -Werror -std=c++11 -O0 -g --pre-js prejs_file_api.js --post-js postjs_file_api.js -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s "EXPORTED_RUNTIME_METHODS=['ALLOC_NORMAL','printErr','ALLOC_STACK','print']" -s DEMANGLE_SUPPORT=1 -s INITIAL_MEMORY=83886080 -s ALLOW_MEMORY_GROWTH=1 -lworkerfs.js
cp libzim-wasm.dev.* tests/prototype/

# Development ASM version for testing, completely unoptimized
libzim-asm.dev.js: build/lib/libzim.a libzim_bindings.cpp prejs_file_api.js postjs_file_api.js
libzim-asm.dev.js: libzim_bindings.cpp prejs_file_api.js postjs_file_api.js
em++ -o libzim-asm.dev.js --bind libzim_bindings.cpp -I/src/build/include -L/src/build/lib -lzim -llzma -lzstd -lxapian -lz -licui18n -licuuc -licudata -lpthread -lm -fdiagnostics-color=always -pipe -Wall -Winvalid-pch -Wnon-virtual-dtor -Werror -std=c++11 -O0 -g --pre-js prejs_file_api.js --post-js postjs_file_api.js -s WASM=0 --memory-init-file 0 -s DISABLE_EXCEPTION_CATCHING=0 -s "EXPORTED_RUNTIME_METHODS=['ALLOC_NORMAL','printErr','ALLOC_STACK','print']" -s DEMANGLE_SUPPORT=1 -s INITIAL_MEMORY=83886080 -s ALLOW_MEMORY_GROWTH=1 -lworkerfs.js

# Production WASM version, optimized and packed
libzim-wasm.js: build/lib/libzim.a libzim_bindings.cpp prejs_file_api.js postjs_file_api.js
libzim-wasm.js: libzim_bindings.cpp prejs_file_api.js postjs_file_api.js
em++ -o libzim-wasm.js --bind libzim_bindings.cpp -I/src/build/include -L/src/build/lib -lzim -llzma -lzstd -lxapian -lz -licui18n -licuuc -licudata -O3 --pre-js prejs_file_api.js --post-js postjs_file_api.js -s WASM=1 -s "EXPORTED_RUNTIME_METHODS=['ALLOC_NORMAL','printErr','ALLOC_STACK','print']" -s INITIAL_MEMORY=83886080 -s ALLOW_MEMORY_GROWTH=1 -lworkerfs.js

# Production ASM version, optimized and packed
libzim-asm.js: build/lib/libzim.a libzim_bindings.cpp prejs_file_api.js postjs_file_api.js
libzim-asm.js: libzim_bindings.cpp prejs_file_api.js postjs_file_api.js
em++ -o libzim-asm.js --bind libzim_bindings.cpp -I/src/build/include -L/src/build/lib -lzim -llzma -lzstd -lxapian -lz -licui18n -licuuc -licudata -O3 --pre-js prejs_file_api.js --post-js postjs_file_api.js -s WASM=0 --memory-init-file 0 -s MIN_EDGE_VERSION=40 -s "EXPORTED_RUNTIME_METHODS=['ALLOC_NORMAL','printErr','ALLOC_STACK','print']" -s INITIAL_MEMORY=83886080 -s ALLOW_MEMORY_GROWTH=1 -lworkerfs.js

# Test case: for testing large files
Expand Down

0 comments on commit 7d17061

Please sign in to comment.