python / cpython

The Python programming language
https://www.python.org
Other
62.15k stars 29.86k forks source link

Test the `wasm32-wasip2` target triple #121634

Closed brettcannon closed 1 week ago

brettcannon commented 1 month ago

https://bytecodealliance.zulipchat.com/#narrow/stream/394175-SIG-Guest-Languages/topic/Python.20subgroup/near/450807393

Requires #120371 since WASI SDK 22 is required. But this supposedly has some socket support! Downside is any runtime that doesn't support preview2 won't be able to use the file. That probably means adding a flag to wasi.py to control for the target triple as it's currently hard-coded:

https://github.com/python/cpython/blob/e8c91d90ba8fab410a27fad4f709cc73f6ffcbf4/Tools/wasm/wasi.py#L23

Linked PRs

Zheaoli commented 1 month ago

May I make a try for this?

brettcannon commented 1 month ago

May I make a try for this?

Are you asking about changing wasi.py, or trying to make wasm23-wasip2 work? If it's the latter then https://github.com/dicej/cpython/commit/118e9d8eeabb6345d57295f6cec1616694eacbc2 may be of some help.

Zheaoli commented 1 month ago

Sorry for confused reply. I would like to make a try to support wasm32-wasip2

Zheaoli commented 1 month ago

Hi Brett, Sorry for replying too late.

I have made a try to support the socket in p2, but I found some issues. For now, the socket support in p2 is not UNIX compatible. It miss many things that are widely used. For example, getaddrinfo is not usable in p2. This means that we need to wrap https://github.com/WebAssembly/wasi-sockets/blob/main/wit/ip-name-lookup.wit as getaddrinfo in socket module. Otherwise, the socket test can't not be passed in p2 environment. I'm not sure this is acceptable or not

brettcannon commented 3 weeks ago

@Zheaoli I think some support is better than nothing. I'm okay getting what's there working and then providing the feedback of what's still missing.

brettcannon commented 3 weeks ago

I've started a branch to at least allow for compiling w/ wasm32-wasip2 regardless of whether any networking is turned on.

brettcannon commented 3 weeks ago

FYI I will leave this open while I figure out what to do about WASI 0.2 as it's technically a new platform which means buildbot, PEP 11, deciding what to test in CI, etc.

brettcannon commented 1 week ago

OK, so I found out that VS Code's WASI support is not moving over to WASI 0.2 yet because it's a lot of work and the thinking is networking isn't useful w/o threads and those haven't fully landed in WASM yet (I hear Chrome/v8 is the holdup). As such, work isn't as concerned w/ WASI 0.2 and since that would mean I would have to support it as a tier 3 on my own time I'm going to de-emphasize WASI 0.2 and instead focus on more generic things like getting e.g., zlib working (my plans are tracked at https://opensource.snarky.ca/Python/WASI).

So I'm closing this issue as done as my changes to wasi.py means one can do their own WASI 0.2 build w/o issue (just w/o special features turned on).