Skip to content

Update MINIMAL_RUNTIME instantiate/compileStreaming detection #24268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/postamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ var imports = {

#if MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION
// https://caniuse.com/#feat=wasm and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming
// Firefox 52 added Wasm support, but only Firefox 58 added instantiateStreaming.
// Chrome 57 added Wasm support, but only Chrome 61 added instantiateStreaming.
// Node.js and Safari do not support instantiateStreaming.
#if MIN_FIREFOX_VERSION < 58 || MIN_CHROME_VERSION < 61 || ENVIRONMENT_MAY_BE_NODE || MIN_SAFARI_VERSION != TARGET_NOT_SUPPORTED
#if MIN_FIREFOX_VERSION < 58 || MIN_CHROME_VERSION < 61 || MIN_NODE_VERSION < 180100 || MIN_SAFARI_VERSION < 150000
#if ASSERTIONS && !WASM2JS
// Module['wasm'] should contain a typed array of the Wasm object data, or a
// precompiled WebAssembly Module.
Expand Down Expand Up @@ -154,12 +151,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
// Depending on the build mode, Module['wasm'] can mean a different thing.
#if MINIMAL_RUNTIME_STREAMING_WASM_COMPILATION || MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION || PTHREADS
// https://caniuse.com/#feat=wasm and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming
// Firefox 52 added Wasm support, but only Firefox 58 added compileStreaming &
// instantiateStreaming.
// Chrome 57 added Wasm support, but only Chrome 61 added compileStreaming &
// instantiateStreaming.
// Node.js and Safari do not support compileStreaming or instantiateStreaming.
#if MIN_FIREFOX_VERSION < 58 || MIN_CHROME_VERSION < 61 || ENVIRONMENT_MAY_BE_NODE || MIN_SAFARI_VERSION != TARGET_NOT_SUPPORTED || PTHREADS
#if MIN_FIREFOX_VERSION < 58 || MIN_CHROME_VERSION < 61 || MIN_NODE_VERSION < 180100 || MIN_SAFARI_VERSION < 150000 || PTHREADS
// In pthreads, Module['wasm'] is an already compiled WebAssembly.Module. In
// that case, 'output' is a WebAssembly.Instance.
// In main thread, Module['wasm'] is either a typed array or a fetch stream.
Expand Down
8 changes: 2 additions & 6 deletions tools/minimal_runtime_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from . import building
from . import shared
from . import utils
from . import feature_matrix
from .settings import settings

logger = logging.getLogger('minimal_runtime_shell')
Expand All @@ -29,19 +28,16 @@ def generate_minimal_runtime_load_statement(target_basename):
# Expand {{{ DOWNLOAD_WASM }}} block from here (if we added #define support, this could be done in
# the template directly)
if settings.MINIMAL_RUNTIME_STREAMING_WASM_COMPILATION:
if settings.MIN_SAFARI_VERSION != feature_matrix.UNSUPPORTED or settings.ENVIRONMENT_MAY_BE_NODE or settings.MIN_FIREFOX_VERSION < 58 or settings.MIN_CHROME_VERSION < 61:
# Firefox 52 added Wasm support, but only Firefox 58 added compileStreaming.
# Chrome 57 added Wasm support, but only Chrome 61 added compileStreaming.
if settings.MIN_SAFARI_VERSION < 150000 or settings.MIN_NODE_VERSION < 180100 or settings.MIN_FIREFOX_VERSION < 58 or settings.MIN_CHROME_VERSION < 61:
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming
# In Safari and Node.js, WebAssembly.compileStreaming() is not supported, in which case fall back to regular download.
download_wasm = f"WebAssembly.compileStreaming ? WebAssembly.compileStreaming(fetch('{target_basename}.wasm')) : binary('{target_basename}.wasm')"
else:
# WebAssembly.compileStreaming() is unconditionally supported:
download_wasm = f"WebAssembly.compileStreaming(fetch('{target_basename}.wasm'))"
elif settings.MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION:
# Same compatibility story as above for
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming
if settings.MIN_SAFARI_VERSION != feature_matrix.UNSUPPORTED or settings.ENVIRONMENT_MAY_BE_NODE or settings.MIN_FIREFOX_VERSION < 58 or settings.MIN_CHROME_VERSION < 61:
if settings.MIN_SAFARI_VERSION < 150000 or settings.MIN_NODE_VERSION < 180100 or settings.MIN_FIREFOX_VERSION < 58 or settings.MIN_CHROME_VERSION < 61:
download_wasm = f"!WebAssembly.instantiateStreaming && binary('{target_basename}.wasm')"
else:
# WebAssembly.instantiateStreaming() is unconditionally supported, so we do not download wasm
Expand Down