-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Remove caching in wasmer_wamr mode #127
Changes from 29 commits
7302ad0
85336ee
052dca6
cc5e49a
ce10788
fc15501
e40c9f3
0fe1843
c2ba5b7
3b745ca
d866ebd
a299e31
fd98bee
d092438
c0ad0fe
6dd0b41
1a5b46b
5f5813f
e79ec8a
2253824
773d114
c3354aa
41ac607
5207718
a04b6a2
c366edf
17da637
b55a420
594a8c1
d9614af
99e3980
a5c86ac
c409299
acfb72f
cd40252
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ pub const WASM_METERING_LIMIT: u64 = 10_000_000; | |
|
||
/// Generate an engine with a wasm compiler | ||
/// and Metering (use limits) in place. | ||
pub fn make_engine() -> Engine { | ||
pub(crate) fn make_engine() -> Engine { | ||
let cost_function = |_operator: &wasmparser::Operator| -> u64 { 1 }; | ||
// @todo 100 giga-ops is totally arbitrary cutoff so we probably | ||
// want to make the limit configurable somehow. | ||
|
@@ -50,10 +50,15 @@ pub fn make_engine() -> Engine { | |
engine | ||
} | ||
|
||
pub fn make_runtime_engine() -> Engine { | ||
pub(crate) fn make_runtime_engine() -> Engine { | ||
Engine::headless() | ||
} | ||
|
||
/// Build an interpreter module from wasm bytes. | ||
pub fn build_module(_wasm: &[u8]) -> Result<Arc<Module>, wasmer::RuntimeError> { | ||
unimplemented!("The feature flag 'wasmer_wamr' must be enabled to support building a Module directly. Please use the ModuleCache instead."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is keep a consistent api so we don't need to use conditional feature flags in the consumer. I recognize this is silly, since the function below |
||
} | ||
|
||
/// Take WASM binary and prepare a wasmer Module suitable for iOS | ||
pub fn build_ios_module(wasm: &[u8]) -> Result<Module, CompileError> { | ||
info!( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
use crate::prelude::*; | ||
use std::path::Path; | ||
use std::sync::Arc; | ||
use wasmer::CompileError; | ||
use wasmer::DeserializeError; | ||
use wasmer::Engine; | ||
|
@@ -7,14 +9,22 @@ use wasmer::Module; | |
/// Generate an engine with a wasm interpreter | ||
/// The interpreter used (wasm micro runtime) does not support metering | ||
/// See tracking issue: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2163 | ||
pub fn make_engine() -> Engine { | ||
pub(crate) fn make_engine() -> Engine { | ||
Engine::default() | ||
} | ||
|
||
pub fn make_runtime_engine() -> Engine { | ||
pub(crate) fn make_runtime_engine() -> Engine { | ||
Engine::default() | ||
} | ||
|
||
/// Build an interpreter module from wasm bytes. | ||
pub fn build_module(wasm: &[u8]) -> Result<Arc<Module>, wasmer::RuntimeError> { | ||
let compiler_engine = make_engine(); | ||
let res = Module::from_binary(&compiler_engine, wasm); | ||
let module = res.map_err(|e| wasm_error!(WasmErrorInner::ModuleBuild(e.to_string())))?; | ||
Ok(Arc::new(module)) | ||
} | ||
|
||
/// Take WASM binary and prepare a wasmer Module suitable for iOS | ||
pub fn build_ios_module(_wasm: &[u8]) -> Result<Module, CompileError> { | ||
unimplemented!("The feature flag 'wasmer_sys' must be enabled to support compiling wasm"); | ||
|
@@ -24,3 +34,25 @@ pub fn build_ios_module(_wasm: &[u8]) -> Result<Module, CompileError> { | |
pub fn get_ios_module_from_file(_path: &Path) -> Result<Module, DeserializeError> { | ||
unimplemented!("The feature flag 'wasmer_sys' must be enabled to support compiling wasm"); | ||
} | ||
|
||
#[cfg(test)] | ||
pub mod tests { | ||
use super::build_module; | ||
|
||
#[test] | ||
fn build_module_test() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. smoke test for building a wasm module in |
||
// simple example wasm taken from wasmer docs | ||
// https://docs.rs/wasmer/latest/wasmer/struct.Module.html#example | ||
let wasm: Vec<u8> = vec![ | ||
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, 0x01, 0x7f, | ||
0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0b, 0x01, 0x07, 0x61, 0x64, 0x64, 0x5f, | ||
0x6f, 0x6e, 0x65, 0x00, 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x20, 0x00, 0x41, 0x01, | ||
0x6a, 0x0b, 0x00, 0x1a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x01, 0x0a, 0x01, 0x00, 0x07, | ||
0x61, 0x64, 0x64, 0x5f, 0x6f, 0x6e, 0x65, 0x02, 0x07, 0x01, 0x00, 0x01, 0x00, 0x02, | ||
0x70, 0x30, | ||
]; | ||
|
||
let res = build_module(wasm.as_slice()); | ||
assert!(res.is_ok()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#! /usr/bin/env bash | ||
|
||
./bench-wasmer_sys_dev.sh | ||
./bench-wasmer_sys_prod.sh | ||
./bench-wasmer_wamr.sh | ||
./scripts/bench-wasmer_sys_dev.sh | ||
./scripts/bench-wasmer_sys_prod.sh | ||
./scripts/bench-wasmer_wamr.sh |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#! /usr/bin/env bash | ||
|
||
./test-wasmer_sys_dev.sh | ||
./test-wasmer_sys_prod.sh | ||
./test-wasmer_wamr.sh | ||
./scripts/test-wasmer_sys_dev.sh | ||
./scripts/test-wasmer_sys_prod.sh | ||
./scripts/test-wasmer_wamr.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename error type to clarify that it is an error arising when creating a new wasmer Module. Only in
wasmer_sys
mode does compilation occur here.