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 the compatibility issue with loading WATM-Go in WATER-rs #37

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Changes from 1 commit
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
30 changes: 28 additions & 2 deletions crates/water/src/runtime/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::runtime::*;
#[derive(Default, Clone)]
pub struct Host {
pub preview1_ctx: Option<wasmtime_wasi::WasiCtx>,
#[cfg(feature = "multithread")]
pub wasi_threads: Option<Arc<WasiThreadsCtx<Host>>>,
}

Expand Down Expand Up @@ -37,10 +38,13 @@ impl H2O<Host> {
}

let engine = Engine::new(&wasm_config)?;
let linker: Linker<Host> = Linker::new(&engine);


let module = Module::from_file(&engine, &conf.filepath)?;

let linker: Linker<Host> = Linker::new(&engine);

// linker.allow_unknown_exports(true);

erikziyunchi marked this conversation as resolved.
Show resolved Hide resolved
let host = Host::default();
let store = Store::new(&engine, host);

Expand Down Expand Up @@ -143,8 +147,30 @@ impl H2O<Host> {
version_common::funcs::export_config(&mut linker, conf.config_wasm.clone())?;
}

// linker.define_unknown_imports_as_traps(&module)?;

let instance = linker.instantiate(&mut store, &module)?;

// call _start function explicitly if there is one exported from the WATM module
let func = instance
.get_func(&mut store, "_start");

match func {
Some(func) => {
let mut res = vec![Val::null(); func.ty(&store).results().len()];
match func.call(&mut store, &[], &mut res) {
Ok(_) => {}
Err(e) => {
return Err(anyhow::Error::msg(format!(
"failed to call _start function: {}",
e
)))
}
}
}
None => {}
}

Ok(H2O {
version: match version {
Some(v) => v,
Expand Down
Loading