Skip to content
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

fix: wasmer-runtime deprecation #375

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/mun_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mlua = { package ="mlua", version="0.2", default-features = false, features=["ve
mun_test = { path = "../mun_test" }
tempfile = "3"
termcolor = "1.1"
wasmer-runtime = "0.16"
wasmer = "2.2.1"

[[bench]]
name = "benchmarks"
Expand Down
13 changes: 9 additions & 4 deletions crates/mun_runtime/benches/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use mun_runtime::StructRef;
use wasmer::Store;

mod util;

Expand All @@ -9,7 +10,9 @@ pub fn fibonacci_benchmark(c: &mut Criterion) {
// Perform setup (not part of the benchmark)
let runtime = util::runtime_from_file("fibonacci.mun");
let lua = util::lua_from_file("fibonacci.lua");
let wasm = util::wasmer_from_file("fibonacci.wasm");
let wasm_store = Store::default();
let wasm = util::wasmer_from_file(&wasm_store, "fibonacci.wasm");
let wasm_func = wasm.exports.get_function("main").unwrap();

let mut group = c.benchmark_group("fibonacci");

Expand Down Expand Up @@ -38,7 +41,7 @@ pub fn fibonacci_benchmark(c: &mut Criterion) {
// Run Wasm fibonacci
group.bench_with_input(BenchmarkId::new("wasm", i), i, |b, i| {
b.iter(|| {
wasm.call("main", &[(*i as i32).into()]).unwrap();
wasm_func.call(&[(*i as i32).into()]).unwrap();
})
});
}
Expand Down Expand Up @@ -72,7 +75,9 @@ pub fn empty_benchmark(c: &mut Criterion) {
// Perform setup (not part of the benchmark)
let runtime = util::runtime_from_file("empty.mun");
let lua = util::lua_from_file("empty.lua");
let wasm = util::wasmer_from_file("empty.wasm");
let wasm_store = Store::default();
let wasm = util::wasmer_from_file(&wasm_store, "empty.wasm");
let wasm_func = wasm.exports.get_function("empty").unwrap();

let mut group = c.benchmark_group("empty");

Expand All @@ -89,7 +94,7 @@ pub fn empty_benchmark(c: &mut Criterion) {
})
});
group.bench_function("wasm", |b| {
b.iter(|| wasm.call("empty", &[black_box(20i64).into()]))
b.iter(|| wasm_func.call(&[black_box(20i64).into()]))
});

group.finish();
Expand Down
9 changes: 5 additions & 4 deletions crates/mun_runtime/benches/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use compiler::{Config, DisplayColor, Driver, OptimizationLevel, PathOrInline};
use mlua::Lua;
use mun_runtime::Runtime;
use std::path::{Path, PathBuf};
use wasmer_runtime::{instantiate, Instance};
use wasmer::{Instance, Module, Store};

fn compute_resource_path<P: AsRef<Path>>(p: P) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
Expand Down Expand Up @@ -40,8 +40,9 @@ pub fn lua_from_file<P: AsRef<Path>>(p: P) -> Lua {
lua
}

pub fn wasmer_from_file<P: AsRef<Path>>(p: P) -> Instance {
pub fn wasmer_from_file<P: AsRef<Path>>(store: &Store, p: P) -> Instance {
let wasm_content = std::fs::read(compute_resource_path(p)).unwrap();
let import_objects = wasmer_runtime::imports! {};
instantiate(&wasm_content, &import_objects).unwrap()
let import_objects = wasmer::imports! {};
let module = Module::new(store, &wasm_content).unwrap();
Instance::new(&module, &import_objects).unwrap()
}