From cf7b7fe991c29d1b65b226b5d6412acf7583fe05 Mon Sep 17 00:00:00 2001 From: adam j hartz Date: Mon, 21 Jul 2025 05:56:45 -0400 Subject: [PATCH] gh-136251: Improvements to WASM demo REPL (GH-136252) (cherry picked from commit d1d526afe7ce62c787b150652a2ba136cb949d74) Co-authored-by: adam j hartz Co-authored-by: Hood Chatham --- Makefile.pre.in | 4 +- ...-07-05-15-10-42.gh-issue-136251.GRM6o8.rst | 1 + Python/emscripten_syscalls.c | 2 +- Tools/wasm/README.md | 10 +- .../web_example/{python.html => index.html} | 362 +++++++++++++++--- configure | 2 +- configure.ac | 2 +- 7 files changed, 327 insertions(+), 56 deletions(-) create mode 100644 Misc/NEWS.d/next/Tools-Demos/2025-07-05-15-10-42.gh-issue-136251.GRM6o8.rst rename Tools/wasm/emscripten/web_example/{python.html => index.html} (52%) diff --git a/Makefile.pre.in b/Makefile.pre.in index 66b34b779f27cb..fae5e384d3245f 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1096,7 +1096,7 @@ $(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS) # wasm32-emscripten browser web example WEBEX_DIR=$(srcdir)/Tools/wasm/emscripten/web_example/ -web_example/python.html: $(WEBEX_DIR)/python.html +web_example/index.html: $(WEBEX_DIR)/index.html @mkdir -p web_example @cp $< $@ @@ -1124,7 +1124,7 @@ web_example/python.mjs web_example/python.wasm: $(BUILDPYTHON) cp python.wasm web_example/python.wasm .PHONY: web_example -web_example: web_example/python.mjs web_example/python.worker.mjs web_example/python.html web_example/server.py $(WEB_STDLIB) +web_example: web_example/python.mjs web_example/python.worker.mjs web_example/index.html web_example/server.py $(WEB_STDLIB) ############################################################################ # Header files diff --git a/Misc/NEWS.d/next/Tools-Demos/2025-07-05-15-10-42.gh-issue-136251.GRM6o8.rst b/Misc/NEWS.d/next/Tools-Demos/2025-07-05-15-10-42.gh-issue-136251.GRM6o8.rst new file mode 100644 index 00000000000000..6a35afe15e3875 --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2025-07-05-15-10-42.gh-issue-136251.GRM6o8.rst @@ -0,0 +1 @@ +Fixes and usability improvements for ``Tools/wasm/emscripten/web_example`` diff --git a/Python/emscripten_syscalls.c b/Python/emscripten_syscalls.c index 886262acbc6810..d3eedad30e3639 100644 --- a/Python/emscripten_syscalls.c +++ b/Python/emscripten_syscalls.c @@ -100,7 +100,7 @@ EM_JS_MACROS(void, _emscripten_promising_main_js, (void), { return; } const origResolveGlobalSymbol = resolveGlobalSymbol; - if (!Module.onExit && process?.exit) { + if (!Module.onExit && globalThis?.process?.exit) { Module.onExit = (code) => process.exit(code); } // * wrap the main symbol with WebAssembly.promising, diff --git a/Tools/wasm/README.md b/Tools/wasm/README.md index 232321c515721e..9288598a0abc29 100644 --- a/Tools/wasm/README.md +++ b/Tools/wasm/README.md @@ -22,7 +22,7 @@ https://github.com/psf/webassembly for more information. ### Build To cross compile to the ``wasm32-emscripten`` platform you need -[the Emscripten compiler toolchain](https://emscripten.org/), +[the Emscripten compiler toolchain](https://emscripten.org/), a Python interpreter, and an installation of Node version 18 or newer. Emscripten version 4.0.2 is recommended; newer versions may also work, but all official testing is performed with that version. All commands below are relative @@ -86,11 +86,11 @@ CLI you will need to write your own alternative to `node_entry.mjs`. ### The Web Example -When building for Emscripten, the web example will be built automatically. It is -in the ``web_example`` directory. To run the web example, ``cd`` into the +When building for Emscripten, the web example will be built automatically. It +is in the ``web_example`` directory. To run the web example, ``cd`` into the ``web_example`` directory, then run ``python server.py``. This will start a web -server; you can then visit ``http://localhost:8000/python.html`` in a browser to -see a simple REPL example. +server; you can then visit ``http://localhost:8000/`` in a browser to see a +simple REPL example. The web example relies on a bug fix in Emscripten version 3.1.73 so if you build with earlier versions of Emscripten it may not work. The web example uses diff --git a/Tools/wasm/emscripten/web_example/python.html b/Tools/wasm/emscripten/web_example/index.html similarity index 52% rename from Tools/wasm/emscripten/web_example/python.html rename to Tools/wasm/emscripten/web_example/index.html index 078f86eb764419..9c89c9c0ed3bf5 100644 --- a/Tools/wasm/emscripten/web_example/python.html +++ b/Tools/wasm/emscripten/web_example/index.html @@ -1,31 +1,39 @@ - - - - - + + + + + wasm-python terminal + >