1 //! This library provides a way to interpret Wasm functions in the official Wasm
2 //! specification interpreter, written in OCaml, from Rust.
3 //!
4 //! In order to not break Wasmtime's build, this library will always compile. It
5 //! does depend on certain tools (see `README.md`) that may or may not be
6 //! available in the environment:
7 //! - when the tools are available, we build and link to an OCaml static
8 //! library (see `with_library` module)
9 //! - when the tools are not available, this library will panic at runtime (see
10 //! `without_library` module).
11
12 /// Enumerate the kinds of Wasm values the OCaml interpreter can handle.
13 #[derive(Clone, Debug, PartialEq)]
14 pub enum SpecValue {
15 I32(i32),
16 I64(i64),
17 F32(i32),
18 F64(i64),
19 V128(Vec<u8>),
20 }
21
22 /// Represents a WebAssembly export from the OCaml interpreter side.
23 pub enum SpecExport {
24 Global(SpecValue),
25 Memory(Vec<u8>),
26 }
27
28 /// Represents a WebAssembly instance from the OCaml interpreter side.
29 pub struct SpecInstance {
30 #[cfg(feature = "has-libinterpret")]
31 repr: ocaml_interop::BoxRoot<SpecInstance>,
32 }
33
34 #[cfg(feature = "has-libinterpret")]
35 mod with_library;
36 #[cfg(feature = "has-libinterpret")]
37 pub use with_library::*;
38
39 #[cfg(not(feature = "has-libinterpret"))]
40 mod without_library;
41 #[cfg(not(feature = "has-libinterpret"))]
42 pub use without_library::*;
43
44 // If the user is fuzzing`, we expect the OCaml library to have been built.
45 #[cfg(all(fuzzing, not(feature = "has-libinterpret")))]
46 compile_error!("The OCaml library was not built.");
47
48 /// Check if the OCaml spec interpreter bindings will work.
support_compiled_in() -> bool49 pub fn support_compiled_in() -> bool {
50 cfg!(feature = "has-libinterpret")
51 }
52