-
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
Java Script API bindings #1298
Comments
@NikolajBjorner An alternative that I mentioned a while back is to use SWIG. This supports automatically generating language bindings for many different languages. This could reduce the maintenance burden of the manually maintained language bindings. However I've never used SWIG before so I'm not sure if the bindings generated are of sufficient quality. |
If anyone is interested, I am working on typescript bindings for webassembly compiled libz3.so. I can contribute my progress so far? |
@cpitclaudel recently compiled all of Z3 to Javascript, which removes all the OS-dependency issues at the cost of runtime performance, but the cost was smaller than I expected. |
@wintersteiger I would be very interested in that! What is the size of the "binary" you got? Do you have any instructions? |
Roughly 20MB (when compiled to WebAssembly). Compiling to javascript doesn't work, due to (I think) unaligned memory accesses. I could write things up, but probably not before the week-end after the next. |
@cpitclaudel I am very interested in seeing your build setup for compilation to webassembly. |
I've finally packaged everything 🎉 The repo is here: https://github.com/cpitclaudel/z3.wasm The repo includes the build scripts, a binary release, some documentation, and the sources of the demo page. The generated binaries expose Z3's command line, and a small SMT2 API. I've tested this on small examples, and I'm using this as the SMT solver backend for my JavaScript build of F* (https://people.csail.mit.edu/cpitcla/fstar.js/stlc.html) |
This is great! I added a link to the repository from the readme.md file. |
There is also https://github.com/babelsberg/z3.js which is a set of build-scripts I've used previously to compiled Z3 into native JavaScript. Our approach (z3javascript) works well from Node / Electron but I think as WebAssembly matures that would probably be a better long term target (compatability). I experimented with ASM.js two years ago and it compiled fine but was too slow for practical usage. A big issue we've found is that JavaScripts lack of destructors can make memory management very difficult. Is Z3 going to get official JavaScript bindings or is this just for documentation? |
I would like to make an attempt to contribute something here. Besides SWIG and Native C++ add ons for Node (https://nodejs.org/api/addons.html), another option is to wrap the C API using http://grpc.io. In addition to opening up the languages supported by it, using gRPC would bring the benefit of being able to integrate with a remote Z3 server. I would love to hear feedback on this option. |
Sounds very nice. With Miguel Neves we have an internal scale out version of Z3 that runs in Azure. For ecma script integration, I have no real understanding of what is the better approach. |
I have a working (for simple programs at least) TypeScript bindings around libz3 compiled with WASM. Repo is here: https://github.com/d1m0/z3.ts. Here is an example of code using the bindings: var lib: LibZ3 = new LibZ3(wasmInstance) var s1: Z3_symbol = lib.Z3_mk_int_symbol(context, new Sint32(1)) var eq: Z3_ast = lib.Z3_mk_eq(context, c1, c2) lib.Z3_solver_assert(context, solver, eq) The bindings were auto-generated from the Pyhton bindings in z3.z3core. |
Looks pretty slick. For example, the code that does not produce any attribute when the return value is VOID is
Your bindings will too easily bit-rot (I am going to change a lot in the next couple of months so it is going to be quite busy). |
Sure! If it would not be too much work for you! Also if you see a way to just fold some of this code into the main repo, I would love to help. |
Thanks for your feedback, @NikolajBjorner FYI, I gave SWIG a try and it while it seems very nice, the Javascript backend does not seem to be actively maintained (e.g. swig/swig#804). It's possible to patch the issues, but it will probably require continuous maintenance. |
I've built a native N-API binding for Z3. Rather than compiling Z3 into Javascript, it defines an FFI from Javascript into Z3 compiled natively. It is still work-in-progress and has not been integrated with Z3's build system. I am putting it up early for other people who are looking for this functionality, and who would be willing to help harden it. It can be found here: https://github.com/sb98052/z3/tree/master/src/api/n-api I plan on submitting this extension as a pull request when I am convinced that it is stable and has test coverage equalling the other APIs. |
I've been interested in this for a while for browser usage in an actual application. I have now created my own library build to WASM via emscripten as well: https://github.com/sim642/z3em. There's nothing revolutionary there except that it's packaged and published on npm unlike other similar attempts: https://www.npmjs.com/package/z3em. My goal is to integrate Z3 into an actual logic game of mine (https://github.com/sim642/einstein-js/tree/z3) and have Z3 as an independent and reusable module. I haven't focused on API but have just exposed the bare minimum to evaluate smtlib2 interactively. I encountered an issue with compiling Z3 via emscripten: sim642/z3em#1. The I think currently there's no means for cross-compilation as |
Thanks! Commit c247abf provides enough scaffolding for me to transition my changes over to your build system. I should have a PR for your review soon. |
Hello. I prototyped z3js, a utility library for transpiling a tiny subset of javascript into smt and vice versa. The main idea of z3js is using it with @cpitclaudel's z3.wasm to use z3 in (a tiny subset of) javascript (even inbrowser) and hence act as javascript-binding for z3. z3js is far far far away from being actually useful but would like to hear z3 experts' feedback on it. Thanks in advance. |
I've been using @cpitclaudel's z3.wasm, but I haven't yet found a way to set the timeout without either a pthread issue or a crash: building --single-threaded leads to crashes when I give |
Hey :) it is great to see that there is effort to get Z3 running in the browser. Are there news regarding the current status of this?(compiled into WASM? @cpitclaudel )?. I would love to use the TypeScript bindings by @d1m0 and facing some compilation issues such as Are there pre-built releases of both Z3.wasm and the TypeScript (or JavaScript) bindings that work with the WASM? EDIT: I have fixed the compilation issues by using specific versions of Emscripten and Z3. |
I don't have TS bindings, but you can see an example of use by an Elm app in https://github.com/mgree/crossbars/, using a WebWorker via an elm port. |
@mgree: Thanks a lot. Great project :) |
@stahlbauer hey! I haven't touched the .ts bindings in a long time, but if they may be useful to you, I can resurrect them over a weekend. Let me know if you would be interesting in maintaining/contributing to those as well! |
@cd1m0: Hey, I have fixed the TS bindings and got them working. At the moment, the adjustments are in my fork (on Github) of the bindings. I am also working on a more user-friendly API to Z3 in TS that builds on this bindings. Should be finished within the next two weeks. |
There's now TypeScript bindings published on npm: https://www.npmjs.com/package/z3-solver |
What are the current ways to use Z3 from Java Script?
The following efforts relate to this (summarized from conversation below).
The text was updated successfully, but these errors were encountered: