Skip to content
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
1,815 changes: 1,006 additions & 809 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ tokio = { version = "1", features = ["full"] }
tokio-util = { version = "0.7", features = ["codec"] }
tracing = "0.1"
hyper = { version = "1", features = ["full"] }
http = "1.3.1"
http = "1.3"
async-trait = "0.1"
wasmtime = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0"}
wasmtime-wasi = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0"}
wasi-common = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0"}
wasmtime-wasi-nn = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0", features = ["openvino", "candle"] }
wasmtime-wasi-http = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0"}
wasmtime-environ = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0"}
wasmtime = { git = "https://github.com/G-Core/wasmtime.git", features = ["component-model"], branch = "release-36.0.0"}
wasmtime-wasi = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0"}
wasmtime-wasi-io = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0"}
wasi-common = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0"}
wasmtime-wasi-nn = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0", features = ["openvino", "candle"] }
wasmtime-wasi-http = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0"}
wasmtime-environ = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0"}
bytesize = "2.0.1"

clap = { version = "4", features = ["derive"] }
Expand All @@ -46,7 +47,7 @@ authors.workspace = true


[dev-dependencies]
tempfile = "3.20.0"
tempfile = "3.22"

[dependencies]
anyhow = { workspace = true }
Expand Down
9 changes: 4 additions & 5 deletions crates/http-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ anyhow = {workspace = true}
tracing = {workspace = true}
hyper = { workspace = true }
tokio = { workspace = true }
hyper-util = { version = "0.1.10", features = ["client", "client-legacy", "http1", "tokio"] }
http-body-util = "0.1.3"
pin-project = "1.1.10"
tower-service = "0.3.3"
smol_str = {workspace = true}
hyper-util = { version = "0.1", features = ["client", "client-legacy", "http1", "tokio"] }
http-body-util = "0.1"
pin-project = "1.1"
tower-service = "0.3"

[dev-dependencies]
claims = "0.8"
Expand Down
14 changes: 7 additions & 7 deletions crates/http-service/src/executor/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ use hyper::body::Body;
use reactor::gcore::fastedge;
use runtime::{store::StoreBuilder, InstancePre};
use std::time::{Duration, Instant};
use wasmtime_wasi::StdoutStream;
use wasmtime_wasi_http::body::HyperOutgoingBody;

