GeezerVison is showing github.com — Consider supporting emscripten/webassembly as a build target · Issue #84461 · python/cpython
Consider supporting emscripten/webassembly as a build target #84461Description
| BPO |
40280 |
| Nosy |
@warsaw, @brettcannon, @terryjreedy, @tiran, @mcepl, @pmp-p, @rdb, @ethanhs, @corona10, @miss-islington, @tirkarthi, @erlend-aasland |
| PRs |
bpo-40280: Add wasm cross build targets (GH-29771) #29771bpo-40280: Use Setup.stdlib static for wasm builds (GH-29784) #29784bpo-40280: Move hard-coded feature checks to configure (GH-29789) #29789bpo-40280: clean and ignore .wasm files (GH-29794) #29794bpo-40280: Add configure check for socket shutdown (GH-29795) #29795bpo-40280: Disable unusable core extension modules on emscripten (GH-29834) #29834bpo-40280: Emscripten systems use .wasm suffix by default (GH-29842) #29842bpo-40280: Emscripten has no support for subprocesses #29872bpo-40280: Emscripten defaults to --with-ensurepip=no (GH-29873) #29873bpo-40280: Emscripten with_ensurepip=no, second attempt (GH-29884) #29884bpo-40280: Optimize ints and and startup on wasm (GH-29887) #29887bpo-40280: Enable assertions in Emscripten debug builds #29892bpo-40280: Update what's new (GH-29893) #29893bpo-40280: Add Tools/wasm with helpers for cross building (GH-29984) #29984bpo-40280: Disable epoll_create in Emscripten config.site (GH-30494) #30494bpo-40280: Add build target for Emscripten/node.js #30495bpo-40280: Skip IPPROTO_SCTP tests on Emscripten #30538bpo-40280: Add --with-emscripten-target to build for browser or node (GH-30552) #30552bpo-40280: Allow to compile _testcapi as builtin module (GH-30559) #30559bpo-40280: Build WASM stdlib bundle and more modules for node (GH-30597) #30597bpo-40280: Block more syscalls that are causing crashes in tests (GH-30601) #30601bpo-40280: Skip subprocess-based tests on wasm32-emscripten (GH-30615) #30615bpo-40280: Change subprocess imports for cleaner error on wasm32 (GH-30620) #30620bpo-40280: Add requires_fork test helper (GH-30622) #30622bpo-40280: Misc fixes for wasm32-emscripten (GH-30722) #30722bpo-40280: Get help() working and more (GH-30858) #30858bpo-40280: Use presence of msvcrt module to detect Windows #30930bpo-40280: Address more test failures on Emscripten (GH-31050) #31050bpo-40280: Block more non-working syscalls in Emscripten (GH-31757) #31757bpo-40280: Skip dysfunctional pipe tests on Emscripten (GH-31770) #31770bpo-40280: Skip more tests/features that don't apply to Emscripten (GH-31791) #31791bpo-40280: Disable AF_UNIX, AF_PACKET, SO_REUSE* on Emscripten #31829bpo-40280: select: Use NULL for empty fdset (GH-31865) #31865bpo-40280: Detect presence of time.tzset and thread_time clock (GH-31898) #31898bpo-40280: Skip wakeup_fd pipe tests on Emscripten (GH-31909) #31909bpo-40280: Skip more tests on Emscripten (GH-31947) #31947bpo-40280: Skip socket, fork, subprocess tests on Emscripten #31986bpo-40280: Add wasm32-emscripten and wasm32-wasi SOABI #32095bpo-40280: Emscripten fork_exec now fails early (GH-32224) #32224bpo-40280: Add debug Emscripten flavors (GH-32233) #32233bpo-40280: Enable most file-at() and nanosleep APIs again (GH-32238) #32238bpo-40280: Detect if WASM platform supports threading #32243bpo-40280: Add --enable-wasm-dynamic-linking (GH-32253) #32253bpo-46315: Use fopencookie only on Emscripten 3.x and newer (GH-32266) #32266bpo-40280: Add limited Emscripten REPL (GH-32284) #32284bpo-40280: Detect missing threading on WASM platforms (GH-32352) #32352bpo-40280: WASM defaults to no dynamic linking (GH-32360) #32360bpo-40280: WASM docs and smaller browser builds (GH-32412) #32412 |
| Dependencies |
bpo-23325: Turn SIG_DFL and SIG_IGN into functionsbpo-33393: update config.guess and config.subbpo-41498: Undefinied _Py_Sigset_Converter function when HAVE_SIGSET_T not setbpo-45881: Cross compiling on Linux is untested, undocumented, and brokenbpo-45886: Fix Program/freeze_module for cross compiling Pythonbpo-45898: ctypes cfield.c defines duplicate ffi_type* symbolsbpo-46383: _zoneinfo module_free has invalid function signaturebpo-46390: Multiple test failures on Alpine 3.15 / musl-1.2.2-r7bpo-46408: signal module wrongly relies on small int singletonsbpo-47162: Add call trampoline to work around bad fpcasts on Emscriptenbpo-47176: Interrupt handling for wasm32-emscripten builds without pthreadsbpo-47196: Function pointer cast in test_impbpo-47197: ctypes mishandles void return type |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = None
created_at = <Date 2020-04-14.07:11:35.905>
labels = ['type-feature', 'build', '3.11']
title = 'Consider supporting emscripten/webassembly as a build target'
updated_at = <Date 2022-04-08.10:17:32.793>
user = 'https://bugs.python.org/SimonBiggs'
bugs.python.org fields:
activity = <Date 2022-04-08.10:17:32.793>
actor = 'christian.heimes'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Build']
creation = <Date 2020-04-14.07:11:35.905>
creator = 'Simon Biggs'
dependencies = ['23325', '33393', '41498', '45881', '45886', '45898', '46383', '46390', '46408', '47162', '47176', '47196', '47197']
files = []
hgrepos = []
issue_num = 40280
keywords = ['patch']
message_count = 65.0
messages = ['366369', '366374', '366375', '366379', '369598', '394081', '406985', '406986', '407011', '407012', '407013', '407014', '407015', '407018', '407020', '407021', '407030', '407046', '407048', '407049', '407052', '407080', '407264', '407284', '407484', '407498', '407519', '407524', '407541', '408855', '410138', '410400', '410423', '410554', '410577', '410647', '410727', '410743', '411039', '411514', '411560', '411847', '412595', '414748', '414769', '414780', '414845', '414940', '415136', '415259', '415297', '415398', '415757', '415976', '416494', '416509', '416541', '416542', '416579', '416681', '416763', '416865', '416916', '416933', '416934']
nosy_count = 14.0
nosy_names = ['barry', 'brett.cannon', 'terry.reedy', 'christian.heimes', 'mcepl', 'pmpp', 'rdb', 'ethan smith', 'corona10', 'miss-islington', 'Roman Yurchak', 'xtreak', 'erlendaasland', 'Simon Biggs']
pr_nums = ['29771', '29784', '29789', '29794', '29795', '29834', '29842', '29872', '29873', '29884', '29887', '29892', '29893', '29984', '30494', '30495', '30538', '30552', '30559', '30597', '30601', '30615', '30620', '30622', '30722', '30858', '30930', '31050', '31757', '31770', '31791', '31829', '31865', '31898', '31909', '31947', '31986', '32095', '32224', '32233', '32238', '32243', '32253', '32266', '32284', '32352', '32360', '32412']
priority = 'normal'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue40280'
versions = ['Python 3.11']
Reacted by Felipe S. S. Schneider and Yisi Reacted by Felipe S. S. Schneider and Rui Lopes Reacted by Felipe S. S. Schneider Reacted by Felipe S. S. Schneider Reacted by Felipe S. S. Schneider ActivitySimonBiggs commented on Apr 14, 2020 MannequinAuthor More actions Since asm.js came on the scene, and now Web Assembly people have created CPython patches to support building CPython with emscripten. See:
To ease the compiling of CPython with emscripten it would be helpful if patches that achieved these ends for the compiling to Web Assembly with emscripten were built into the upstream source repository itself.
If web assembly were to became a supported compilation target of the upstream CPython repository this would significantly reduce the friction of allowing CPython, and the latest CPython, to become a language readily usable within the browser.
Cheers,
Simon Reacted by Marcel Guinhos and Felipe S. S. Schneider serhiy-storchaka commented on Apr 14, 2020 Do you want to provide a pull request? pmp-p commented on Apr 14, 2020 you can add
(wasm not asm.js, clang-10+ required)
demo https://pmp-p.github.io/python-next/test.html
CPython can already run in the browser with very little patching, but major issues are :
-
asyncify'ing the whole wasm VM to have pre-emption over cPython's one to prevent blocking I/O slows down things *a lot* (10x)
=> (very?) bad user experience.
-
the size of vm + stdlib ~ 30 MiB and wasm compilation time.
=> bad user experience on first load or slow connexion.
-
the lack of threading in wasm MinimumViableProduct specification (but this is the browser standard for now), that leads to rewrite bits of stdlib ( like eg asyncio module )
=> adding more maintenance burden on stdlib (!)
i tested them all and my personnal opinion is : I can see no use case that would favour "stock" cPython wasm versus a blazing fast MicroPytho (or pycopy) wasm flavour or supercharged full stack pyodide. SimonBiggs commented on Apr 14, 2020 MannequinAuthor More actions Hi pmp-p and Serhiy,
I'd be more than happy to attempt a pull request, but I imagine a change
such as this needs to be discussed first, trying not to "rush to make a
patch" (https://www.youtube.com/watch?v=voXVTjwnn-U&feature=youtu.be&t=2546).
Also, I doubt I will do a good job of it... but I am more than happy to try.
A note regarding "supercharged full stack pyodide", potentially without
efforts such as upstreaming into CPython and emscripten the relevant
patches, that supercharged full stack may just unfortunately stagnate. See
pyodide/pyodide#635 (comment)
With respect to blocking when running Python as WASM, I have found running
the WebAssembly CPython within a webworker and signalling data back and
forth causes there to be no UI issues. It ends up being quite a neat set
up. Main down side right now however is the set up is currently going
stale, hence me believing reaching out like this is in the best interests
of Python going forward.
Cheers,
Simon
On Tue, 14 Apr 2020 at 18:58, pmp-p <[email protected]> wrote:
pmp-p <[email protected]> added the comment:
you can add
*
https://github.com/pmp-p/pydk/tree/master/sources.em/Python-3.8.0b4.patchset
-- Python 3.8.x
(wasm not asm.js, clang-10+ required)
demo https://pmp-p.github.io/python-next/test.html
CPython can already run in the browser with very little patching, but
major issues are :
-
asyncify'ing the whole wasm VM to have pre-emption over cPython's one
to prevent blocking I/O slows down things *a lot* (10x)
=> (very?) bad user experience.
-
the size of vm + stdlib ~ 30 MiB and wasm compilation time.
=> bad user experience on first load or slow connexion.
-
the lack of threading in wasm MinimumViableProduct specification (but
this is the browser standard for now), that leads to rewrite bits of stdlib
( like eg asyncio module )
=> adding more maintenance burden on stdlib (!)
i tested them all and my personnal opinion is : I can see no use case that
would favour "stock" cPython wasm versus a blazing fast MicroPytho (or
pycopy) wasm flavour or supercharged full stack pyodide.
----------
nosy: +pmpp
Python tracker <[email protected]>
<https://bugs.python.org/issue40280\>
Beuc commented on May 22, 2020 I've been maintaining a Python Emscripten build for the Ren'Py (game engine) web port:
https://github.com/python-emscripten/python
https://renpy.beuc.net/
I recently tackled Python3 with a minimal/embeddable approach and checking the other ports already pointed in the discussion:
https://github.com/python-emscripten/python/tree/trunk/3.8/
(2 patches, and a short pyconfig.h fix-up)
There is also a Cython module to use the Emscripten C API.
Here's a demo at:
https://www.beuc.net/python-emscripten/demo/3/
(hello-world size: 3MB, with a few common modules: 4MB)
I can provide a pull request with a first few core changes.
Should this be done on github?
cross-compilation handling appears to follow an incorrect logic, in particular by querying 'dpkg' or parsing compiler output to detect include paths -- it is the (cross-)compiler's responsibility to provide the system paths, and detecting them manually causes conflicts. I had to patch setup.py. Let me know if I missed something.
Usually cross-compiling is triggered by non-matching build-type/host-type. Here cross-compilation logic is apparently triggered when exporting _PYTHON_HOST_PLATFORM=xxx manually (it's in the Makefile but not exported, and breaks normal build when exported). Is this the way it's meant to be used? ethanhs commented on May 20, 2021 I think the first thing we should do is figure out whether we want to support Emscripten or WASI (or both).
Emscripten uses Javascript polyfills for some syscalls, while WASI makes direct calls the VM it is running in. They both can use WebAssembly for executing the code. This means Emscripten has wider API support, but WASI is lighter weight in many ways.
I think starting with patches to support Emscripten would be best, as it is easier to target, then add support for WASI later.
I think supporting WASI has a lot of value, because it can be run deterministically, which would be great for data science (Imagine a jupyter notebook that runs the same everywhere!)
One issue with WASI, and may be an issue with Emscripten, is threads. In 3.8 (or 3.9?) threadless builds were removed. However, WebAssembly's threading API is not really meant to emulate pthread, and SharedArrayBuffer, the primitive it is built on, is disabled in several browsers due to Spectre concerns.
Would patches to re-add a threadless build mode be accepted? tiran commented on Nov 25, 2021 I have added wasm32/wasm64 architectures with emscripten/wasi operating system as cross-build targets. The values are based on Rust targets:
$ rustc --print target-list | grep wasm
wasm32-unknown-emscripten
wasm32-unknown-unknown
wasm32-wasi
wasm64-unknown-unknown
wasm (WebAssembly) is "native instruction set" for the JavaScript VM while wasi or emscripten provide operating system facilities like memory management and I/O.
MetadataMetadataStatusShow more project fields
DevelopmentNo branches or pull requestsIssue actions
|