Skip to content

feat: add WebAssembly build target for MicroPythonOS#1

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/investigate-wasm-micropython
Draft

feat: add WebAssembly build target for MicroPythonOS#1
Copilot wants to merge 2 commits into
mainfrom
copilot/investigate-wasm-micropython

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 28, 2026

Adds infrastructure to compile and run MicroPythonOS in the browser via Emscripten. Since lvgl_micropython/make.py has no webassembly target, the build uses MicroPython's upstream ports/webassembly Makefile directly (plain MicroPython + frozen Python files; LVGL canvas rendering is a follow-up once lvgl_micropython gains an Emscripten builder with -s USE_SDL=2).

C modules (c_mpos/micropython_wasm.mk)

  • Includes only quirc (pure C, no system deps)
  • Explicitly excludes: webcam (v4l2), adc_mic/pdm_mic (ESP-IDF), rvswd (ESP32 debugger), secp256k1-embedded-ecdh (possible x86 asm — pure-Python fallback already in lib/)

Python adaptation

  • detect_board() in mpos/main.py returns "webassembly" when sys.platform == "webassembly", slotted between the linux/darwin and esp32 branches
  • New mpos/board/webassembly.py: attempts SDL2 display/pointer init inside try/except (no-op without LVGL); skips audio, camera, and WiFi (WifiService already handles a missing network module gracefully)

Build script (scripts/build_mpos.sh wasm)

Sources emsdk, strips @micropython.viper (restored after build), compiles mpy-cross, then:

make -C ports/webassembly \
    USER_C_MODULES=".../c_mpos/micropython_wasm.mk" \
    FROZEN_MANIFEST=".../manifests/manifest.py"

Stages micropython.mjs, micropython.wasm, and html/index.html into lvgl_micropython/build/. The script documents the exact make.py invocation to switch to once lvgl_micropython gains Emscripten SDL2 support.

HTML shell (html/index.html)

  • <canvas id="lvgl"> (320×240) for future LVGL SDL2 rendering via Emscripten's SDL2 port
  • Terminal panel wired to Module.print / Module.printErr
  • REPL input row calling mp_js_do_exec via ccall

CI (.github/workflows/wasm.yml)

Installs and caches emsdk, runs build_mpos.sh wasm, uploads .mjs, .wasm, and index.html as 7-day artifacts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants