-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Fix pthread worker options usage with Vite bundler #22834
base: main
Are you sure you want to change the base?
Fix pthread worker options usage with Vite bundler #22834
Conversation
@@ -2098,6 +2098,9 @@ def phase_final_emitting(options, state, target, wasm_target): | |||
|
|||
target_dir = os.path.dirname(os.path.abspath(target)) | |||
|
|||
if settings.PTHREADS: | |||
replace_worker_options_placeholders(final_js) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on test failures, is there an earlier location where we should be replacing these values? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After further reflection on how these files fit together, it seems some kind of internal setting could be a more appropriate way to configure this?
Could it be as simple as adding it to settings_internal.js and configure settings.PTHREAD_WORKER_OPTIONS
in link.py
?
@@ -426,14 +407,14 @@ var LibraryPThread = { | |||
createScriptURL: (ignored) => new URL("{{{ TARGET_JS_NAME }}}", import.meta.url) | |||
} | |||
); | |||
worker = new Worker(p.createScriptURL('ignored'), workerOptions); | |||
worker = new Worker(p.createScriptURL('ignored'), {{{ WORKER_OPTIONS }}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simpler way to do this would be to define a new macro here at the top of this file. e.g.
{{{
globalThis.WORKER_OPTIONS = {
...
};
null;
}}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much! I wasn't too sure how the templating works in these files 😅 . I'll update the PR with this approach when I get a chance.
Overview
An attempt at solving #22394.
When code using threads is compiled with Emscripten and then bundled with Vite it does not bundle and throws an error.
This is due to a variable reference for worker options being used during worker construction. For vite to bundle workers it needs static references.
As discussed in the issue, the easiest solution would be to switch to using an object literal for each worker construction.