Skip to content

Use mainScriptUrlOrBlob if present under EXPORT_ES6 #23890

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

Merged

Conversation

JoeOsborn
Copy link
Contributor

@JoeOsborn JoeOsborn commented Mar 11, 2025

Spun out from #23804 .

This is a fix for #23769 which was introduced by #23171 , where the use of the bundler pattern hard-coding a script name was made to apply to all ES6 exports.

mainScriptUrlOrBlob is necessary under es6 exports to support running a threaded emscripten module from another origin, e.g. to distribute an emscripten module on a CDN (the script will load for the main thread but won’t be allowed to create workers). Using blobs is an effective workaround.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 11, 2025

Can we add a test for this.

Otherwise lgtm.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 11, 2025

Can you mention that is a fix for a regression that was introduced #23171? (Assuming that is true?)

@sbc100
Copy link
Collaborator

sbc100 commented Mar 11, 2025

Could you also perhaps mention (in a comment) why/when this might be needed /used?

@JoeOsborn
Copy link
Contributor Author

Indeed this is a fix for #23769 which was introduced by #23171 , where the use of the bundler pattern hard-coding a script name was made to apply to all ES6 exports.

I’ll look into adding tests for vite and webpack.

@JoeOsborn
Copy link
Contributor Author

And it’s necessary to support running a threaded emscripten module from another origin, e.g. to distribute an emscripten module on a CDN (the script will load for the main thread but won’t be allowed to create workers). Using blobs instead allows a workaround.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 11, 2025

Can you put all those detail in the PR description?

In terms of testing I think it should be fine to just extend the existing testing we have for mainScriptUrlOrBlobin test_browser.py (test_load_js_from_blob_with_pthreads).

@sbc100
Copy link
Collaborator

sbc100 commented Mar 11, 2025

I created a PR to increase the testing we have for mainScriptUrlOrBlob: #23891

@JoeOsborn
Copy link
Contributor Author

Yes, cool! I am working on tests for pthread as blob and for webpack/vite, but I’m encountering something weird in my vite test. I want to instantiate the module twice (once with a string mainUrlOrBlob and once with a blob) within one test, but I’m getting two report_result outputs and the test harness doesn’t like it. Is there a way I can skip the generation of one or both of those report_result?exit=0 or expect to see two of them?

@JoeOsborn
Copy link
Contributor Author

As a quick update, I’m pretty sure I can revise this PR with tests tomorrow. There are some issues with the paths used by the web server giving 404s under some conditions but not others, but I’m confident I can resolve these.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 12, 2025

Instead of creating a new browser test can you just update the new test_mainScriptUrlOrBlob in test_other.py ? I think it will make testing much simpler.

else:
copytree(test_file('webpack'), '.')
outfile = 'src/hello.js'
self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web,worker', '-o', outfile])
self.run_process(shared.get_npm_cmd('webpack') + ['--mode=development', '--no-devtool'])
shutil.copy(outfile, 'dist/')
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the idea is that the bundler should do this.. so you should not have to do this here. In fact, if you have to do this that would seem like a bug maybe? (Same with the .wasm file below I guess).

In any case, I think this bundler stuff is orthogonal the this change which I think we can test without modifying any bundler tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, this one wasn't meant to be included here.

@JoeOsborn JoeOsborn force-pushed the support-mainthreadurlorblob-es6modules branch from f620b51 to 7616b71 Compare March 12, 2025 17:23
@JoeOsborn
Copy link
Contributor Author

Sorry my commits got messy there, I accidentally ran a commit -a without noticing.

@JoeOsborn
Copy link
Contributor Author

Instead of creating a new browser test can you just update the new test_mainScriptUrlOrBlob in test_other.py ? I think it will make testing much simpler.

I ended up modifying a different existing browser test specifically about pthread blob support.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 12, 2025

Instead of creating a new browser test can you just update the new test_mainScriptUrlOrBlob in test_other.py ? I think it will make testing much simpler.

I ended up modifying a different existing browser test specifically about pthread blob support.

BTW, test_mainScriptUrlOrBlob is also specifically about pthread blob support, but it doesn't need the browser to run. I think it should certainly be updated as part of this PR.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for doing that.

Can you update the test in test_other too with an es6 module variant?

Otherwise lgtm!

@JoeOsborn
Copy link
Contributor Author

Will do! It will only be for URLs though, not for blobs, since Node doesn’t seem to support blobs.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 12, 2025

Will do! It will only be for URLs though, not for blobs, since Node doesn’t seem to support blobs.

Yes, the existing test in other just does Module = { mainScriptUrlOrBlob: "./foo.js" }. I don't think we need to change that. Just run it in ES6 mode.

@JoeOsborn JoeOsborn force-pushed the support-mainthreadurlorblob-es6modules branch from ec7aad1 to 47c54b5 Compare March 12, 2025 21:45
auto-merge was automatically disabled March 14, 2025 18:22

Head branch was pushed to by a user without write access

@JoeOsborn JoeOsborn force-pushed the support-mainthreadurlorblob-es6modules branch from ce68912 to 472313d Compare March 14, 2025 18:22
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Oops, looks like you accidentally included an update to test/third_party/googletest. A assume that was not deliberate?

@JoeOsborn
Copy link
Contributor Author

Ah sorry, yeah that was something that bootstrap or some other script updated as far as I can tell. Do you need me to revert that and push another commit or will you handle it during merge?

@sbc100
Copy link
Collaborator

sbc100 commented Mar 14, 2025

Yup, can you revert and push again.

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