Skip to content

Commit 6968891

Browse files
committed
feat: updating wasmtime to 36.0.0
1 parent a6d1001 commit 6968891

13 files changed

Lines changed: 1114 additions & 862 deletions

File tree

Cargo.lock

Lines changed: 1006 additions & 809 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ tokio = { version = "1", features = ["full"] }
1313
tokio-util = { version = "0.7", features = ["codec"] }
1414
tracing = "0.1"
1515
hyper = { version = "1", features = ["full"] }
16-
http = "1.3.1"
16+
http = "1.3"
1717
async-trait = "0.1"
18-
wasmtime = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0"}
19-
wasmtime-wasi = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0"}
20-
wasi-common = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0"}
21-
wasmtime-wasi-nn = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0", features = ["openvino", "candle"] }
22-
wasmtime-wasi-http = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0"}
23-
wasmtime-environ = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-31.0.0"}
18+
wasmtime = { git = "https://github.com/G-Core/wasmtime.git", features = ["component-model"], branch = "release-36.0.0"}
19+
wasmtime-wasi = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0"}
20+
wasmtime-wasi-io = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0"}
21+
wasi-common = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0"}
22+
wasmtime-wasi-nn = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0", features = ["openvino", "candle"] }
23+
wasmtime-wasi-http = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0"}
24+
wasmtime-environ = { git = "https://github.com/G-Core/wasmtime.git", branch = "release-36.0.0"}
2425
bytesize = "2.0.1"
2526

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

4748

4849
[dev-dependencies]
49-
tempfile = "3.20.0"
50+
tempfile = "3.22"
5051

5152
[dependencies]
5253
anyhow = { workspace = true }

crates/http-backend/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ anyhow = {workspace = true}
1313
tracing = {workspace = true}
1414
hyper = { workspace = true }
1515
tokio = { workspace = true }
16-
hyper-util = { version = "0.1.10", features = ["client", "client-legacy", "http1", "tokio"] }
17-
http-body-util = "0.1.3"
18-
pin-project = "1.1.10"
19-
tower-service = "0.3.3"
20-
smol_str = {workspace = true}
16+
hyper-util = { version = "0.1", features = ["client", "client-legacy", "http1", "tokio"] }
17+
http-body-util = "0.1"
18+
pin-project = "1.1"
19+
tower-service = "0.3"
2120

2221
[dev-dependencies]
2322
claims = "0.8"

crates/http-service/src/executor/http.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ use hyper::body::Body;
1111
use reactor::gcore::fastedge;
1212
use runtime::{store::StoreBuilder, InstancePre};
1313
use std::time::{Duration, Instant};
14-
use wasmtime_wasi::StdoutStream;
1514
use wasmtime_wasi_http::body::HyperOutgoingBody;
1615

