Repository navigation
Consider supporting emscripten/webassembly as a build target #84461
Copy link
Copy link
Closed
Labels
3.11only security fixesonly security fixesOS-wasibuildThe build process and cross-buildThe build process and cross-buildtype-featureA feature request or enhancementA feature request or enhancement
Description
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']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixesOS-wasibuildThe build process and cross-buildThe build process and cross-buildtype-featureA feature request or enhancementA feature request or enhancement
Projects
- StatusShow more project fieldsDone
Activity
SimonBiggs commentedon Apr 14, 2020
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
serhiy-storchaka commentedon Apr 14, 2020
Do you want to provide a pull request?
pmp-p commentedon 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 commentedon Apr 14, 2020
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 <report@bugs.python.org> wrote:
Beuc commentedon 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 commentedon 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 commentedon 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-unknownwasm (WebAssembly) is "native instruction set" for the JavaScript VM while wasi or emscripten provide operating system facilities like memory management and I/O.
178 remaining items
pythongh-84461: Omit resource mod and getresuid funcs on Emscripten
gh-84461: Omit resource mod and getresuid funcs on Emscripten (GH-96303)
pythongh-84461: Omit resource mod and getresuid funcs on Emscripten (p…
gh-84461: Omit resource mod and getresuid funcs on Emscripten (GH-96303)
Revert "[3.11] pythongh-84461: Fix Emscripten umask and permission is…
pythongh-84461: Fix Emscripten umask and permission issues (pythonGH-…
[3.11] gh-108822: Backport libregrtest changes from the main branch (#…
index on testlogging-noasyncore: a36235d pythongh-84461: Omit resourc…
WIP on testlogging-noasyncore: a36235d pythongh-84461: Omit resource …
pythongh-84461: Include _emscripten_info in pythoninfo output (python…