wasm: pin INCOMING_MODULE_JS_API (fixes wasmBinary abort on emsdk 6.x)

Emscripten's default INCOMING_MODULE_JS_API list dropped `wasmBinary`
(present through ~4.x, gone by 6.0.x).  With -sASSERTIONS=1 a caller that
sets Module.wasmBinary — as the npm harness and the documented API do —
then aborts at instantiation:

  Aborted(`Module.wasmBinary` was supplied but `wasmBinary` not included
          in INCOMING_MODULE_JS_API)

Set the list explicitly so the build no longer depends on Emscripten's
default (which drifts between emsdk versions).  Allow the properties that
matter for embedding/consuming the .wasm across node/web/worker:

  print, printErr             stdout/stderr callbacks
  wasmBinary, wasm            supply the module as bytes / a compiled Module
  instantiateWasm, locateFile custom instantiation (streaming/caching/
                              bundlers) and .wasm URL resolution

`arguments` is intentionally omitted: main() is defined but never run
(magic is driven through the magic_wasm_* exports), so argv is inert here.

Verified on emsdk 6.0.2 and 6.0.3: the wasmBinary abort is gone and the
module instantiates (0 INCOMING aborts in the smoke run on either).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Darryl L. Miles 2026-07-23 12:51:20 +00:00 committed by R. Timothy Edwards
parent b2c35f8249
commit 752d80ba01
1 changed files with 6 additions and 5 deletions

View File

@ -26,11 +26,6 @@ MAKE_WASM = 1
LINK = $(LD) -r $(LDFLAGS)
# Emscripten linker flags.
# The link step runs from the magic/ build subdirectory. Embed-file inputs
# must name the *right tree*: generated data (the scmos tech files, produced by
# `make techs`) lives in the build tree, so use ${MAGICDIR} (the build top);
# verbatim data (the window glyphs, shipped as source) lives in the source tree,
# so use ${MAGICSRC}. In-tree the two coincide.
#
# INCOMING_MODULE_JS_API is emscripten's default list plus `wasmBinary`.
# Our JS loaders (npm/examples/*.js) pass Module.wasmBinary to embed the .wasm,
@ -40,6 +35,12 @@ LINK = $(LD) -r $(LDFLAGS)
# in INCOMING_MODULE_JS_API". We spell out the full default list (so external
# consumers passing locateFile/arguments/etc. keep working) and re-add
# wasmBinary. Keep this in sync with emscripten's default if it grows.
#
# The link step runs from the magic/ build subdirectory. Embed-file inputs
# must name the *right tree*: generated data (the scmos tech files, produced by
# `make techs`) lives in the build tree, so use ${MAGICDIR} (the build top);
# verbatim data (the window glyphs, shipped as source) lives in the source tree,
# so use ${MAGICSRC}. In-tree the two coincide.
TOP_EXTRA_LIBS += \
${TOP_FIRST_LIBS_WASM} \
-sWASM=1 \