-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-127111: Emscripten Make web example work again #127113
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
Conversation
215c295
to
525223d
Compare
525223d
to
715455e
Compare
I moved the web example from `Tools/wasm` into `Tools/wasm/emscripten/web_example`. I also added a new target `build_emscripten` which is `build_wasm` but also builds the web_example. The web_example needs: 1. python.html, copied 2. python.worker.mjs copied 3. python.mjs and python.wasm output from the main linking of the Python interpreter 4. The webserver that sets COOP and COEP 5. python3.14.zip This last is created by the `wasm_assets.py` script, which required a pretty small set of changes to work fine for us. The last thing that should be done is the `python.worker.mjs` script should be made independent of the Python version: currently 3.14 is hard coded. I ran into trouble doing this, so maybe I can leave it to a followup.
715455e
to
bbb2ab9
Compare
The Emscripten seems to work fine, however when viewing the web_example (using the provided server.py), I still get a CORS error:
# Shell
(base) jglass@jglass-XPS-8930:~/Documents/cpython$ python Tools/wasm/emscripten/web_example/server.py
Serving HTTP on 127.0.0.1 port 8000 (http://127.0.0.1:8000/) ...
127.0.0.1 - - [26/Nov/2024 07:28:13] "GET /Tools/wasm/emscripten/web_example/python.html HTTP/1.1" 200 -
127.0.0.1 - - [26/Nov/2024 07:28:15] "GET /Tools/wasm/emscripten/web_example/python.worker.mjs HTTP/1.1" 200 -
127.0.0.1 - - [26/Nov/2024 07:28:15] code 404, message File not found
127.0.0.1 - - [26/Nov/2024 07:28:15] "GET /Tools/wasm/emscripten/web_example/python.mjs HTTP/1.1" 404 -
127.0.0.1 - - [26/Nov/2024 07:28:17] code 404, message File not found
127.0.0.1 - - [26/Nov/2024 07:28:17] "GET /mini-coi.js HTTP/1.1" 404 - |
Thanks for testing it @JeffersGlass. Maybe I'll have to try a different CDN. It worked fine for me though... |
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.
The general shape of this makes sense.
From a general process perspective, this needs a news entry to describe that that web example has been updated, and documentation in the WASM README on how to run the example.
However, assuming the usage instructions are python Tools/wasm/emscripten build
and open web_example/python.html
- I get 2 errors.
First, during the build process, the macOS version of realpath
apparently doesn't honor the -s
flag, so the usage on L223 of the Tools/emscripten/__main__.py
raises an error and python Tools/wasm/emscripten build
doesn't complete.
Second, I wasn't able to see the example working in practice. When I open file:///.../web_example/python.html
in Chrome, I get the following error:
python.html:50 Uncaught (in promise) SecurityError: Failed to construct 'Worker': Script at 'file:///Users/rkm/projects/python/cpython/cross-build/wasm32-emscripten/web_example/python.worker.mjs' cannot be accessed from origin 'null'.
at WorkerManager.initialiseWorker (python.html:50:27)
at new WorkerManager (python.html:45:14)
at window.onload (python.html:350:33)
If I use python -m http.server
to serve the web_example
folder, and open python.html, I get:
Uncaught ReferenceError: SharedArrayBuffer is not defined
at new StdinBuffer (python.worker.mjs:5:24)
at python.worker.mjs:62:21
EDIT: Strike that - I see from @JeffersGlass comment that python web_example/server.py
is the expected operation; that works for me. That only leaves the issue with realpath
failing during the build (that's a problem that I didn't pick up with my review of #126903, but we can fix it here)
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Apple's crappy gnu coreutils strike again. |
@JeffersGlass This isn't a CORS error, you're serving it out of the source directory whereas you need to serve it out of the output directory: ./cross-build/wasm32-emscripten/web_example/server.py |
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.
A couple of documentation tweaks; I'm still having issues with realpath as well. Not sure if I'm doing something wrong, though.
Thanks for the review @freakboy3742! I continue to appreciate your detailed PR feedback. I've been enjoying working with you so far on this. |
Apply shell check fixes don't disparage BSD coreutils fix indentation realpath not readlink
@freakboy3742 I reverted changes to |
Thanks for making the requested changes! @freakboy3742: please review the changes made to this pull request. |
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.
This obviously needs the changes from #127506 to be fully usable on macOS; but I'm happy with this as a set of changes in itself.
Moves the Emscripten web example into a standalone folder, and updates Makefile targets to build the web example. Instructions for usage have also been added.
Moves the Emscripten web example into a standalone folder, and updates Makefile targets to build the web example. Instructions for usage have also been added.
I moved the web example from
Tools/wasm
intoTools/wasm/emscripten/web_example
. I also added a new targetbuild_emscripten
which isbuild_wasm
but also builds the web_example. The web_example needs:This last is created by the
wasm_assets.py
script, which required a pretty small set of changes to work fine for us.The last thing that should be done is the
python.worker.mjs
script should be made independent of the Python version: currently 3.14 is hard coded. I ran into trouble doing this, so maybe I can leave it to a followup.