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
Consider supporting emscripten/webassembly as a build target #84461
Comments
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, |
Do you want to provide a pull request? |
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 :
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. |
Hi pmp-p and Serhiy, I'd be more than happy to attempt a pull request, but I imagine a change A note regarding "supercharged full stack pyodide", potentially without With respect to blocking when running Python as WASM, I have found running Cheers, On Tue, 14 Apr 2020 at 18:58, pmp-p <report@bugs.python.org> wrote:
|
I've been maintaining a Python Emscripten build for the Ren'Py (game engine) web port: I recently tackled Python3 with a minimal/embeddable approach and checking the other ports already pointed in the discussion: There is also a Cython module to use the Emscripten C API. Here's a demo at: I can provide a pull request with a first few core changes. 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? |
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? |
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. |
Our config.sub is recent enough and has support for wasm32, wasm64, wasi, and emscripten: $ grep was[mi] config.sub
| wasm32 | wasm64 \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ |
LLVM considers |
My last message had a couple of typos; should have been |
Do we need to care about our |
To help keep links up-to-date, Pyodide now lives at: |
Our config.sub agrees with LLVM: $ ./config.sub wasm32-wasi
wasm32-unknown-wasi The config.sub and config.guess scripts in main are recent enough for wasm. Just to be sure I created #29781 and plan to backport the changeset to 3.10 and 3.9. It's generally safe to update the files to latest version. |
I have uploaded my config.site override to https://gist.github.com/tiran/5ccffa28723d3e4739db848451bd9efa . It contains overrides based on pyodide and overrides for new features. I'm also getting this error with emscripten 2.0.13. _sys_shutdown is the syscall for shutdown(2) used by the socket module. error: undefined symbol: __sys_shutdown (referenced by top-level compiled C/C++ code) |
Thanks a lot for working on this!
Yes, the issue with Emscripten is that a number of system calls are either not implemented or implemented but not tested. See a list we are using in https://github.com/pyodide/pyodide/blob/main/cpython/pyconfig.undefs.h (though things might have improved since it was created). FYI, with Emscripten, the list of CPython unit tests that are currently skipped (as of Python 3.9.5) is in https://github.com/pyodide/pyodide/blob/main/src/tests/python_tests.txt some of those are due to browser VM limitations (e.g. virtual filestem by Emscripten that's not fully POSIX compliant, no processes, no sockets, async only via the browser event loop etc), others because we are not yet using threading since not all browsers support it, and some failures probably need more investigation. Also opened pyodide/pyodide#2000 . Let us know if there is anything we can do help with this effort. |
Thanks Roman, I replied on the pyodide issue tracker. |
(cherry picked from commit c200757) Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Brett Cannon <brett@python.org>
Co-authored-by: Brett Cannon <brett@python.org> (cherry picked from commit 8ba1c7f) Co-authored-by: Christian Heimes <christian@python.org>
Subresource integrity hashes are is best practice when using pinned versions of packages, since we don't need to trust the CDN. (I don't mean to imply anything about unpkg in particular; in fact it currently seems quite trustworthy.)
Cross-builds do not need BUILDPYTHON to build extensions. They use an external build python interpreter. Emscripten browser builds had a circular on WASM_ASSETS -> pybuilddir.txt -> sysconfig_data -> python.js -> WASM_ASSETS.
``` Objects/stringlib/fastsearch.h:358:30: warning: comparison of integers of different signs: 'Py_ssize_t' (aka 'long') and 'unsigned int' [-Wsign-compare] Modules/socketmodule.c:1025:1: warning: unused function 'new_sockobject' [-Wunused-function] Modules/signalmodule.c:195:1: warning: unused function 'timeval_from_double' [-Wunused-function] Modules/_io/bufferedio.c:809:5: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical] emcc: warning: object file output extension (.so) used for non-object output. If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc] ```
Cross-builds do not need BUILDPYTHON to build extensions. They use an external build python interpreter. Emscripten browser builds had a circular on WASM_ASSETS -> pybuilddir.txt -> sysconfig_data -> python.js -> WASM_ASSETS.
(cherry picked from commit 084023ccbeb3bf54a2e19873c6a4b0bec7b617f6) Co-authored-by: Christian Heimes <christian@python.org>
wasm_assets script did not take the ABIFLAG flag of sysconfigdata into account.
wasm_assets script did not take the ABIFLAG flag of sysconfigdata into account.
wasm_assets script did not take the ABIFLAG flag of sysconfigdata into account. (cherry picked from commit 7a2cc35) Co-authored-by: Christian Heimes <christian@python.org>
- Emscripten's default umask is too strict, see emscripten-core/emscripten#17269 - getuid/getgid and geteuid/getegid are stubs that always return 0 (root). Disable effective uid/gid syscalls and fix tests that use chmod() current user. - Cannot drop X bit from directory.
- Emscripten's default umask is too strict, see emscripten-core/emscripten#17269 - getuid/getgid and geteuid/getegid are stubs that always return 0 (root). Disable effective uid/gid syscalls and fix tests that use chmod() current user. - Cannot drop X bit from directory.
…thonGH-94002) - Emscripten's default umask is too strict, see emscripten-core/emscripten#17269 - getuid/getgid and geteuid/getegid are stubs that always return 0 (root). Disable effective uid/gid syscalls and fix tests that use chmod() current user. - Cannot drop X bit from directory. (cherry picked from commit 2702e40) Co-authored-by: Christian Heimes <christian@python.org>
pythonGH-93992 removed geteuid() and enabled the test again on Emscripten.
…ythonGH-94007) pythonGH-93992 removed geteuid() and enabled the test again on Emscripten. (cherry picked from commit 62363bf) Co-authored-by: Christian Heimes <christian@python.org>
void
return typeNote: 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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: