Skip to content

Commit 0839553

Browse files
authored
Merge pull request #61 from emlearn/webassembly-build
Add Webassembly build
2 parents b06a6a2 + 903d025 commit 0839553

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

.github/workflows/build.yaml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,49 @@ jobs:
223223
name: emlearn-micropython-build-macos
224224
path: dist
225225

226+
build-webassembly:
227+
runs-on: ubuntu-latest
228+
env:
229+
MPY_DIR: ./micropython
230+
MICROPYTHON_BIN: ./micropython/ports/unix/build-nomodules/micropython
231+
steps:
232+
- uses: actions/checkout@v4
233+
with:
234+
submodules: true
235+
- name: Install OS dependencies
236+
run: sudo add-apt-repository universe
237+
- uses: actions/setup-python@v5
238+
with:
239+
python-version: '3.10'
240+
- uses: actions/checkout@v4
241+
with:
242+
repository: jonnor/micropython
243+
path: micropython
244+
ref: webassembly-extra-cflags
245+
- name: Install Python dependencies
246+
run: pip install -r requirements.txt
247+
- name: Setup MicroPython
248+
working-directory: micropython
249+
run: |
250+
npm install terser
251+
git clone https://github.com/emscripten-core/emsdk.git
252+
(cd emsdk && ./emsdk install 4.0.21 && ./emsdk activate 4.0.21)
253+
make -C mpy-cross CFLAGS_EXTRA=-Wno-error
254+
- name: Build Webassembly
255+
run: |
256+
source ${MPY_DIR}/emsdk/emsdk_env.sh
257+
make -C ${MPY_DIR}/ports/webassembly submodules
258+
make webassembly V=1
259+
- name: Archive dist artifacts
260+
uses: actions/upload-artifact@v4
261+
with:
262+
name: emlearn-micropython-build-webassembly
263+
path: dist
264+
226265
deploy-pages:
227266
permissions:
228267
contents: write
229-
needs: [build-linux, build-arm, build-esp32, build-macos, build-riscv]
268+
needs: [build-linux, build-arm, build-esp32, build-macos, build-riscv, build-webassembly]
230269
runs-on: ubuntu-latest
231270

232271
steps:

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ PORT_BUILD_DIR=$(MPY_DIR)/ports/$(PORT)/build-$(BOARD)
2727
PORT_DIST_DIR=./dist/ports/$(PORT)/$(BOARD)
2828

2929
UNIX_MICROPYTHON = ./dist/ports/unix/micropython
30-
30+
WEBASSEMBLY_MICROPYTHON = ./dist/ports/webassembly/micropython.mjs
3131

3232
# List of modules
3333
MODULES = emlearn_trees \
@@ -72,6 +72,17 @@ $(UNIX_MICROPYTHON): $(PORT_DIR)
7272

7373
unix: $(UNIX_MICROPYTHON)
7474

75+
$(WEBASSEMBLY_MICROPYTHON): $(PORT_DIR)
76+
emcc --version
77+
mkdir -p $(PORT_DIR)/../webassembly
78+
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
79+
cp $(MPY_DIR)/ports/webassembly/build-standard/micropython.mjs $@
80+
cp $(MPY_DIR)/ports/webassembly/build-standard/micropython.wasm dist/ports/webassembly/
81+
82+
83+
webassembly: $(WEBASSEMBLY_MICROPYTHON)
84+
85+
7586
check_unix: $(UNIX_MICROPYTHON)
7687
$(UNIX_MICROPYTHON) tests/test_all.py test_iir,test_fft,test_arrayutils
7788
# TODO: enable more modules

0 commit comments

Comments
 (0)