Skip to content

Commit 66619bc

Browse files
authored
Fix for WASM_WORKERS + node + MINIMAL_RUNTIME (emscripten-core#24172)
1 parent ce1fdec commit 66619bc

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/lib/libwasm_worker.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
#if WASM_WORKERS == 2
3838
_wasmWorkerBlobUrl
3939
#elif MINIMAL_RUNTIME
40+
#if ENVIRONMENT_MAY_BE_NODE
41+
Module['$wb'] || './${WASM_WORKER_FILE}'
42+
#else
4043
Module['$wb']
44+
#endif
4145
#else
4246
locateFile('${WASM_WORKER_FILE}')
4347
#endif
@@ -195,7 +199,11 @@ if (ENVIRONMENT_IS_WASM_WORKER
195199
'$ww': _wasmWorkersID,
196200
#if MINIMAL_RUNTIME
197201
'wasm': Module['wasm'],
202+
#if ENVIRONMENT_MAY_BE_NODE
203+
'js': Module['js'] || './{{{ TARGET_JS_NAME }}}',
204+
#else
198205
'js': Module['js'],
206+
#endif
199207
'mem': wasmMemory,
200208
#else
201209
'wasm': wasmModule,

test/test_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9568,6 +9568,7 @@ def test_emscripten_async_load_script(self):
95689568

95699569
@node_pthreads
95709570
@no_asan('ASan does not support WASM_WORKERS')
9571+
@also_with_minimal_runtime
95719572
def test_wasm_worker_hello(self):
95729573
self.do_run_in_out_file_test('wasm_worker/hello_wasm_worker.c', emcc_args=['-sWASM_WORKERS'])
95739574

tools/minimal_runtime_shell.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def generate_minimal_runtime_load_statement(target_basename):
5151
download_wasm = f"binary('{target_basename}.wasm')"
5252

5353
# Main JS file always in first entry
54-
files_to_load = [f"script('{target_basename}.js')"]
54+
files_to_load = [f"script('{settings.TARGET_JS_NAME}')"]
5555

5656
# Download .wasm file
5757
if (settings.WASM == 1 and settings.WASM2JS == 0) or not download_wasm:
@@ -73,7 +73,7 @@ def generate_minimal_runtime_load_statement(target_basename):
7373
then_statements += ["%s.$wb = URL.createObjectURL(new Blob([r[%d]], { type: 'application/javascript' }));" % (settings.EXPORT_NAME, len(files_to_load))]
7474

7575
if download_wasm and settings.WASM_WORKERS == 1:
76-
files_to_load += [f"binary('{target_basename}.ww.js')"]
76+
files_to_load += [f"binary('{settings.WASM_WORKER_FILE}')"]
7777

7878
# Download Wasm2JS code if target browser does not support WebAssembly
7979
if settings.WASM == 2:
@@ -164,7 +164,7 @@ def generate_minimal_runtime_load_statement(target_basename):
164164
else:
165165
save_js = ''
166166

167-
files_to_load[0] = f"binary('{target_basename}.js')"
167+
files_to_load[0] = f"binary('{settings.TARGET_JS_NAME}')"
168168
if not settings.MODULARIZE:
169169
then_statements += ["var url = %sURL.createObjectURL(new Blob([r[0]], { type: 'application/javascript' }));" % save_js,
170170
script_load]
@@ -200,7 +200,7 @@ def generate_minimal_runtime_html(target, options, js_target, target_basename):
200200
if re.search(r'{{{\s*SCRIPT\s*}}}', shell):
201201
shared.exit_with_error('--shell-file "' + options.shell_path + '": MINIMAL_RUNTIME uses a different kind of HTML page shell file than the traditional runtime! Please see $EMSCRIPTEN/src/shell_minimal_runtime.html for a template to use as a basis.')
202202

203-
shell = shell.replace('{{{ TARGET_BASENAME }}}', target_basename)
203+
shell = shell.replace('{{{ TARGET_BASENAME }}}', settings.TARGET_BASENAME)
204204
shell = shell.replace('{{{ EXPORT_NAME }}}', settings.EXPORT_NAME)
205205
shell = shell.replace('{{{ TARGET_JS_NAME }}}', settings.TARGET_JS_NAME)
206206

0 commit comments

Comments
 (0)