2019-01-23 20:34:15 +00:00
|
|
|
pub use wasmer_runtime_core::import::ImportObject;
|
2019-01-23 23:30:35 +00:00
|
|
|
pub use wasmer_runtime_core::instance::{Function, Instance};
|
2019-01-22 19:02:06 +00:00
|
|
|
pub use wasmer_runtime_core::module::Module;
|
2019-01-23 20:34:15 +00:00
|
|
|
pub use wasmer_runtime_core::types::Value;
|
|
|
|
pub use wasmer_runtime_core::vm::Ctx;
|
|
|
|
|
|
|
|
pub use wasmer_runtime_core::{compile_with, validate};
|
2019-01-08 17:09:47 +00:00
|
|
|
|
2019-01-23 20:34:15 +00:00
|
|
|
pub use wasmer_runtime_core::error;
|
|
|
|
pub use wasmer_runtime_core::imports;
|
|
|
|
|
2019-01-23 23:30:35 +00:00
|
|
|
pub mod wasm {
|
|
|
|
pub use wasmer_runtime_core::instance::Function;
|
|
|
|
pub use wasmer_runtime_core::types::{FuncSig, Type, Value};
|
2019-01-23 20:34:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Compile WebAssembly binary code into a [`Module`].
|
|
|
|
/// This function is useful if it is necessary to
|
|
|
|
/// compile a module before it can be instantiated
|
|
|
|
/// (otherwise, the [`instantiate`] function should be used).
|
|
|
|
///
|
|
|
|
/// [`Module`]: struct.Module.html
|
|
|
|
/// [`instantiate`]: fn.instantiate.html
|
2019-01-22 19:02:06 +00:00
|
|
|
///
|
2019-01-23 20:34:15 +00:00
|
|
|
/// # Params:
|
2019-01-22 19:02:06 +00:00
|
|
|
/// * `wasm`: A `&[u8]` containing the
|
|
|
|
/// binary code of the wasm module you want to compile.
|
2019-01-23 20:34:15 +00:00
|
|
|
/// # Errors:
|
|
|
|
/// If the operation fails, the function returns `Err(error::CompileError::...)`.
|
2019-01-22 19:02:06 +00:00
|
|
|
#[cfg(feature = "wasmer-clif-backend")]
|
2019-01-23 20:34:15 +00:00
|
|
|
pub fn compile(wasm: &[u8]) -> error::CompileResult<Module> {
|
2019-01-22 19:02:06 +00:00
|
|
|
use wasmer_clif_backend::CraneliftCompiler;
|
|
|
|
wasmer_runtime_core::compile_with(&wasm[..], &CraneliftCompiler::new())
|
2019-01-21 22:43:04 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 20:34:15 +00:00
|
|
|
/// Compile and instantiate WebAssembly code without
|
|
|
|
/// creating a [`Module`].
|
|
|
|
///
|
|
|
|
/// [`Module`]: struct.Module.html
|
2019-01-22 19:02:06 +00:00
|
|
|
///
|
2019-01-23 20:34:15 +00:00
|
|
|
/// # Params:
|
2019-01-22 19:02:06 +00:00
|
|
|
/// * `wasm`: A `&[u8]` containing the
|
|
|
|
/// binary code of the wasm module you want to compile.
|
|
|
|
/// * `import_object`: An object containing the values to be imported
|
|
|
|
/// into the newly-created Instance, such as functions or
|
2019-01-23 20:34:15 +00:00
|
|
|
/// Memory objects. There must be one matching property
|
2019-01-22 19:02:06 +00:00
|
|
|
/// for each declared import of the compiled module or else a
|
2019-01-23 20:34:15 +00:00
|
|
|
/// LinkError is thrown.
|
|
|
|
/// # Errors:
|
2019-01-22 19:02:06 +00:00
|
|
|
/// If the operation fails, the function returns a
|
|
|
|
/// `error::CompileError`, `error::LinkError`, or
|
|
|
|
/// `error::RuntimeError` (all combined into an `error::Error`),
|
|
|
|
/// depending on the cause of the failure.
|
|
|
|
#[cfg(feature = "wasmer-clif-backend")]
|
2019-01-23 20:34:15 +00:00
|
|
|
pub fn instantiate(wasm: &[u8], import_object: ImportObject) -> error::Result<Instance> {
|
2019-01-22 19:02:06 +00:00
|
|
|
let module = compile(wasm)?;
|
|
|
|
module.instantiate(import_object)
|
2019-01-09 02:57:28 +00:00
|
|
|
}
|
2019-01-22 23:26:56 +00:00
|
|
|
|
|
|
|
/// The current version of this crate
|
|
|
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|