Skip to content

Commit

Permalink
we should only have one wasm engine
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Dec 30, 2024
1 parent 4fdf069 commit 7600399
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
11 changes: 3 additions & 8 deletions fastn-ds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ pub trait RequestType {
fn body(&self) -> &[u8];
}

pub static WASM_ENGINE: once_cell::sync::Lazy<wasmtime::Engine> =
once_cell::sync::Lazy::new(|| {
wasmtime::Engine::new(wasmtime::Config::new().async_support(true)).unwrap()
});

#[derive(thiserror::Error, Debug)]
pub enum CreatePoolError {
#[error("pool error {0}")]
Expand All @@ -175,7 +170,7 @@ pub enum CreatePoolError {
pub async fn wasmc(path: &str) -> wasmtime::Result<()> {
Ok(tokio::fs::write(
format!("{path}c"),
wasmtime::Module::from_file(&WASM_ENGINE, path)?.serialize()?,
wasmtime::Module::from_file(&fastn_wasm::WASM_ENGINE, path)?.serialize()?,
)
.await?)
}
Expand Down Expand Up @@ -227,13 +222,13 @@ impl DocumentStore {
None => {
let wasmc_path = fastn_ds::Path::new(format!("{path}c").as_str());
let module = match unsafe {
wasmtime::Module::from_trusted_file(&WASM_ENGINE, &wasmc_path.path)
wasmtime::Module::from_trusted_file(&fastn_wasm::WASM_ENGINE, &wasmc_path.path)
} {
Ok(m) => m,
Err(e) => {
tracing::info!("could not read {wasmc_path:?} file: {e:?}");
let source = self.read_content(&fastn_ds::Path::new(path), &None).await?;
wasmtime::Module::from_binary(&WASM_ENGINE, &source)?
wasmtime::Module::from_binary(&fastn_wasm::WASM_ENGINE, &source)?
}
};

Expand Down
2 changes: 1 addition & 1 deletion fastn-ds/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async fn main() {
};

let module = wasmtime::Module::from_binary(
&fastn_ds::WASM_ENGINE,
&fastn_wasm::WASM_ENGINE,
&tokio::fs::read(
"../../ft-sdk/sample-wasm/target/wasm32-unknown-unknown/release/sample_wasm.wasm",
)
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use process_http_request::process_http_request;
pub(crate) use store::Conn;
pub use store::{ConnectionExt, SQLError, Store, StoreExt, StoreImpl};

pub(crate) static WASM_ENGINE: once_cell::sync::Lazy<wasmtime::Engine> =
pub static WASM_ENGINE: once_cell::sync::Lazy<wasmtime::Engine> =
once_cell::sync::Lazy::new(|| {
wasmtime::Engine::new(wasmtime::Config::new().async_support(true)).unwrap()
});
Expand Down

0 comments on commit 7600399

Please sign in to comment.