-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Build Python distributions targeting wasm #7418
Comments
I tried integrating wasm two years ago over the course of a couple of weeks. Obviously currently, there isn't any python wheel with WASM build. Presumably, this is precisely what pyodide would help with. |
I don't see the branch, but fortunately pyodide does support out-of-tree builds now and I'll try it out when I get some time. |
@rhelmot - I poked at this a bit. pyodide build seems to require something equivalent to |
Hmm... we should be fully compliant with the appropriate standards. The only thing I can think which might be an issue is it might try to copy the subtree rooted at the setup.py file in isolation, which will make it not possible to copy the proper z3 sources. I'll take a look soon. |
Finally got around to this. I was able to build the pyodide wheel with minor modifications to setup.py, but running z3test.py yields the following error:
Do you know what this is about? Should I submit the PR or is this indicative of some sort of big architectural incompatibility with the platform? |
Thanks, I have been busy coding on something else. |
still getting the same error after that commit. Do you want me to add pyodide CI so you can test this yourself? |
Ha, I was just updating this thread essentially asking if you could add a CI so I can fix it on my side? |
I would have to swap context to set up an actual pyodide build locally, so a CI would be much better. Also it could, if appropriate, be part of WASM action at some point. I added several more commits after that one to take care of structs that didn't inherit from std::exception |
I have a preliminary build step for wasm CI on the pyodide-ci branch, but the building seems to run the poor azure pipelines box out of memory during the linking stage. I think if we can turn off LTO it'll work fine, but for something like Z3 that seems important... see https://dev.azure.com/Z3Public/Z3/_build/results?buildId=7659&view=logs&j=2f68f21a-4f23-5f18-1620-f32fb059cc4b&t=70bb1769-113b-52cf-d677-1cc690cb0a72 for build logs |
memory issues have been intermittent before. |
Looks like Azure DevOps is set up to run the pipeline from Master when I select to rerun. |
I think there is a typo in your branch: source ~/emsdk/emsdk_emv -> source ~/emsdk/emsdk_env After changing this, the Github Action fails further down the line. Given that Azure pipelines are overloaded and flaky, I wonder if making progress on the GitHub action version is going to be easier. The current break is:
So python isn't just python. |
hmm, you are bypassing me now. I was going to try pip install pyodide-cli per friendly AI suggestion/hallucination |
Looks like we should follow instructions at this point and file with pyodide devs. https://github.com/Z3Prover/z3/actions/runs/11851278844/job/33027495365 |
I wonder, it could very well be the following: https://emscripten.org/docs/porting/exceptions.html It says to pass a compile flag to enable exceptions. |
Once adding -fexceptions the error changed to be related to threads. After adding some of the flags used by the wasm build it gets further. It now fails somewhere else with a memory bounds bug. https://github.com/Z3Prover/z3/actions/runs/11866498035/job/33073294477 I have closed the issue on pyodide even though the error message always says to contact maintainers of pyodide. |
It gets much further if building Z3_SINGLED_THREADED. This is consistent with how wasm is built. |
ended up redefining par or/and tactics in single threaded mode to sequential What are the next steps, what is the distribution story? |
The .whl file is the ultimate distribution artifact here. If you upload it, people can download and install it. I don't think there's any place you can upload pyodide wheels right now to make them automatically available. |
This?
|
I would go for |
copilot suggestion looks shady for some more reasons too. |
It is live.
|
pypi will not host it from what you say and what I can see. I put it here: https://microsoft.github.io/z3guide/z3_solver-4.13.4.0-py3-none-pyodide_2024_0_wasm32.whl The sample above works with loading from that location instead of localhost. The better solution is to upload it as a release artifact and have it accessible from z3prover releases. I am not sure the slicker way? Add to release.yaml? Since there now is a pyodide package, which is the original objective of this issue. I am closing it even as there is more fiddling. Use it or lose it. |
The is very neat stuff. I noticed when trying out pyodide+CrossHair that I'm seeing immediate unsats with a reason of "unclassified exception" when attempting to apply a
Possibly this would be intended based on the cocktail of compile flags we're using, but @NikolajBjorner, maybe you would know? |
I am observing this too. |
Signed-off-by: Nikolaj Bjorner <[email protected]>
Status: Thus, we are hitting issues related to pyodide/pyodide#237 For the JS bindings, there were some related issues. They were addressed, but I am not sure exactly what all the relevant ingredients are at this point. The SharedArrayBuffer was introduced at some point. Other functions are declared as async so presumably it is legal to spawn a thread within an async but not on the main browser thread or something. Some more context on what precisely works will be required for emscripten+pyodide beyond build flags will be required. |
…3 easier The scoped_timer uses a std::therad. Spawning this thread fails in cases of WASM. Instead of adapting builds and using async features at the level of WASM and the client, we expose a specialized version of z3 that doesn't use threads at all, neither for solvers nor for timers. The tradeoff is that the periodic poll that checks for timeout directly queries the global clock each time. We characterize it as based on polling.
Status: the timeout event doesn't use threads in the pyodide build. https://microsoft.github.io/z3guide/programming/Z3%20Python%20-%20Readonly/Introduction/#solvers (hit Run twice since we have yet to deal with that we don't pre-cache the pyodide runs and therefore show a spurious error message) F12 provides a stack deep inside of pyodide with a call to contact maintainers. |
Webassembly is now a supported platform for CPython, and can be used via e.g. the Pyodide project to produce in-browser tools. I'd love to get Z3-backed testing working in this demo of hypothesis-crosshair, for example.
Since Z3 already has wasm builds for js, and many Python libraries with native extensions already support wasm (e.g.), I'm confident that this is practical - if also a bit fiddly to set up.
The text was updated successfully, but these errors were encountered: