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

Update to Wasmtime 25 #2784

Merged
merged 1 commit into from
Sep 24, 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
250 changes: 139 additions & 111 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ tracing = { version = "0.1", features = ["log"] }
tracing-opentelemetry = { version = "0.26", default-features = false, features = ["metrics"] }
url = "2"

wasi-common-preview1 = { version = "22.0.0", package = "wasi-common", features = [
wasi-common-preview1 = { version = "25.0.0", package = "wasi-common", features = [
"tokio",
] }
wasmtime = "22.0.0"
wasmtime-wasi = "22.0.0"
wasmtime-wasi-http = "22.0.0"
wasmtime = "25.0.0"
wasmtime-wasi = "25.0.0"
wasmtime-wasi-http = "25.0.0"

spin-componentize = { path = "crates/componentize" }

Expand Down
11 changes: 7 additions & 4 deletions crates/componentize/src/abi_conformance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,13 @@ async fn run_command(
match store.data().test_config.invocation_style {
InvocationStyle::InboundHttp => {
let func = instance
.exports(&mut *store)
.instance("fermyon:spin/inbound-http")
.ok_or_else(|| anyhow!("no fermyon:spin/inbound-http instance found"))?
.typed_func::<(Request,), (Response,)>("handle-request")?;
.get_export(&mut *store, None, "fermyon:spin/inbound-http")
.and_then(|i| instance.get_export(&mut *store, Some(&i), "handle-request"))
.ok_or_else(|| {
anyhow!("no fermyon:spin/inbound-http/handle-request function was found")
})?;
let func =
instance.get_typed_func::<(Request,), (Response,)>(&mut *store, &func)?;

let result = func
.call_async(
Expand Down
10 changes: 6 additions & 4 deletions crates/componentize/src/abi_conformance/test_inbound_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ pub(crate) async fn test(
let instance = pre.instantiate_async(&mut store).await?;

let func = instance
.exports(&mut store)
.instance("fermyon:spin/inbound-http")
.ok_or_else(|| anyhow!("no fermyon:spin/inbound-http instance found"))?
.typed_func::<(Request,), (Response,)>("handle-request")?;
.get_export(&mut store, None, "fermyon:spin/inbound-http")
.and_then(|i| instance.get_export(&mut store, Some(&i), "handle-request"))
.ok_or_else(|| {
anyhow!("no fermyon:spin/inbound-http/handle-request function was found")
})?;
let func = instance.get_typed_func::<(Request,), (Response,)>(&mut store, &func)?;

let (response,) = func
.call_async(
Expand Down
11 changes: 7 additions & 4 deletions crates/componentize/src/abi_conformance/test_inbound_redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ pub(crate) async fn test(
let instance = pre.instantiate_async(&mut store).await?;

let func = instance
.exports(&mut store)
.instance("fermyon:spin/inbound-redis")
.ok_or_else(|| anyhow!("no inbound-redis instance found"))?
.typed_func::<(Payload,), (Result<(), Error>,)>("handle-message")?;
.get_export(&mut store, None, "fermyon:spin/inbound-redis")
.and_then(|i| instance.get_export(&mut store, Some(&i), "handle-message"))
.ok_or_else(|| {
anyhow!("no fermyon:spin/inbound-redis/handle-message function was found")
})?;
let func =
instance.get_typed_func::<(Payload,), (Result<(), Error>,)>(&mut store, &func)?;

match func
.call_async(store, (b"Hello, SpinRedis!".to_vec(),))
Expand Down
2 changes: 1 addition & 1 deletion crates/componentize/src/bugs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::module_info::ModuleInfo;
pub const EARLIEST_PROBABLY_SAFE_CLANG_VERSION: &str = "15.0.7";

/// This error represents the likely presence of the allocation bug fixed in
/// https://github.com/WebAssembly/wasi-libc/pull/377 in a Wasm module.
/// <https://github.com/WebAssembly/wasi-libc/pull/377> in a Wasm module.
#[derive(Debug, PartialEq)]
pub struct WasiLibc377Bug {
clang_version: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion crates/componentize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ mod tests {

let component = Component::new(&engine, crate::componentize_command(module)?)?;

let (wasi, _) = Command::instantiate_async(&mut store, &component, &linker).await?;
let wasi = Command::instantiate_async(&mut store, &component, &linker).await?;

wasi.wasi_cli_run()
.call_run(&mut store)
Expand Down
11 changes: 5 additions & 6 deletions crates/core/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,11 @@ async fn run_test(
let instance_pre = engine.instantiate_pre(&component)?;
let instance = instance_pre.instantiate_async(&mut store).await?;
let func = {
let mut exports = instance.exports(&mut store);

let mut instance = exports
.instance("wasi:cli/[email protected]")
.context("missing the expected 'wasi:cli/[email protected]' instance")?;
instance.typed_func::<(), (Result<(), ()>,)>("run")?
let func = instance
.get_export(&mut store, None, "wasi:cli/[email protected]")
.and_then(|i| instance.get_export(&mut store, Some(&i), "run"))
.context("missing the expected 'wasi:cli/[email protected]/run' function")?;
instance.get_typed_func::<(), (Result<(), ()>,)>(&mut store, &func)?
};

func.call_async(&mut store, ())
Expand Down
4 changes: 2 additions & 2 deletions crates/factor-key-value/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl key_value::HostStore for KeyValueDispatch {
Ok(store.get_keys().await)
}

fn drop(&mut self, store: Resource<key_value::Store>) -> Result<()> {
async fn drop(&mut self, store: Resource<key_value::Store>) -> Result<()> {
self.stores.remove(store.rep());
Ok(())
}
Expand Down Expand Up @@ -203,6 +203,6 @@ impl spin_world::v1::key_value::Host for KeyValueDispatch {

async fn close(&mut self, store: u32) -> Result<()> {
let this = Resource::new_borrow(store);
<Self as key_value::HostStore>::drop(self, this)
<Self as key_value::HostStore>::drop(self, this).await
}
}
8 changes: 1 addition & 7 deletions crates/factor-outbound-http/src/wasi_2023_10_18.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
use anyhow::Result;
use wasmtime::component::{Linker, Resource};
use wasmtime_wasi_http::bindings as latest;
use wasmtime_wasi_http::{WasiHttpImpl, WasiHttpView};

mod latest {
pub use wasmtime_wasi_http::bindings::wasi::*;
pub mod http {
pub use wasmtime_wasi_http::bindings::http::*;
}
}

mod bindings {
use super::latest;

Expand Down
8 changes: 1 addition & 7 deletions crates/factor-outbound-http/src/wasi_2023_11_10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
use super::wasi_2023_10_18::convert;
use anyhow::Result;
use wasmtime::component::{Linker, Resource};
use wasmtime_wasi_http::bindings as latest;
use wasmtime_wasi_http::{WasiHttpImpl, WasiHttpView};

mod latest {
pub use wasmtime_wasi_http::bindings::wasi::*;
pub mod http {
pub use wasmtime_wasi_http::bindings::http::*;
}
}

mod bindings {
use super::latest;

Expand Down
2 changes: 1 addition & 1 deletion crates/factor-outbound-mqtt/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl v2::HostConnection for InstanceState {
Ok(())
}

fn drop(&mut self, connection: Resource<Connection>) -> anyhow::Result<()> {
async fn drop(&mut self, connection: Resource<Connection>) -> anyhow::Result<()> {
self.connections.remove(connection.rep());
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/factor-outbound-mysql/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<C: Client> v2::HostConnection for InstanceState<C> {
.await?)
}

fn drop(&mut self, connection: Resource<Connection>) -> Result<()> {
async fn drop(&mut self, connection: Resource<Connection>) -> Result<()> {
self.connections.remove(connection.rep());
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/factor-outbound-pg/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<C: Send + Sync + Client> v2::HostConnection for InstanceState<C> {
.await?)
}

fn drop(&mut self, connection: Resource<Connection>) -> anyhow::Result<()> {
async fn drop(&mut self, connection: Resource<Connection>) -> anyhow::Result<()> {
self.connections.remove(connection.rep());
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/factor-outbound-redis/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl v2::HostConnection for crate::InstanceState {
.map_err(other_error)
}

fn drop(&mut self, connection: Resource<RedisConnection>) -> anyhow::Result<()> {
async fn drop(&mut self, connection: Resource<RedisConnection>) -> anyhow::Result<()> {
self.connections.remove(connection.rep());
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/factor-sqlite/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl v2::HostConnection for InstanceState {
conn.query(&query, parameters).await
}

fn drop(&mut self, connection: Resource<v2::Connection>) -> anyhow::Result<()> {
async fn drop(&mut self, connection: Resource<v2::Connection>) -> anyhow::Result<()> {
let _ = self.connections.remove(connection.rep());
Ok(())
}
Expand Down Expand Up @@ -132,7 +132,7 @@ impl v1::Host for InstanceState {
}

async fn close(&mut self, connection: u32) -> anyhow::Result<()> {
<Self as v2::HostConnection>::drop(self, Resource::new_own(connection))
<Self as v2::HostConnection>::drop(self, Resource::new_own(connection)).await
}

fn convert_error(&mut self, error: v1::Error) -> anyhow::Result<v1::Error> {
Expand Down
25 changes: 12 additions & 13 deletions crates/factor-wasi/src/wasi_2023_10_18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ mod bindings {
"#,
async: {
only_imports: [
"[drop]output-stream",
"[drop]input-stream",
"[method]descriptor.access-at",
"[method]descriptor.advise",
"[method]descriptor.change-directory-permissions-at",
Expand Down Expand Up @@ -54,12 +56,9 @@ mod bindings {
"[method]descriptor.unlink-file-at",
"[method]descriptor.unlock",
"[method]descriptor.write",
"[method]input-stream.read",
"[method]input-stream.blocking-read",
"[method]input-stream.blocking-skip",
"[method]input-stream.skip",
"[method]output-stream.forward",
"[method]output-stream.splice",
"[method]output-stream.blocking-splice",
"[method]output-stream.blocking-flush",
"[method]output-stream.blocking-write",
Expand Down Expand Up @@ -676,12 +675,12 @@ impl<T> wasi::io::streams::HostInputStream for WasiImpl<T>
where
T: WasiView,
{
async fn read(
fn read(
&mut self,
self_: Resource<InputStream>,
len: u64,
) -> wasmtime::Result<Result<Vec<u8>, StreamError>> {
let result = latest::io::streams::HostInputStream::read(self, self_, len).await;
let result = latest::io::streams::HostInputStream::read(self, self_, len);
convert_stream_result(self, result)
}

Expand All @@ -694,12 +693,12 @@ where
convert_stream_result(self, result)
}

async fn skip(
fn skip(
&mut self,
self_: Resource<InputStream>,
len: u64,
) -> wasmtime::Result<Result<u64, StreamError>> {
let result = latest::io::streams::HostInputStream::skip(self, self_, len).await;
let result = latest::io::streams::HostInputStream::skip(self, self_, len);
convert_stream_result(self, result)
}

Expand All @@ -716,8 +715,8 @@ where
latest::io::streams::HostInputStream::subscribe(self, self_)
}

fn drop(&mut self, rep: Resource<InputStream>) -> wasmtime::Result<()> {
latest::io::streams::HostInputStream::drop(self, rep)
async fn drop(&mut self, rep: Resource<InputStream>) -> wasmtime::Result<()> {
latest::io::streams::HostInputStream::drop(self, rep).await
}
}

Expand Down Expand Up @@ -795,13 +794,13 @@ where
convert_stream_result(self, result)
}

async fn splice(
fn splice(
&mut self,
self_: Resource<OutputStream>,
src: Resource<InputStream>,
len: u64,
) -> wasmtime::Result<Result<u64, StreamError>> {
let result = latest::io::streams::HostOutputStream::splice(self, self_, src, len).await;
let result = latest::io::streams::HostOutputStream::splice(self, self_, src, len);
convert_stream_result(self, result)
}

Expand All @@ -824,8 +823,8 @@ where
anyhow::bail!("forward API no longer supported")
}

fn drop(&mut self, rep: Resource<OutputStream>) -> wasmtime::Result<()> {
latest::io::streams::HostOutputStream::drop(self, rep)
async fn drop(&mut self, rep: Resource<OutputStream>) -> wasmtime::Result<()> {
latest::io::streams::HostOutputStream::drop(self, rep).await
}
}

Expand Down
25 changes: 12 additions & 13 deletions crates/factor-wasi/src/wasi_2023_11_10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mod bindings {
"#,
async: {
only_imports: [
"[drop]input-stream",
"[drop]output-stream",
"[method]descriptor.advise",
"[method]descriptor.create-directory-at",
"[method]descriptor.get-flags",
Expand All @@ -45,11 +47,8 @@ mod bindings {
"[method]descriptor.sync-data",
"[method]descriptor.unlink-file-at",
"[method]descriptor.write",
"[method]input-stream.read",
"[method]input-stream.blocking-read",
"[method]input-stream.blocking-skip",
"[method]input-stream.skip",
"[method]output-stream.splice",
"[method]output-stream.blocking-splice",
"[method]output-stream.blocking-flush",
"[method]output-stream.blocking-write",
Expand Down Expand Up @@ -625,12 +624,12 @@ impl<T> wasi::io::streams::HostInputStream for WasiImpl<T>
where
T: WasiView,
{
async fn read(
fn read(
&mut self,
self_: Resource<InputStream>,
len: u64,
) -> wasmtime::Result<Result<Vec<u8>, StreamError>> {
let result = latest::io::streams::HostInputStream::read(self, self_, len).await;
let result = latest::io::streams::HostInputStream::read(self, self_, len);
convert_stream_result(self, result)
}

Expand All @@ -643,12 +642,12 @@ where
convert_stream_result(self, result)
}

async fn skip(
fn skip(
&mut self,
self_: Resource<InputStream>,
len: u64,
) -> wasmtime::Result<Result<u64, StreamError>> {
let result = latest::io::streams::HostInputStream::skip(self, self_, len).await;
let result = latest::io::streams::HostInputStream::skip(self, self_, len);
convert_stream_result(self, result)
}

Expand All @@ -665,8 +664,8 @@ where
latest::io::streams::HostInputStream::subscribe(self, self_)
}

fn drop(&mut self, rep: Resource<InputStream>) -> wasmtime::Result<()> {
latest::io::streams::HostInputStream::drop(self, rep)
async fn drop(&mut self, rep: Resource<InputStream>) -> wasmtime::Result<()> {
latest::io::streams::HostInputStream::drop(self, rep).await
}
}

Expand Down Expand Up @@ -744,13 +743,13 @@ where
convert_stream_result(self, result)
}

async fn splice(
fn splice(
&mut self,
self_: Resource<OutputStream>,
src: Resource<InputStream>,
len: u64,
) -> wasmtime::Result<Result<u64, StreamError>> {
let result = latest::io::streams::HostOutputStream::splice(self, self_, src, len).await;
let result = latest::io::streams::HostOutputStream::splice(self, self_, src, len);
convert_stream_result(self, result)
}

Expand All @@ -765,8 +764,8 @@ where
convert_stream_result(self, result)
}

fn drop(&mut self, rep: Resource<OutputStream>) -> wasmtime::Result<()> {
latest::io::streams::HostOutputStream::drop(self, rep)
async fn drop(&mut self, rep: Resource<OutputStream>) -> wasmtime::Result<()> {
latest::io::streams::HostOutputStream::drop(self, rep).await
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/key-value-spin/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod test {
Ok(None)
));

kv.drop(Resource::new_own(rep))?;
kv.drop(Resource::new_own(rep)).await?;

Ok(())
}
Expand Down
Loading
Loading