# CPython for WebAssembly and Pyodide: meeting notes Date: January 2022 The goal of this meeting is to see how we could collaborate on supporting WebAssembly in CPython between, - the effort of supporting the WASM build target in CPython (https://bugs.python.org/issue40280) and https://github.com/ethanhs/python-wasm - the Pyodide project ## Agenda (Feel free to edit) * [name=hc] Maybe should contact the emscripten team and see if we can get a representative from them to join? 1. What WASM related parts could/should be integrated in CPython - [name=ch] for 3.11 I like to add enough to be able to build Pyodide without patching CPython. - the [callback](https://github.com/pyodide/pyodide/blob/main/cpython/patches/keyboard-interrupt.patch) patch for keyboard interrupt and signals is missing - [name=hc] [New trampoline patch to support function pointer casts](https://github.com/pyodide/pyodide/blob/main/cpython/patches/0001-call-trampolines-to-handle-fpcast-troubles.patch) (or some other plan for function pointer cast handling, see [my blog post](https://blog.pyodide.org/posts/function-pointer-cast-handling/)) - [name=es] We probably also want configurable I/O for stdin/stdout/stderr - [name=ch] stdio can be configured with a custom main.c 2. Pyodide parts that could be reused or would be necessary to allow continued work on python-wasm and in CPython upstream 3. Work on passing the CPython test suite 4. Work on unsupported stdlib modules in the browser (sockets etc, multiprocessing) - [name=ch] blocking sockets are a problem. non-blocking sockets should work? 5. [name=hc] Questions about synchronous I/O - Design work for this is immature still but I think it is important to think about in relation to 4. - can we incorporate support for this is a way that is flexible between -s ASYNCIFY, pthreads, Atomics.wait, other techniques? The situation also looks very different for WASI. - What about role of a Comlink-like library? https://github.com/GoogleChromeLabs/comlink - [name=es] I think this would probably be up to embedder - [name=hc] Agreed sockets and other IO stuff it will interact, have to consider how the interface will look - [name=hc] Maybe could just have extra "system calls" we need the embedder to support, maybe behind compile flags 6. WASM wheels specification - [name=ch] first wasm32-emscripten must become an officially supported platform. - [name=es] probably will need a PEP, and a better understanding of the ABIs involved (CPython, WASM, Emscripten/wasi) - [name=hc] I think we should stick to thinking about wasm32-emscripten for now wasm32-wasi will not be compatible with wasm32-emscripten anyways (unless the package only uses libc -- even the wasi file system apis aren't posix compatible) - [name=hc] WASI currently lacks dynamic linking. Binary wheels require dynamic linking. I guess we can make wheels targeting WASI + dlfcn.h? Dynamic linking itself is a mature interface, and hopefully when the WASM dynlink proposal gets finished it will be easy enough to implement it. I guess there is some support for this: https://docs.wasmtime.dev/examples-c-linking.html ### Some thoughts on WASI * [name=hc] I think we should focus on wasm32-emscripten since we know more about that now. wasm32-wasi is going to expose a very different set of libraries, since Emscripten is trying to mimic a native environment and wasi is very definitely not trying to do that. * Several of us want the sandboxing guarantees WASI provides * [name=hc] One interesting difference is that WASI is intended for sandboxing so people are not likely to want to add a bunch of extra libraries outside of the wasm sandbox because of security concerns. On the other hand, browser builds in emscripten are already sandboxed and emscripten adds a lot of Javascript support. * [name=hc] Are there any reference examples of people with wasm32-wasi Pythons? * [name=es] Here are a couple [singlestore-labs stubbed pthread.h in wasi-libc](https://github.com/singlestore-labs/cpython/tree/wasm_v3.9.7) and [wasmer uses an older threadless build of Python](https://github.com/wapm-packages/python)