Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jamsinclair
Copy link

@jamsinclair jamsinclair commented Nov 2, 2024

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.

@@ -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)
Copy link
Author

@jamsinclair jamsinclair Nov 2, 2024

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? 🤔

Copy link
Author

@jamsinclair jamsinclair Nov 4, 2024

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 }}});
Copy link
Collaborator

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;
}}}

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants