Emit source phase import for MODULARIZE=instance#27237
Open
guybedford wants to merge 2 commits into
Open
Conversation
sbc100
reviewed
Jul 2, 2026
| #if SOURCE_PHASE_IMPORTS && MODULARIZE == 'instance' | ||
| // In MODULARIZE=instance mode the output is not wrapped by modularize.js, so the | ||
| // source phase import (normally emitted there) is emitted here at module scope. | ||
| import source wasmModule from './{{{ WASM_BINARY_FILE }}}'; |
Collaborator
There was a problem hiding this comment.
Can we remove the import source wasmModule from modularize.js maybe and just have a single one here?
Collaborator
There was a problem hiding this comment.
Also should we put this in preamble.js instead? since that seems to be where it is used? (Also, var wasmModule is alreayd declared there in threaded mode.
Collaborator
Author
There was a problem hiding this comment.
Moved to the preamble.js next to wasmModule.
We can't remove the import source wasmModule from modularize.js since these are distinct initialization shapes - modularize.js uses a factory function, while MODULARIZE=instance skips the modularize.js entirely since it doesn't use a factory function.
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.
103e1cd to
476868d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes
-sSOURCE_PHASE_IMPORTSwork together with-sMODULARIZE=instance(andEXPORT_ES6).In
MODULARIZE=instancemode the output is not wrapped bymodularize(), so the top-levelimport source wasmModulestatement thatsrc/modularize.jsnormally emits was never produced. This leftpreamble.jsreferencing an undefinedwasmModule, 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.jsat module scope when both settings are enabled:Adds a parameterized
test_esm_source_phase_imports_instance(default and-O3) that builds with-sSOURCE_PHASE_IMPORTS -sMODULARIZE=instanceand verifies the import is emitted and the module runs.