Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
freakboy3742 merged 11 commits intopython:mainfromhoodmane:web-example
Dec 2, 2024

Conversation

@hoodmane
Copy link
Contributor

@hoodmanehoodmane commentedNov 21, 2024
edited by bedevere-appbot
Loading

I moved the web example fromTools/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:

  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 thewasm_assets.py script, which required a pretty small set of changes to work fine for us.

The last thing that should be done is thepython.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.

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 alsobuilds the web_example. The web_example needs:1. python.html, copied2. python.worker.mjs copied3. python.mjs and python.wasm output from the main linking of the Python interpreter4. The webserver that sets COOP and COEP5. python3.14.zipThis last is created by the `wasm_assets.py` script, which required a prettysmall set of changes to work fine for us.The last thing that should be done is the `python.worker.mjs` script should bemade independent of the Python version: currently 3.14 is hard coded. I raninto trouble doing this, so maybe I can leave it to a followup.
@JeffersGlass
Copy link
Contributor

The Emscripten seems to work fine, however when viewing the web_example (using the provided server.py), I still get a CORS error:

// ConsoleThe FetchEvent for "https://unpkg.com/xterm@4.18.0/css/xterm.css" resulted in a network error response: Cross-Origin-Resource-Policy prevented from serving the response to the client.
# 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 found127.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 found127.0.0.1 - - [26/Nov/2024 07:28:17]"GET /mini-coi.js HTTP/1.1" 404 -

@hoodmane
Copy link
ContributorAuthor

Thanks for testing it@JeffersGlass. Maybe I'll have to try a different CDN. It worked fine for me though...

Copy link
Contributor

@freakboy3742freakboy3742 left a comment
edited
Loading

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 arepython Tools/wasm/emscripten build and openweb_example/python.html - I get 2 errors.

First, during the build process, the macOS version ofrealpath apparently doesn't honor the-s flag, so the usage on L223 of theTools/emscripten/__main__.py raises an error andpython Tools/wasm/emscripten build doesn't complete.

Second, I wasn't able to see the example working in practice. When I openfile:///.../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 usepython -m http.server to serve theweb_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 thatpython web_example/server.py is the expected operation; that works for me. That only leaves the issue withrealpath 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)

@bedevere-app
Copy link

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 phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@hoodmane
Copy link
ContributorAuthor

hoodmane commentedNov 29, 2024
edited
Loading

the macOS version of realpath apparently doesn't honor the -s flag

Apple's crappy gnu coreutils strike again.

@hoodmane
Copy link
ContributorAuthor

The Emscripten seems to work fine, however when viewing the web_example (using the provided server.py), I still get a CORS error:

@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

Copy link
Contributor

@freakboy3742freakboy3742 left a 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.

@hoodmane
Copy link
ContributorAuthor

Thanks for the review@freakboy3742! I continue to appreciate your detailed PR feedback. I've been enjoying working with you so far on this.

@hoodmane
Copy link
ContributorAuthor

@freakboy3742 I reverted changes to__main__.py and moved them over to#127506.
I have made the requested changes; please review again (at least I think I made them...)

@bedevere-app
Copy link

Thanks for making the requested changes!

@freakboy3742: please review the changes made to this pull request.

@erlend-aaslanderlend-aasland removed their request for reviewDecember 2, 2024 21:44
Copy link
Contributor

@freakboy3742freakboy3742 left a 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.

@freakboy3742freakboy3742 merged commitbfb0788 intopython:mainDec 2, 2024
54 of 57 checks passed
@hoodmanehoodmane deleted the web-example branchDecember 6, 2024 08:49
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull requestJan 8, 2025
Moves the Emscripten web example into a standalone folder, and updates Makefile targets to build the web example. Instructions for usage havealso been added.
ebonnal pushed a commit to ebonnal/cpython that referenced this pull requestJan 12, 2025
Moves the Emscripten web example into a standalone folder, and updates Makefile targets to build the web example. Instructions for usage havealso been added.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@freakboy3742freakboy3742freakboy3742 approved these changes

@corona10corona10Awaiting requested review from corona10corona10 is a code owner

Assignees

No one assigned

Labels

buildThe build process and cross-buildOS-emscripten

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@hoodmane@JeffersGlass@freakboy3742

[8]ページ先頭

©2009-2025 Movatter.jp