/// Execute context used by ['HttpService']
#[derive(Clone)]
pub struct HttpExecutorImpl<C> {
pub struct HttpExecutorImpl<C: 'static> {
instance_pre: InstancePre<HttpState<C>>,
store_builder: StoreBuilder,
backend: Backend<C>,
Expand Down Expand Up @@ -95,9 +94,10 @@ where
let mut store = store_builder.build(state)?;

let instance = self.instance_pre.instantiate_async(&mut store).await?;
let http_handler = instance.get_export(&mut store, None, "gcore:fastedge/http-handler");
let http_handler =
instance.get_export_index(&mut store, None, "gcore:fastedge/http-handler");
let process = instance
.get_export(&mut store, http_handler.as_ref(), "process")
.get_export_index(&mut store, http_handler.as_ref(), "process")
.ok_or_else(|| anyhow!("gcore:fastedge/http-handler instance not found"))?;
let func = instance
.get_typed_func::<(fastedge::http::Request,), (fastedge::http::Response,)>(
Expand All @@ -111,9 +111,9 @@ where
Err(error) => {
// log to application logger error
if let Some(ref logger) = store.data().logger {
if let Err(e) = logger.stream().write(error.to_string().into()) {
tracing::debug!(cause=?e, "write error: {}", error)
}
logger
.write_msg(format!("Execution error: {}", error))
.await;
}
return Err(error);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/http-service/src/executor/wasi_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use wasmtime_wasi_http::{body::HyperOutgoingBody, WasiHttpView};

/// Execute context used by ['HttpService']
#[derive(Clone)]
pub struct WasiHttpExecutorImpl<C> {
pub struct WasiHttpExecutorImpl<C: 'static> {
instance_pre: InstancePre<HttpState<C>>,
store_builder: StoreBuilder,
backend: Backend<C>,
Expand Down
13 changes: 8 additions & 5 deletions crates/http-service/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
use wasmtime::component::HasSelf;
use wasmtime_wasi_nn::wit::WasiNnView;

pub use crate::executor::ExecutorFactory;
Expand Down Expand Up @@ -181,25 +182,27 @@ where
fn configure_engine(builder: &mut WasmEngineBuilder<Self::State>) -> Result<()> {
let linker = builder.component_linker_ref();
// Allow re-importing of `wasi:clocks/wall-clock@0.2.0`
wasmtime_wasi::add_to_linker_async(linker)?;
wasmtime_wasi::p2::add_to_linker_async(linker)?;
linker.allow_shadowing(true);
wasmtime_wasi_http::add_to_linker_async(linker)?;

wasmtime_wasi_nn::wit::add_to_linker(linker, |data: &mut runtime::Data<Self::State>| {
WasiNnView::new(&mut data.table, &mut data.wasi_nn)
})?;

reactor::gcore::fastedge::http_client::add_to_linker(linker, |data| {
reactor::gcore::fastedge::http_client::add_to_linker::<_, HasSelf<_>>(linker, |data| {
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The repeated use of HasSelf<_> type parameter suggests this could be extracted into a type alias or helper function to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
&mut data.as_mut().http_backend
})?;

reactor::gcore::fastedge::dictionary::add_to_linker(linker, |data| {
reactor::gcore::fastedge::dictionary::add_to_linker::<_, HasSelf<_>>(linker, |data| {
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The repeated use of HasSelf<_> type parameter suggests this could be extracted into a type alias or helper function to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
&mut data.as_mut().dictionary
})?;

reactor::gcore::fastedge::secret::add_to_linker(linker, |data| &mut data.secret_store)?;
reactor::gcore::fastedge::secret::add_to_linker::<_, HasSelf<_>>(linker, |data| {
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The repeated use of HasSelf<_> type parameter suggests this could be extracted into a type alias or helper function to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
&mut data.secret_store
})?;

reactor::gcore::fastedge::key_value::add_to_linker(linker, |data| {
reactor::gcore::fastedge::key_value::add_to_linker::<_, HasSelf<_>>(linker, |data| {
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The repeated use of HasSelf<_> type parameter suggests this could be extracted into a type alias or helper function to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
&mut data.key_value_store
})?;

Expand Down
2 changes: 1 addition & 1 deletion crates/key-value-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "key-value store host function"
reactor = { path = "../reactor" }
wasmtime = {workspace = true}
slab = "0.4"
async-trait = "0.1.88"
async-trait = "0.1"
smol_str = {workspace = true}

[lints]
Expand Down
3 changes: 1 addition & 2 deletions crates/reactor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
wasmtime::component::bindgen!({
path: "../../sdk/wit",
world: "reactor",
async: true,
tracing: false,
imports: { default: async },
});
2 changes: 2 additions & 0 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ stats = ["clickhouse"]

[dependencies]
anyhow = { workspace = true }
tokio = { workspace = true }
tokio-util = { workspace = true }
wasmtime = { workspace = true }
wasmtime-wasi = { workspace = true }
wasi-common = { workspace = true }
wasmtime-wasi-nn = { workspace = true }
wasmtime-wasi-http = { workspace = true }
wasmtime-environ = { workspace = true }
wasmtime-wasi-io = { workspace = true }
smol_str = { workspace = true }
moka = { workspace = true }
http = {workspace = true}
Expand Down
24 changes: 16 additions & 8 deletions crates/runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::app::KvStoreOption;
use key_value_store::KeyValueStore;
use std::{fmt::Debug, ops::Deref};
use wasmtime::component::ResourceTable;
use wasmtime_wasi::IoView;
use wasmtime_wasi::ResourceTable;
use wasmtime_wasi::WasiCtxView;
use wasmtime_wasi_http::{HttpResult, WasiHttpCtx, WasiHttpView};
use wasmtime_wasi_io::IoView;

use crate::store::StoreBuilder;
use http_backend::Backend;
Expand Down Expand Up @@ -78,7 +79,7 @@ pub enum Wasi {
}

/// Host state data associated with individual [Store]s and [Instance]s.
pub struct Data<T> {
pub struct Data<T: 'static> {
inner: T,
wasi: Wasi,
pub wasi_nn: WasiNnCtx,
Expand Down Expand Up @@ -141,6 +142,10 @@ impl<T: Send + BackendRequest> WasiHttpView for Data<T> {
},
))
}

fn table(&mut self) -> &mut ResourceTable {
&mut self.table
}
}

impl<T> Data<T> {
Expand Down Expand Up @@ -191,12 +196,15 @@ impl AsRef<wasmtime::Config> for WasmConfig {
}

impl<T: Send> wasmtime_wasi::WasiView for Data<T> {
fn ctx(&mut self) -> &mut wasmtime_wasi::WasiCtx {
fn ctx(&mut self) -> WasiCtxView<'_> {
match &mut self.wasi {
Wasi::Preview1(_) => {
unreachable!("using WASI Preview 1 functions with Preview 2 store")
}
Wasi::Preview2(ctx) => ctx,
Wasi::Preview2(ctx) => WasiCtxView {
ctx,
table: &mut self.table,
},
}
}
}
Expand Down Expand Up @@ -302,7 +310,7 @@ pub type ComponentLinker<T> = wasmtime::component::Linker<Data<T>>;
pub type ModuleLinker<T> = wasmtime::Linker<Data<T>>;

/// An `WasmEngine` is a global context for the initialization and execution of WASM application.
pub struct WasmEngine<T> {
pub struct WasmEngine<T: 'static> {
inner: Engine,
component_linker: ComponentLinker<T>,
module_linker: ModuleLinker<T>,
Expand All @@ -311,7 +319,7 @@ pub struct WasmEngine<T> {
/// A builder interface for configuring a new [`WasmEngine`].
///
/// A new [`WasmEngineBuilder`] can be obtained with [`WasmEngine::builder`].
pub struct WasmEngineBuilder<T> {
pub struct WasmEngineBuilder<T: 'static> {
engine: Engine,
component_linker: ComponentLinker<T>,
module_linker: ModuleLinker<T>,
Expand Down Expand Up @@ -385,7 +393,7 @@ pub trait PreCompiledLoader<K> {
}

pub trait ContextT {
type BackendConnector;
type BackendConnector: 'static;

fn make_logger(&self, app_name: SmolStr, wrk: &App) -> Logger;

Expand Down
Loading