1716
/// Execute context used by ['HttpService']
1817
#[derive(Clone)]
19-
pub struct HttpExecutorImpl<C> {
18+
pub struct HttpExecutorImpl<C: 'static> {
2019
instance_pre: InstancePre<HttpState<C>>,
2120
store_builder: StoreBuilder,
2221
backend: Backend<C>,
@@ -95,9 +94,9 @@ where
9594
let mut store = store_builder.build(state)?;
9695

9796
let instance = self.instance_pre.instantiate_async(&mut store).await?;
98-
let http_handler = instance.get_export(&mut store, None, "gcore:fastedge/http-handler");
97+
let http_handler = instance.get_export_index(&mut store, None, "gcore:fastedge/http-handler");
9998
let process = instance
100-
.get_export(&mut store, http_handler.as_ref(), "process")
99+
.get_export_index(&mut store, http_handler.as_ref(), "process")
101100
.ok_or_else(|| anyhow!("gcore:fastedge/http-handler instance not found"))?;
102101
let func = instance
103102
.get_typed_func::<(fastedge::http::Request,), (fastedge::http::Response,)>(
@@ -111,9 +110,7 @@ where
111110
Err(error) => {
112111
// log to application logger error
113112
if let Some(ref logger) = store.data().logger {
114-
if let Err(e) = logger.stream().write(error.to_string().into()) {
115-
tracing::debug!(cause=?e, "write error: {}", error)
116-
}
113+
logger.write_msg(format!("Execution error: {}", error)).await;
117114
}
118115
return Err(error);
119116
}

crates/http-service/src/executor/wasi_http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use wasmtime_wasi_http::{body::HyperOutgoingBody, WasiHttpView};
1717

1818
/// Execute context used by ['HttpService']
1919
#[derive(Clone)]
20-
pub struct WasiHttpExecutorImpl<C> {
20+
pub struct WasiHttpExecutorImpl<C: 'static> {
2121
instance_pre: InstancePre<HttpState<C>>,
2222
store_builder: StoreBuilder,
2323
backend: Backend<C>,

crates/http-service/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use wasmtime::component::HasSelf;
12
use std::net::SocketAddr;
23
use std::sync::Arc;
34
use std::time::Duration;
@@ -181,25 +182,26 @@ where
181182
fn configure_engine(builder: &mut WasmEngineBuilder<Self::State>) -> Result<()> {
182183
let linker = builder.component_linker_ref();
183184
// Allow re-importing of `wasi:clocks/wall-clock@0.2.0`
184-
wasmtime_wasi::add_to_linker_async(linker)?;
185+
wasmtime_wasi::p2::add_to_linker_async(linker)?;
185186
linker.allow_shadowing(true);
186187
wasmtime_wasi_http::add_to_linker_async(linker)?;
187188

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

192-
reactor::gcore::fastedge::http_client::add_to_linker(linker, |data| {
193-
&mut data.as_mut().http_backend
194-
})?;
193+
reactor::gcore::fastedge::http_client::add_to_linker::<_, HasSelf<_>>(
194+
linker,
195+
|data| &mut data.as_mut().http_backend,
196+
)?;
195197

196-
reactor::gcore::fastedge::dictionary::add_to_linker(linker, |data| {
198+
reactor::gcore::fastedge::dictionary::add_to_linker::<_, HasSelf<_>>(linker, |data| {
197199
&mut data.as_mut().dictionary
198200
})?;
199201

200-
reactor::gcore::fastedge::secret::add_to_linker(linker, |data| &mut data.secret_store)?;
202+
reactor::gcore::fastedge::secret::add_to_linker::<_, HasSelf<_>>(linker, |data| &mut data.secret_store)?;
201203

202-
reactor::gcore::fastedge::key_value::add_to_linker(linker, |data| {
204+
reactor::gcore::fastedge::key_value::add_to_linker::<_, HasSelf<_>>(linker, |data| {
203205
&mut data.key_value_store
204206
})?;
205207

crates/key-value-store/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description = "key-value store host function"
1010
reactor = { path = "../reactor" }
1111
wasmtime = {workspace = true}
1212
slab = "0.4"
13-
async-trait = "0.1.88"
13+
async-trait = "0.1"
1414
smol_str = {workspace = true}
1515

1616
[lints]

crates/reactor/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
wasmtime::component::bindgen!({
44
path: "../../sdk/wit",
55
world: "reactor",
6-
async: true,
7-
tracing: false,
6+
imports: { default: async },
87
});

crates/runtime/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ stats = ["clickhouse"]
1313

1414
[dependencies]
1515
anyhow = { workspace = true }
16+
tokio = { workspace = true }
1617
tokio-util = { workspace = true }
1718
wasmtime = { workspace = true }
1819
wasmtime-wasi = { workspace = true }
1920
wasi-common = { workspace = true }
2021
wasmtime-wasi-nn = { workspace = true }
2122
wasmtime-wasi-http = { workspace = true }
2223
wasmtime-environ = { workspace = true }
24+
wasmtime-wasi-io = { workspace = true }
2325
smol_str = { workspace = true }
2426
moka = { workspace = true }
2527
http = {workspace = true}

crates/runtime/src/lib.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::app::KvStoreOption;
22
use key_value_store::KeyValueStore;
33
use std::{fmt::Debug, ops::Deref};
4-
use wasmtime::component::ResourceTable;
5-
use wasmtime_wasi::IoView;
4+
use wasmtime_wasi::ResourceTable;
5+
use wasmtime_wasi::WasiCtxView;
66
use wasmtime_wasi_http::{HttpResult, WasiHttpCtx, WasiHttpView};
7+
use wasmtime_wasi_io::IoView;
78

89
use crate::store::StoreBuilder;
910
use http_backend::Backend;
@@ -78,7 +79,7 @@ pub enum Wasi {
7879
}
7980

8081
/// Host state data associated with individual [Store]s and [Instance]s.
81-
pub struct Data<T> {
82+
pub struct Data<T: 'static> {
8283
inner: T,
8384
wasi: Wasi,
8485
pub wasi_nn: WasiNnCtx,
@@ -141,6 +142,10 @@ impl<T: Send + BackendRequest> WasiHttpView for Data<T> {
141142
},
142143
))
143144
}
145+
146+
fn table(&mut self) -> &mut ResourceTable {
147+
&mut self.table
148+
}
144149
}
145150

146151
impl<T> Data<T> {
@@ -191,12 +196,15 @@ impl AsRef<wasmtime::Config> for WasmConfig {
191196
}
192197

193198
impl<T: Send> wasmtime_wasi::WasiView for Data<T> {
194-
fn ctx(&mut self) -> &mut wasmtime_wasi::WasiCtx {
199+
fn ctx(&mut self) -> WasiCtxView<'_> {
195200
match &mut self.wasi {
196201
Wasi::Preview1(_) => {
197202
unreachable!("using WASI Preview 1 functions with Preview 2 store")
198203
}
199-
Wasi::Preview2(ctx) => ctx,
204+
Wasi::Preview2(ctx) => WasiCtxView {
205+
ctx,
206+
table: &mut self.table,
207+
},
200208
}
201209
}
202210
}
@@ -302,7 +310,7 @@ pub type ComponentLinker<T> = wasmtime::component::Linker<Data<T>>;
302310
pub type ModuleLinker<T> = wasmtime::Linker<Data<T>>;
303311

304312
/// An `WasmEngine` is a global context for the initialization and execution of WASM application.
305-
pub struct WasmEngine<T> {
313+
pub struct WasmEngine<T: 'static> {
306314
inner: Engine,
307315
component_linker: ComponentLinker<T>,
308316
module_linker: ModuleLinker<T>,
@@ -311,7 +319,7 @@ pub struct WasmEngine<T> {
311319
/// A builder interface for configuring a new [`WasmEngine`].
312320
///
313321
/// A new [`WasmEngineBuilder`] can be obtained with [`WasmEngine::builder`].
314-
pub struct WasmEngineBuilder<T> {
322+
pub struct WasmEngineBuilder<T: 'static> {
315323
engine: Engine,
316324
component_linker: ComponentLinker<T>,
317325
module_linker: ModuleLinker<T>,
@@ -385,7 +393,7 @@ pub trait PreCompiledLoader<K> {
385393
}
386394

387395
pub trait ContextT {
388-
type BackendConnector;
396+
type BackendConnector: 'static;
389397

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

0 commit comments

Comments
 (0)