diff options
author | Christian Heimes <christian@python.org> | 2022-02-05 19:52:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-05 19:52:01 (GMT) |
commit | 96b344c2f15cb09251018f57f19643fe20637392 (patch) | |
tree | 3fe6c8f5d1a2897881806db1f3b441d11114adeb /Tools/wasm | |
parent | 9d4161a60ca8b470148ffd6c73e3110a0aa6d66f (diff) | |
download | cpython-96b344c2f15cb09251018f57f19643fe20637392.zip cpython-96b344c2f15cb09251018f57f19643fe20637392.tar.gz cpython-96b344c2f15cb09251018f57f19643fe20637392.tar.bz2 |
bpo-40280: Address more test failures on Emscripten (GH-31050)
Co-authored-by: Brett Cannon <brett@python.org>
Diffstat (limited to 'Tools/wasm')
-rw-r--r-- | Tools/wasm/README.md | 108 | ||||
-rw-r--r-- | Tools/wasm/config.site-wasm32-emscripten | 24 |
2 files changed, 109 insertions, 23 deletions
diff --git a/Tools/wasm/README.md b/Tools/wasm/README.md index f59b876..1cdaa4e 100644 --- a/Tools/wasm/README.md +++ b/Tools/wasm/README.md @@ -1,7 +1,11 @@ # Python WebAssembly (WASM) build +**WARNING: WASM support is highly experimental! Lots of features are not working yet.** + This directory contains configuration and helpers to facilitate cross -compilation of CPython to WebAssembly (WASM). +compilation of CPython to WebAssembly (WASM). For now we support +*wasm32-emscripten* builds for modern browser and for *Node.js*. It's not +possible to build for *wasm32-wasi* out-of-the-box yet. ## wasm32-emscripten build @@ -22,16 +26,14 @@ popd ### Fetch and build additional emscripten ports ```shell -embuilder build zlib +embuilder build zlib bzip2 ``` -### Cross compile to wasm32-emscripten - -For browser: +### Cross compile to wasm32-emscripten for browser ```shell -mkdir -p builddir/emscripten -pushd builddir/emscripten +mkdir -p builddir/emscripten-browser +pushd builddir/emscripten-browser CONFIG_SITE=../../Tools/wasm/config.site-wasm32-emscripten \ emconfigure ../../configure -C \ @@ -41,11 +43,27 @@ CONFIG_SITE=../../Tools/wasm/config.site-wasm32-emscripten \ --with-build-python=$(pwd)/../build/python emmake make -j$(nproc) +popd +``` + +Serve `python.html` with a local webserver and open the file in a browser. + +```shell +emrun builddir/emscripten-browser/python.html +``` + +or + +```shell +python3 -m http.server ``` -For node: +### Cross compile to wasm32-emscripten for node ``` +mkdir -p builddir/emscripten-node +pushd builddir/emscripten-node + CONFIG_SITE=../../Tools/wasm/config.site-wasm32-emscripten \ emconfigure ../../configure -C \ --host=wasm32-unknown-emscripten \ @@ -54,18 +72,70 @@ CONFIG_SITE=../../Tools/wasm/config.site-wasm32-emscripten \ --with-build-python=$(pwd)/../build/python emmake make -j$(nproc) +popd ``` -### Test in browser - -Serve `python.html` with a local webserver and open the file in a browser. - -```shell -emrun python.html ``` - -or - -```shell -python3 -m http.server +node --experimental-wasm-threads --experimental-wasm-bulk-memory builddir/emscripten-node/python.js ``` + +## wasm32-emscripten limitations and issues + +- Most stdlib modules with a dependency on external libraries are missing: + ``ctypes``, ``readline``, ``sqlite3``, ``ssl``, and more. +- Shared extension modules are not implemented yet. All extension modules + are statically linked into the main binary. +- Processes are not supported. System calls like fork, popen, and subprocess + fail with ``ENOSYS`` or ``ENOSUP``. +- Blocking sockets are not available and non-blocking sockets don't work + correctly, e.g. ``socket.accept`` crashes the runtime. ``gethostbyname`` + does not resolve to a real IP address. IPv6 is not available. +- The ``select`` module is limited. ``select.select()`` crashes the runtime + due to lack of exectfd support. +- The ``*at`` variants of functions (e.g. ``openat``) are not available. + The ``dir_fd`` argument of *os* module functions can't be used. +- Signal support is limited. ``signal.alarm``, ``itimer``, ``sigaction`` + are not available or do not work correctly. ``SIGTERM`` exits the runtime. +- Most user, group, and permission related function and modules are not + supported or don't work as expected, e.g.``pwd`` module, ``grp`` module, + ``os.setgroups``, ``os.chown``, and so on. +- Offset and iovec I/O functions (e.g. ``os.pread``, ``os.preadv``) are not + available. +- ``os.mknod`` and ``os.mkfifo`` + [don't work](https://github.com/emscripten-core/emscripten/issues/16158) + and are disabled. +- Large file support crashes the runtime and is disabled. +- ``mmap`` module is unstable. flush (``msync``) can crash the runtime. +- Resource-related functions like ``os.nice`` and most functions of the + ``resource`` module are not available. +- Some time and datetime features are broken. ``strftime`` and ``strptime`` + have known bugs, e.g. + [%% quoting](https://github.com/emscripten-core/emscripten/issues/16155), + [%U off-by-one](https://github.com/emscripten-core/emscripten/issues/16156). + Extended glibc formatting features are not available. +- ``locales`` module is affected by musl libc issues, + [bpo-46390](https://bugs.python.org/issue46390). +- ``uuid`` module is affected by + [memory leak](https://github.com/emscripten-core/emscripten/issues/16081) + and crasher in Emscripten's ``freeaddrinfo``, +- Recursive ``glob`` leaks file descriptors. +- Python's object allocator ``obmalloc`` is disabled by default. +- ``ensurepip`` is not available. + +### wasm32-emscripten in browsers + +- The bundled stdlib is limited. Network-related modules, + distutils, multiprocessing, dbm, tests and similar modules + are not shipped. All other modules are bundled as pre-compiled + ``pyc`` files. +- Threading is not supported. + +### wasm32-emscripten in node + +Node builds use ``NODERAWFS``, ``USE_PTHREADS`` and ``PROXY_TO_PTHREAD`` +linker options. + +- Node RawFS allows direct access to the host file system. +- pthread support requires WASM threads and SharedArrayBuffer (bulk memory). + The runtime keeps a pool of web workers around. Each web worker uses + several file descriptors (eventfd, epoll, pipe). diff --git a/Tools/wasm/config.site-wasm32-emscripten b/Tools/wasm/config.site-wasm32-emscripten index 413506b..98991b4 100644 --- a/Tools/wasm/config.site-wasm32-emscripten +++ b/Tools/wasm/config.site-wasm32-emscripten @@ -27,9 +27,6 @@ ac_cv_func_prlimit=no # unsupported syscall, https://github.com/emscripten-core/emscripten/issues/13393 ac_cv_func_shutdown=no -# breaks build, see https://github.com/ethanhs/python-wasm/issues/16 -ac_cv_lib_bz2_BZ2_bzCompress=no - # clock_nanosleep() causes time.sleep() to sleep forever. # nanosleep() works correctly ac_cv_func_clock_nanosleep=no @@ -66,6 +63,11 @@ ac_cv_func_pwritev=no ac_cv_func_pipe2=no ac_cv_func_nice=no ac_cv_func_setitimer=no +# unsupported syscall: __syscall_prlimit64 +ac_cv_func_prlimit=no +# unsupported syscall: __syscall_getrusage +ac_cv_func_getrusage=no +ac_cv_func_posix_fallocate=no # Syscalls that resulted in a segfault ac_cv_func_utimensat=no @@ -78,6 +80,20 @@ ac_cv_header_sys_ioctl_h=no ac_cv_func_openpty=no ac_cv_func_forkpty=no +# mkfifo and mknod are broken, create regular file +ac_cv_func_mkfifo=no +ac_cv_func_mkfifoat=no +ac_cv_func_mknod=no +ac_cv_func_mknodat=no + +# always fails with permission error +ac_cv_func_setgroups=no +ac_cv_func_setresuid=no +ac_cv_func_setresgid=no + +# alarm signal is not delivered, may need a callback into the event loop? +ac_cv_func_alarm=no + # To use dlopen, you need to use Emscripten's linking support, -# see https://github.com/emscripten-core/emscripten/wiki/Linking) +# see https://emscripten.org/docs/compiling/Dynamic-Linking.html ac_cv_func_dlopen=no |