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
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
24 changes: 23 additions & 1 deletion 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);

let host = Host::default();
let store = Store::new(&engine, host);

Expand Down Expand Up @@ -143,8 +147,26 @@ 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");

if let Some(func) = 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
)))
}
}
}

Ok(H2O {
version: match version {
Some(v) => v,
Expand Down
1 change: 0 additions & 1 deletion crates/water/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use tracing::{debug, info};
use wasi_common::{file::FileAccessMode, WasiCtx, WasiFile};
use wasmtime::*;
use wasmtime_wasi::sync::{Dir, WasiCtxBuilder};
use wasmtime_wasi_threads::WasiThreadsCtx;

// =================== CURRENT CRATE IMPORTS ===================
use crate::{
Expand Down
Loading