Skip to content
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
13 changes: 11 additions & 2 deletions src/postamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ var imports = {
};

#if MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION
{{{
#if EXPORT_ES6 && !ENVIRONMENT_MAY_BE_AUDIO_WORKLET
const moduleUrl = `new URL('${TARGET_BASENAME}.wasm', import.meta.url)`;
#elif !EXPORT_ES6 || AUDIO_WORKLET
const moduleUrl = `'${TARGET_BASENAME}.wasm'`;
#else
const moduleUrl = `ENVIRONMENT_IS_AUDIO_WORKLET ? '${TARGET_BASENAME}.wasm' : new URL('${TARGET_BASENAME}.wasm', import.meta.url)`;
#endif
}}}
// https://caniuse.com/#feat=wasm and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming
#if MIN_SAFARI_VERSION < 150000 || ENVIRONMENT_MAY_BE_NODE
#if ASSERTIONS && !WASM2JS
Expand All @@ -197,13 +206,13 @@ instantiatePromise =
// Node's fetch API cannot be used for local files, so we cannot use instantiateStreaming
&& !ENVIRONMENT_IS_NODE
#endif
? WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports)
? WebAssembly.instantiateStreaming(fetch({{{ moduleUrl }}}), imports)
: WebAssembly.instantiate(Module['wasm'], imports)).then((output) => {
#else
#if AUDIO_WORKLET
instantiatePromise =
#endif
WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports).then((output) => {
WebAssembly.instantiateStreaming(fetch({{{ moduleUrl }}}), imports).then((output) => {
#endif

#else // Non-streaming instantiation
Expand Down
8 changes: 6 additions & 2 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5557,9 +5557,13 @@ def test_webpack(self, args):

@also_with_threads
@requires_dev_dependency('vite')
def test_vite(self):
@parameterized({
'': ([],),
'minimal': (['-sMINIMAL_RUNTIME', '-sMINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION'],),
})
def test_vite(self, args):
copytree(test_file('vite'), '.')
self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sENVIRONMENT=web', '-o', 'hello.mjs'])
self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sENVIRONMENT=web', '-o', 'hello.mjs'] + args)
self.run_process(shared.get_npm_cmd('vite') + ['build'])
self.run_browser('dist/index.html', '/report_result?exit:0')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding a new test here you should be able to using @parameterize.

Something like:

  @parameterized({                                                                                        
    '': ([],),                                                                                                                          
    'minimal': (['-sMINIMAL_RUNTIME', '-sMINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION'],),                                        
  })  
  def test_vite_minimal_runtime(self, args):

(then add args to the compile_btest arguments).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.


Expand Down