Hello, so basically i loaded a precompiled module using Module::deserialize which worked wonderfully, but then i receive this error "unknown import: wasi_snapshot_preview1::fd_write
has not been defined"; comming from the go implementation, i saw that i was missing the equivalent of "linker.DefineWasi()"; but i have been searching for a method to link a wasi instance to the linker for hours now without finding any result. So my question would be, first how can i remedy to this ? and what am i doing wrong ?
Also please pardon my ignorance since i picked up rust 2 days ago and i wanted to toy around with wasmtime a bit.
Thanks !
The code in question :
pub async unsafe fn execute (
code: Vec<u8>,
entry_point: &str,
params: &[Val],
engine: wasmtime::Engine,
linker: wasmtime::Linker<WasiCtx>,
work_dir_path:&str,
// mut store: wasmtime::Store<WasiCtx>,
) {
let mut std_err = wasmtime_wasi::sync::stdio::stderr();
let mut std_out = wasmtime_wasi::sync::stdio::stdout();
let wasi = WasiCtxBuilder::new()
.stderr(Box::new(std_err))
.stdout(Box::new(std_out))
.build();
let mut store = wasmtime::Store::new(linker.engine(),wasi);
let module = Module::deserialize(&engine, code).unwrap();
let mut results:[Val;0] = [];
let instance = linker.instantiate(&mut store,&module).unwrap();
let entrypoint_function = instance.get_func(&mut store, entry_point).unwrap();
entrypoint_function.call(&mut store, params, &mut results).unwrap();
// read the stdout and err
let mut bufs: [u8;80] = [0;80];
// std_out.seek(0);
let out_text = store.data().table().get::<wasmtime_wasi::sync::stdio::Stderr>(2).unwrap().read_vectored(&mut [std::io::IoSliceMut::new(&mut bufs)]).await.unwrap();
println!("my loaver {}",out_text);
}
You're probably missing a call to add_to_linker.
That worked, thank you !
Last updated: Nov 22 2024 at 16:03 UTC