Skip to content

Commit cdfda48

Browse files
authored
fix: wasmer-runtime deprecation (#375)
1 parent 25156eb commit cdfda48

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

crates/mun_runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mlua = { package ="mlua", version="0.2", default-features = false, features=["ve
3333
mun_test = { path = "../mun_test" }
3434
tempfile = "3"
3535
termcolor = "1.1"
36-
wasmer-runtime = "0.16"
36+
wasmer = "2.2.1"
3737

3838
[[bench]]
3939
name = "benchmarks"

crates/mun_runtime/benches/benchmarks.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
22
use mun_runtime::StructRef;
3+
use wasmer::Store;
34

45
mod util;
56

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

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

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

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

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

95100
group.finish();

crates/mun_runtime/benches/util/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use compiler::{Config, DisplayColor, Driver, OptimizationLevel, PathOrInline};
22
use mlua::Lua;
33
use mun_runtime::Runtime;
44
use std::path::{Path, PathBuf};
5-
use wasmer_runtime::{instantiate, Instance};
5+
use wasmer::{Instance, Module, Store};
66

77
fn compute_resource_path<P: AsRef<Path>>(p: P) -> PathBuf {
88
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
@@ -40,8 +40,9 @@ pub fn lua_from_file<P: AsRef<Path>>(p: P) -> Lua {
4040
lua
4141
}
4242

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

0 commit comments

Comments
 (0)