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 #[allow(dead_code)] 24 pub enum SpecExport { 25 Global(SpecValue), 26 Memory(Vec<u8>), 27 } 28 29 /// Represents a WebAssembly instance from the OCaml interpreter side. 30 pub struct SpecInstance { 31 #[cfg(feature = "has-libinterpret")] 32 repr: ocaml_interop::BoxRoot<SpecInstance>, 33 } 34 35 #[cfg(feature = "has-libinterpret")] 36 mod with_library; 37 #[cfg(feature = "has-libinterpret")] 38 pub use with_library::*; 39 40 #[cfg(not(feature = "has-libinterpret"))] 41 mod without_library; 42 #[cfg(not(feature = "has-libinterpret"))] 43 pub use without_library::*; 44 45 // If the user is fuzzing`, we expect the OCaml library to have been built. 46 #[cfg(all(fuzzing, not(feature = "has-libinterpret")))] 47 compile_error!("The OCaml library was not built."); 48 49 /// Check if the OCaml spec interpreter bindings will work. 50 pub fn support_compiled_in() -> bool { 51 cfg!(feature = "has-libinterpret") 52 } 53