Refine the runtime api and document the exposed items (#115)

* private module, remove unused method, docs on compile_with

* refine runtime api and document exposed items

* Fix integration test build

* Fix lint
This commit is contained in:
Lachlan Sneff
2019-01-23 12:34:15 -08:00
committed by GitHub
parent 7632beced8
commit ab65477d1f
10 changed files with 205 additions and 53 deletions

View File

@ -1,47 +1,57 @@
#[doc(inline)]
pub use wasmer_runtime_core::*;
pub use wasmer_runtime_core::import::ImportObject;
pub use wasmer_runtime_core::instance::Instance;
pub use wasmer_runtime_core::module::Module;
pub use wasmer_runtime_core::validate;
pub use wasmer_runtime_core::types::Value;
pub use wasmer_runtime_core::vm::Ctx;
/// The `compile(...)` function compiles a `Module`
/// from WebAssembly binary code. This function is useful if it
/// is necessary to a compile a module before it can be instantiated
/// (otherwise, the webassembly::instantiate() function should be used).
pub use wasmer_runtime_core::{compile_with, validate};
pub use wasmer_runtime_core::error;
pub use wasmer_runtime_core::imports;
pub mod value {
pub use wasmer_runtime_core::types::{Type, Value};
}
/// 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).
///
/// Params:
/// [`Module`]: struct.Module.html
/// [`instantiate`]: fn.instantiate.html
///
/// # Params:
/// * `wasm`: A `&[u8]` containing the
/// binary code of the wasm module you want to compile.
/// Errors:
/// If the operation fails, the function returns `Err(error::CompileError::...).`
/// # Errors:
/// If the operation fails, the function returns `Err(error::CompileError::...)`.
#[cfg(feature = "wasmer-clif-backend")]
pub fn compile(wasm: &[u8]) -> error::CompileResult<module::Module> {
pub fn compile(wasm: &[u8]) -> error::CompileResult<Module> {
use wasmer_clif_backend::CraneliftCompiler;
wasmer_runtime_core::compile_with(&wasm[..], &CraneliftCompiler::new())
}
/// The `instantiate(...)` function allows you to compile and
/// instantiate WebAssembly code in one go.
/// Compile and instantiate WebAssembly code without
/// creating a [`Module`].
///
/// Params:
/// [`Module`]: struct.Module.html
///
/// # Params:
/// * `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
/// webassembly::Memory objects. There must be one matching property
/// Memory objects. There must be one matching property
/// for each declared import of the compiled module or else a
/// webassembly::LinkError is thrown.
/// Errors:
/// LinkError is thrown.
/// # Errors:
/// 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")]
pub fn instantiate(
wasm: &[u8],
import_object: import::ImportObject,
) -> error::Result<instance::Instance> {
pub fn instantiate(wasm: &[u8], import_object: ImportObject) -> error::Result<Instance> {
let module = compile(wasm)?;
module.instantiate(import_object)
}