Skip to content

Emit source phase import for MODULARIZE=instance#27237

Merged
sbc100 merged 2 commits into
emscripten-core:mainfrom
guybedford:esm-source-phase-instance
Jul 9, 2026
Merged

Emit source phase import for MODULARIZE=instance#27237
sbc100 merged 2 commits into
emscripten-core:mainfrom
guybedford:esm-source-phase-instance

Conversation

@guybedford

Copy link
Copy Markdown
Collaborator

This makes -sSOURCE_PHASE_IMPORTS work together with -sMODULARIZE=instance (and EXPORT_ES6).

In MODULARIZE=instance mode the output is not wrapped by modularize(), so the top-level import source wasmModule statement that src/modularize.js normally emits was never produced. This left preamble.js referencing an undefined wasmModule, breaking source phase imports in instance mode.

Since instance mode output is itself a module, the source phase import is now emitted directly from postamble.js at module scope when both settings are enabled:

#if SOURCE_PHASE_IMPORTS && MODULARIZE == 'instance'
import source wasmModule from './{{{ WASM_BINARY_FILE }}}';
#endif

Adds a parameterized test_esm_source_phase_imports_instance (default and -O3) that builds with -sSOURCE_PHASE_IMPORTS -sMODULARIZE=instance and verifies the import is emitted and the module runs.

Comment thread test/test_other.py Outdated
Comment thread src/postamble.js Outdated
@guybedford
guybedford force-pushed the esm-source-phase-instance branch 2 times, most recently from ef110e9 to 5535e45 Compare July 9, 2026 01:22
Comment thread test/test_other.py Outdated
Comment thread test/test_other.py Outdated
In MODULARIZE=instance mode the modularize() wrapper is not applied, so the
top-level 'import source wasmModule' statement in src/modularize.js was never
emitted, leaving preamble.js referencing an undefined wasmModule. Emit the
source phase import from preamble.js (module scope in instance mode), next to
where wasmModule is declared and used, so that -sSOURCE_PHASE_IMPORTS works
alongside -sMODULARIZE=instance/EXPORT_ES6.
@guybedford
guybedford force-pushed the esm-source-phase-instance branch from 5535e45 to ca8df65 Compare July 9, 2026 18:03
@sbc100
sbc100 enabled auto-merge (squash) July 9, 2026 18:14
@sbc100
sbc100 merged commit f616d92 into emscripten-core:main Jul 9, 2026
39 checks passed
@guybedford
guybedford deleted the esm-source-phase-instance branch July 9, 2026 20:07
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