-
Notifications
You must be signed in to change notification settings - Fork 35
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
Try to get WASI working here as well? #18
Comments
I would love to work on WASI! Unfortunately, I'm not sure how we'd do that :/ We would need to either
Both of these are a lot of work, so I figured making progress on getting Emscripten working will probably carry over, and would be the best use of time for now until we have a good idea of which of the above we should do. |
https://github.com/singlestore-labs/cpython/tree/wasm_v3.9.7 is supposedly a build of CPython 3.9.7 that works under WASI. I have not dived into it, though, to see what they had to do to make it work. Otherwise https://leaningtech.com/cheerpx/ claims to have gotten it to work, but that's a very different approach. |
singlestore labs uses stubs for pthreads, https://github.com/singlestore-labs/cpython/blob/wasm_v3.9.7/wasi-stubs/include/pthread_stubs.h |
That could work. However, I also know that WASI libc itself is compiled as single threaded, so I'm not sure if that could cause any issues. Would be interesting to try nonetheless! |
Ok I think we'd also need to maybe rebuild wasi-libc even if we had pthread stubs. See this comment and the discussion here: WebAssembly/wasi-libc#209 (comment) |
Another option may be to stub out pthreads at the level of https://github.dev/python/cpython/blob/main/Python/thread_pthread.h so it isn't stubbing out pthreads per-se, just removing our use of the header. |
I think that is probably the best option, I've been toying with that idea in my head for a bit. I think it would probably require changes elsewhere as well. It seems a lot of places check if |
You say "patches", I say "change in CPython" 😉. For me, I want WASI for three reasons:
And it's that last one that's critical to me, because that then makes WebAssembly a legitimate build target for CPython which then helps Pyodide and emscripten-based targets as well. And since I have plans to introduce platform support tiers, having a stable buildbot will be important someday. 😉 Hence I would want this upstream instead of as a series of patches. |
Oh yeah when I say patches I mean patches in the "changes that would get upstreamed". They would live temporarily as patches, as I expect the changes to be more than a single PR.
Note that the existing scripts could be changed to generate node-compatible Emscripten output by outputting to a
As am I! This and reproducible computing are both very interesting concepts to me.
We could probably do this with Emscripten, but WASI would be better for sure.
Would definitely like to see this happen. I will probably try to get CPython to build on WASI over the weekend :) |
@brettcannon I looked into platform specific compiler flags a while ago. Emscripten and wasi define some macros by default, https://gist.github.com/tiran/ee6e825e1388b21ca70f4fc645d8cbb9 #ifdef __wasm__
#endif
#ifdef __EMSCRIPTEN__
#endif
#ifdef __wasi__
#endif if sys.platform == "emscripten":
pass |
Yesterday I got a hacky WASI build to work using bubble gum, paper clips, and the pthread stubs from https://github.com/singlestore-labs/cpython/blob/wasm_v3.9.7/wasi-stubs/include/pthread_stubs.h
I have created upstream ticket https://bugs.python.org/issue46315 and opened a PR with the non-hacky bits of my patch. |
We've actually been continuing our work on the WASI Python build. We're continuing down the path of a compatibility layer called WASIX to fill the gaps left between POSIX and WASI: https://github.com/singlestore-labs/wasix. The reason we went this direction was so that we could also use that library to compile 3rd party libraries for Python extensions as well. Trying to patch every 3rd party library to bypass the missing features didn't seem like a viable option. We have a WASI Python build working now that based on WASIX that runs most of the Python unit test suite. Of course many tests fail since there are no threads, pipes, sockets, etc. yet, but a vast majority are passing now. I was actually planning on pinging your team with the changes to the Python sources that we did have to see if we could work together on this. |
@kesmit13 Would you be able to share the source and/or a binary. I'd like to try running it with https://github.com/turbolent/w2c2 and implement support for wasix |
@turbolent Our WASI Python repo is available at https://github.com/singlestore-labs/python-wasi. It's mostly just a patch to |
So far the work has focused on the
emscripten
browser. Do we want to also try and tacklewasi
in this repo as well?The text was updated successfully, but these errors were encountered: