Skip to content

Build Wasm Examples #40

Build Wasm Examples

Build Wasm Examples #40

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
# See README.md in this directory for more information about workflow_call
name: Build Wasm Examples
on:
workflow_dispatch: {}
workflow_call:
inputs:
docs_only:
description: Skip building if docs only
required: false
type: string
default: "false"
schedule:
# Run at 1am UTC daily
- cron: '0 1 * * *'
permissions:
packages: write
contents: read
jobs:
build-wasm-examples:
if: ${{ inputs.docs_only == 'false' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Remove default clang
run: sudo rm /usr/bin/clang
- name: Hyperlight setup workflow
uses: hyperlight-dev/[email protected]
with:
rust-toolchain: "1.85.0"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull wasm-clang-builder
continue-on-error: true
run: |
docker pull ghcr.io/${{ github.repository_owner }}/wasm-clang-builder:latest
- name: Set up Docker image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ github.repository_owner }}/wasm-clang-builder
- name: Build and push wasm-clang-builder
# Only push if not from a fork, not from pull request, and not from dependabot
uses: docker/build-push-action@v6
with:
context: src/wasmsamples
file: src/wasmsamples/dockerfile
load: true
push: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false) && github.actor != 'dependabot[bot]' }}
build-args: |
WASI_SDK_VERSION_FULL=20.0
GCC_VERSION=12
tags: ghcr.io/${{ github.repository_owner }}/wasm-clang-builder:latest
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/wasm-clang-builder:buildcache
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/wasm-clang-builder:buildcache,mode=max
- name: Build Modules
run: |
for FILENAME in $(find . -name '*.c')
do
echo Building ${FILENAME}
docker run --rm -i -v "${PWD}:/tmp/host" ghcr.io/${{ github.repository_owner }}/wasm-clang-builder:latest /opt/wasi-sdk/bin/clang -flto -ffunction-sections -mexec-model=reactor -O3 -z stack-size=4096 -Wl,--initial-memory=65536 -Wl,--export=__data_end -Wl,--export=__heap_base,--export=malloc,--export=free,--export=__wasm_call_ctors -Wl,--strip-all,--no-entry -Wl,--allow-undefined -Wl,--gc-sections -o /tmp/host/${FILENAME%.*}-wasi-libc.wasm /tmp/host/${FILENAME}
cargo run -p hyperlight-wasm-aot compile ${FILENAME%.*}-wasi-libc.wasm ${FILENAME%.*}.aot
cp ${FILENAME%.*}.aot ${FILENAME%.*}.wasm
done
shell: bash
working-directory: src/wasmsamples
- name: Upload Wasm Modules
uses: actions/upload-artifact@v4
with:
name: guest-modules
path: |
src/wasmsamples/*.wasm
src/wasmsamples/*.aot