Add a crate to interface with the WebAssembly spec interpreter

The WebAssembly spec interpreter is written in OCaml and the new crate
uses `ocaml-interop` along with a small OCaml wrapper to interpret Wasm
modules in-process. The build process for this crate is currently
Linux-specific: it requires several OCaml packages (e.g. `apt install -y
ocaml-nox ocamlbuild`) as well as `make`, `cp`, and `ar`.
This commit is contained in:
Andrew Brown
2021-07-28 13:12:47 -07:00
parent 2e95d4e7c6
commit a7f592a026
16 changed files with 442 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
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-interop` and 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 a `Makefile`)
- `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)
Remember to retrieve the Wasm spec submodule:
```
git clone ... --recursive
```
### Build
```
RUSTFLAGS=--cfg=fuzzing cargo build
```
Use `FFI_LIB_DIR=path/to/lib/...` to specify a different location for the static
library (this is mainly for debugging). If the `--cfg=fuzzing` configuration is
not provided, this crate will build successfully but fail at runtime.
### Test
```
RUSTFLAGS=--cfg=fuzzing cargo test
```