diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 56828a4..5d1abb5 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -223,10 +223,49 @@ jobs: name: emlearn-micropython-build-macos path: dist + build-webassembly: + runs-on: ubuntu-latest + env: + MPY_DIR: ./micropython + MICROPYTHON_BIN: ./micropython/ports/unix/build-nomodules/micropython + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install OS dependencies + run: sudo add-apt-repository universe + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + - uses: actions/checkout@v4 + with: + repository: jonnor/micropython + path: micropython + ref: webassembly-extra-cflags + - name: Install Python dependencies + run: pip install -r requirements.txt + - name: Setup MicroPython + working-directory: micropython + run: | + npm install terser + git clone https://github.com/emscripten-core/emsdk.git + (cd emsdk && ./emsdk install 4.0.21 && ./emsdk activate 4.0.21) + make -C mpy-cross CFLAGS_EXTRA=-Wno-error + - name: Build Webassembly + run: | + source ${MPY_DIR}/emsdk/emsdk_env.sh + make -C ${MPY_DIR}/ports/webassembly submodules + make webassembly V=1 + - name: Archive dist artifacts + uses: actions/upload-artifact@v4 + with: + name: emlearn-micropython-build-webassembly + path: dist + deploy-pages: permissions: contents: write - needs: [build-linux, build-arm, build-esp32, build-macos, build-riscv] + needs: [build-linux, build-arm, build-esp32, build-macos, build-riscv, build-webassembly] runs-on: ubuntu-latest steps: diff --git a/Makefile b/Makefile index dade70b..7d29d35 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ PORT_BUILD_DIR=$(MPY_DIR)/ports/$(PORT)/build-$(BOARD) PORT_DIST_DIR=./dist/ports/$(PORT)/$(BOARD) UNIX_MICROPYTHON = ./dist/ports/unix/micropython - +WEBASSEMBLY_MICROPYTHON = ./dist/ports/webassembly/micropython.mjs # List of modules MODULES = emlearn_trees \ @@ -72,6 +72,17 @@ $(UNIX_MICROPYTHON): $(PORT_DIR) unix: $(UNIX_MICROPYTHON) +$(WEBASSEMBLY_MICROPYTHON): $(PORT_DIR) + emcc --version + mkdir -p $(PORT_DIR)/../webassembly + make -C $(MPY_DIR)/ports/webassembly VARIANT=standard V=1 USER_C_MODULES=$(C_MODULES_SRC_PATH) FROZEN_MANIFEST=$(MANIFEST_PATH) CFLAGS_EXTRA="-Wno-unused-function -Wno-unused-function ${CFLAGS_EXTRA}" -j4 + cp $(MPY_DIR)/ports/webassembly/build-standard/micropython.mjs $@ + cp $(MPY_DIR)/ports/webassembly/build-standard/micropython.wasm dist/ports/webassembly/ + + +webassembly: $(WEBASSEMBLY_MICROPYTHON) + + check_unix: $(UNIX_MICROPYTHON) $(UNIX_MICROPYTHON) tests/test_all.py test_iir,test_fft,test_arrayutils # TODO: enable more modules