|
| 1 | +# |
| 2 | +# Copyright 2026 Paul Guyot <pguyot@kallisys.net> |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later |
| 5 | +# |
| 6 | + |
| 7 | +name: WASI Build |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + paths: |
| 12 | + - '.github/workflows/wasi-build.yaml' |
| 13 | + - 'CMakeLists.txt' |
| 14 | + - 'CMakeModules/**' |
| 15 | + - 'libs/**' |
| 16 | + - 'src/platforms/wasi/**' |
| 17 | + - 'src/libAtomVM/**' |
| 18 | + pull_request: |
| 19 | + paths: |
| 20 | + - '.github/workflows/wasi-build.yaml' |
| 21 | + - 'CMakeLists.txt' |
| 22 | + - 'CMakeModules/**' |
| 23 | + - 'libs/**' |
| 24 | + - 'src/platforms/wasi/**' |
| 25 | + - 'src/libAtomVM/**' |
| 26 | + |
| 27 | +permissions: |
| 28 | + contents: write |
| 29 | + |
| 30 | +concurrency: |
| 31 | + group: ${{ github.workflow }}-${{ github.ref != 'refs/heads/main' && github.ref || github.run_id }} |
| 32 | + cancel-in-progress: true |
| 33 | + |
| 34 | +jobs: |
| 35 | + |
| 36 | + compile_tests: |
| 37 | + |
| 38 | + runs-on: ubuntu-24.04 |
| 39 | + container: erlang:28 |
| 40 | + permissions: |
| 41 | + actions: read |
| 42 | + contents: read |
| 43 | + security-events: write |
| 44 | + |
| 45 | + strategy: |
| 46 | + fail-fast: false |
| 47 | + matrix: |
| 48 | + language: ["c-cpp"] |
| 49 | + |
| 50 | + steps: |
| 51 | + - name: Checkout repo |
| 52 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 53 | + |
| 54 | + - name: Install required packages |
| 55 | + run: apt update && apt install -y gperf zlib1g-dev cmake ninja-build |
| 56 | + |
| 57 | + - name: "Git config safe.directory for codeql" |
| 58 | + run: git config --global --add safe.directory /__w/AtomVM/AtomVM |
| 59 | + |
| 60 | + - name: "Initialize CodeQL" |
| 61 | + uses: github/codeql-action/init@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4 |
| 62 | + with: |
| 63 | + languages: ${{matrix.language}} |
| 64 | + build-mode: manual |
| 65 | + queries: +./code-queries/term-to-non-term-func.ql,./code-queries/non-term-to-term-func.ql,./code-queries/mismatched-atom-string-length.ql,./code-queries/mismatched-free-type.ql,./code-queries/term-use-after-gc.ql,./code-queries/allocations-exceeding-ensure-free.ql,./code-queries/allocations-without-ensure-free.ql |
| 66 | + |
| 67 | + - name: Compile AtomVM and test modules |
| 68 | + run: | |
| 69 | + set -e |
| 70 | + mkdir build |
| 71 | + cd build |
| 72 | + cmake .. -G Ninja -DAVM_WARNINGS_ARE_ERRORS=ON |
| 73 | + ninja AtomVM atomvmlib erlang_test_modules test_etest test_alisp test_estdlib test_eavmlib |
| 74 | +
|
| 75 | + - name: "Perform CodeQL Analysis" |
| 76 | + uses: github/codeql-action/analyze@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4 |
| 77 | + |
| 78 | + - name: Upload AtomVM and test modules |
| 79 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 80 | + with: |
| 81 | + name: atomvm-and-test-modules |
| 82 | + path: | |
| 83 | + build/**/*.avm |
| 84 | + build/**/*.beam |
| 85 | + build/src/AtomVM |
| 86 | + retention-days: 1 |
| 87 | + |
| 88 | + wasi_build_and_test: |
| 89 | + needs: compile_tests |
| 90 | + runs-on: ubuntu-24.04 |
| 91 | + |
| 92 | + strategy: |
| 93 | + fail-fast: false |
| 94 | + matrix: |
| 95 | + include: |
| 96 | + # No SMP, no networking - minimal stable target. |
| 97 | + - target: wasm32-wasip1 |
| 98 | + disable_smp: ON |
| 99 | + wasmtime_flags: "" |
| 100 | + # SMP via wasi-threads, no networking. Needs shared-memory in wasmtime. |
| 101 | + - target: wasm32-wasip1-threads |
| 102 | + disable_smp: OFF |
| 103 | + wasmtime_flags: "-W threads -W shared-memory -S threads" |
| 104 | + # No SMP, networking via wasi:sockets@0.2.x - exercises BSD sockets and SSL. |
| 105 | + - target: wasm32-wasip2 |
| 106 | + disable_smp: ON |
| 107 | + wasmtime_flags: "-S inherit-network -S allow-ip-name-lookup" |
| 108 | + |
| 109 | + steps: |
| 110 | + - name: Checkout repo |
| 111 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 112 | + |
| 113 | + - name: Install required packages |
| 114 | + run: sudo apt-get update -y && sudo apt-get install -y cmake ninja-build gperf |
| 115 | + |
| 116 | + - name: Install WASI SDK |
| 117 | + run: | |
| 118 | + set -euo pipefail |
| 119 | + WASI_SDK_VERSION=33 |
| 120 | + wget -q "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux.tar.gz" |
| 121 | + sudo mkdir -p /opt/wasi-sdk |
| 122 | + sudo tar xzf "wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux.tar.gz" --strip-components=1 -C /opt/wasi-sdk |
| 123 | +
|
| 124 | + - name: Install wasmtime |
| 125 | + run: | |
| 126 | + set -euo pipefail |
| 127 | + WASMTIME_VERSION=44.0.1 |
| 128 | + WASMTIME_TARBALL="wasmtime-v${WASMTIME_VERSION}-x86_64-linux.tar.xz" |
| 129 | + WASMTIME_SHA256="afd58715f105e3a7f454169daed22168c5736ec5f225fb04c4ac62c54c9508a3" |
| 130 | + wget -q "https://github.com/bytecodealliance/wasmtime/releases/download/v${WASMTIME_VERSION}/${WASMTIME_TARBALL}" |
| 131 | + echo "${WASMTIME_SHA256} ${WASMTIME_TARBALL}" | sha256sum -c - |
| 132 | + sudo mkdir -p /opt/wasmtime |
| 133 | + sudo tar xf "${WASMTIME_TARBALL}" --strip-components=1 -C /opt/wasmtime |
| 134 | + echo "/opt/wasmtime" >> $GITHUB_PATH |
| 135 | +
|
| 136 | + - name: Build (${{ matrix.target }}) |
| 137 | + working-directory: ./src/platforms/wasi/ |
| 138 | + run: | |
| 139 | + set -euo pipefail |
| 140 | + mkdir build |
| 141 | + cd build |
| 142 | + cmake -G Ninja \ |
| 143 | + -DCMAKE_TOOLCHAIN_FILE=../wasi-sdk.cmake \ |
| 144 | + -DAVM_DISABLE_JIT=ON \ |
| 145 | + -DAVM_DISABLE_SMP=${{ matrix.disable_smp }} \ |
| 146 | + -DWASI_TARGET=${{ matrix.target }} \ |
| 147 | + .. |
| 148 | + ninja |
| 149 | +
|
| 150 | + - name: Download AtomVM and test modules |
| 151 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 152 | + with: |
| 153 | + name: atomvm-and-test-modules |
| 154 | + path: build |
| 155 | + |
| 156 | + - name: Test (${{ matrix.target }}) |
| 157 | + working-directory: ./build |
| 158 | + run: | |
| 159 | + set -euxo pipefail |
| 160 | + WASM=../src/platforms/wasi/build/src/AtomVM.wasm |
| 161 | + FLAGS="${{ matrix.wasmtime_flags }}" |
| 162 | + wasmtime run ${FLAGS} --dir=. ${WASM} tests/libs/alisp/test_alisp.avm |
| 163 | + wasmtime run ${FLAGS} --dir=. ${WASM} tests/libs/estdlib/test_estdlib.avm |
| 164 | + wasmtime run ${FLAGS} --dir=. ${WASM} tests/libs/etest/test_etest.avm |
| 165 | + wasmtime run ${FLAGS} --dir=. ${WASM} tests/libs/eavmlib/test_eavmlib.avm |
| 166 | +
|
| 167 | + - name: "Rename and write sha256sum" |
| 168 | + if: startsWith(github.ref, 'refs/tags/') |
| 169 | + working-directory: src/platforms/wasi/build/src |
| 170 | + run: | |
| 171 | + ATOMVM_WASM=AtomVM-${{ matrix.target }}-${{ github.ref_name }}.wasm |
| 172 | + mv AtomVM.wasm "${ATOMVM_WASM}" |
| 173 | + sha256sum "${ATOMVM_WASM}" > "${ATOMVM_WASM}.sha256" |
| 174 | +
|
| 175 | + - name: "Release" |
| 176 | + uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0 |
| 177 | + if: startsWith(github.ref, 'refs/tags/') |
| 178 | + with: |
| 179 | + draft: true |
| 180 | + fail_on_unmatched_files: true |
| 181 | + files: | |
| 182 | + src/platforms/wasi/build/src/AtomVM-${{ matrix.target }}-${{ github.ref_name }}.wasm |
| 183 | + src/platforms/wasi/build/src/AtomVM-${{ matrix.target }}-${{ github.ref_name }}.wasm.sha256 |
0 commit comments