While cairo-rs is compatible with WebAssembly, it doesn't implement any bindings to it. Instead, create a new WebAssembly crate with cairo-rs as a dependency and implement the required functionality there.
Since mimalloc is not automatically compilable to WebAssembly, the cairo-rs dependency should disable the default features, which will in turn disable mimalloc.
A working example is provided in this repository.
To compile and run the example you need:
- a Cairo 0 compiler
- the wasm-pack crate
- some HTTP server (for example: the
live-server
npm module)
Note The first two dependencies can be installed via the repository's installation script (see "Installation script")
To build the example, first compile your Cairo program:
cairo-compile src/array_sum.cairo --no_debug_info --output src/array_sum.json
And then the WebAssembly package:
wasm-pack build --target=web
This will generate a javascript module that is directly loadable by the browser.
To run the example webpage, you need to run an HTTP server. For example, using the live-server npm module:
# while in <repo>/examples/wasm-demo
npx live-server
Warning Trying to run
index.html
directly (i.e. URL starts withfile://
) will result in a CORS error.