This commit builds on bytecodealliance/wasm-tools#690 to add support to testing of the component model to execute functions when running `*.wast` files. This support is all built on #4442 as functions are invoked through a "dynamic" API. Right now the testing and integration is fairly crude but I'm hoping that we can try to improve it over time as necessary. For now this should provide a hopefully more convenient syntax for unit tests and the like.
wasm-spec-interpreter
This project shows how to use ocaml-interop to call into the Wasm spec
interpreter. There are several steps to making this work:
- building the OCaml Wasm spec interpreter as a static library
- building a Rust-to-OCaml FFI bridge using
ocaml-interopand a custom OCaml wrapper - linking both things into a Rust crate
Dependencies
This crate only builds in an environment with:
make(the Wasm spec interpreter uses aMakefile)ocamlopt,ocamlbuild(available with, e.g.,dnf install ocaml)- Linux tools (e.g.
ar); currently it is easiest to build the static libraries in a single environment but this could be fixed in the future (TODO) libgmp, for the OCamlzarithpackagegitis used bybuild.rsto retrieve the repository containing the Wasm spec interpreter; it is safe to completely removeocaml/specto get a new copy
Build
cargo build --features build-libinterpret
Use FFI_LIB_DIR=path/to/lib/... to specify a different location for the static
library (this is mainly for debugging). If the build-libinterpret feature is
not provided, this crate will build successfully but fail at runtime.
Test
cargo test --features build-libinterpret