Skip to content

Wasm build fixes - #2

Open
lynt-smitka wants to merge 4 commits into
johnnohj:browser-boardfrom
MakerClassCZ:wasm-build-fixes
Open

Wasm build fixes#2
lynt-smitka wants to merge 4 commits into
johnnohj:browser-boardfrom
MakerClassCZ:wasm-build-fixes

Conversation

@lynt-smitka

Copy link
Copy Markdown

Four small fixes found while building the browser-board wasm port from a
fresh checkout.

  • py/compile: guard the WASM native-emitter table slot for mpy-cross. The
    dynamic-compiler table referenced emit_native_wasm_method_table, which
    mpy-cross cannot provide (it needs the port-runtime mp_wasm_compile_native),
    so mpy-cross failed to link. Gated on MICROPY_EMIT_WASM (NULL when absent;
    index stays aligned to MP_NATIVE_ARCH_WASM32).

  • tools/gen_display_resources: support the current adafruit_bitmap_font
    API. The generator assumed the old dict-glyph + _load_row API; the current
    lib returns fontio.Glyph objects and writes glyph pixels via
    bitmap[i] = bit, which broke the browser build. BitmapStub now supports
    both; glyph access uses attributes.

  • requirements-dev: add huffman + adafruit-circuitpython-bitmap-font
    (imported by gen_display_resources but not listed, so a fresh venv fails).

  • wasm/js/display: set the canvas backing-store resolution (canvas.width /
    canvas.height) from the framebuffer, not just CSS. Otherwise an embedder
    whose <canvas> lacks width/height attributes gets the 300×150 default and
    putImageData() is clipped.

The MICROPY_DYNAMIC_COMPILER emit_native_table lists every arch's method
table so -march can pick one at runtime. mpy-cross links this table but
cannot provide the WASM native emitter: it needs the port-runtime symbol
mp_wasm_compile_native, which only exists in the wasm port, not the host
tool. So building mpy-cross fails with:
  undefined reference to `emit_native_wasm_method_table'

Gate the table entry on MICROPY_EMIT_WASM (NULL when absent). The slot stays
index-aligned to MP_NATIVE_ARCH_WASM32, and mpy-cross never selects wasm32
for freezing, so the NULL is unreachable there.
… API

The display-resource generator targeted an old bitmap_font API and broke the
wasm browser build:
  - BitmapStub only had _load_row(); current bitmap_font writes glyph pixels
    via bitmap[y*width + x] = bit -> "BitmapStub does not support item
    assignment".
  - glyphs are accessed as dicts (g["shift"], g["bounds"], g["bitmap"]) but
    fontio.Glyph is an object -> "'Glyph' object is not subscriptable".

Give BitmapStub __setitem__ (flat index -> byte-packed bit) plus a byte-packed
.rows property (kept _load_row for the older API), and read glyph attributes
(g.shift_y, g.width/height/dx/dy, g.bitmap).
The wasm port's tools/gen_display_resources.py imports both (huffman for the
translation compression, adafruit_bitmap_font to rasterize the built-in font),
but neither was listed, so a fresh venv fails the browser build with
ModuleNotFoundError.
…mebuffer

Display only set canvas.style.width/height (CSS), not canvas.width/height (the
backing-store resolution). An embedder whose <canvas> lacks width/height
attributes gets the 300x150 default, so putImageData() of the fbWidth×fbHeight
framebuffer is clipped/misplaced (the built-in IDE happens to hardcode the
attributes). Set canvas.width/height to the framebuffer dimensions so any
embedder renders correctly; CSS still scales it for display.
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.

1 participant