Skip to content

Commit f51829e

Browse files
authored
Merge pull request #3237 from alexcrichton/wasmtime36
Update to Wasmtime 36.0.1
2 parents 748429a + ad350d5 commit f51829e

File tree

17 files changed

+914
-903
lines changed

17 files changed

+914
-903
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,16 @@ tower-service = "0.3.3"
169169
tracing = { version = "0.1.41", features = ["log"] }
170170
url = "2"
171171
walkdir = "2"
172-
wasm-encoder = "0.235"
173-
wasm-metadata = "0.235"
172+
wasm-encoder = "0.236.1"
173+
wasm-metadata = "0.236.1"
174174
wasm-pkg-client = "0.11"
175175
wasm-pkg-common = "0.11"
176-
wasmparser = "0.235"
177-
wasmtime = "35.0.0"
178-
wasmtime-wasi = "35.0.0"
179-
wasmtime-wasi-http = "35.0.0"
180-
wit-component = "0.235"
181-
wit-parser = "0.235"
176+
wasmparser = "0.236.1"
177+
wasmtime = "36.0.1"
178+
wasmtime-wasi = "36.0.1"
179+
wasmtime-wasi-http = "36.0.1"
180+
wit-component = "0.236.1"
181+
wit-parser = "0.236.1"
182182

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

crates/componentize/src/abi_conformance/mod.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use wasmtime::{
3636
component::{Component, HasSelf, InstancePre, Linker},
3737
Engine, Store,
3838
};
39-
use wasmtime_wasi::p2::{pipe::MemoryOutputPipe, IoView, WasiCtx, WasiCtxBuilder, WasiView};
40-
use wasmtime_wasi::ResourceTable;
39+
use wasmtime_wasi::p2::pipe::MemoryOutputPipe;
40+
use wasmtime_wasi::{ResourceTable, WasiCtx, WasiCtxBuilder, WasiCtxView, WasiView};
4141

4242
pub use test_key_value::KeyValueReport;
4343
pub use test_llm::LlmReport;
@@ -60,8 +60,7 @@ mod test_wasi;
6060
wasmtime::component::bindgen!({
6161
path: "../../wit",
6262
world: "fermyon:spin/host",
63-
async: true,
64-
trappable_imports: true,
63+
imports: { default: async | trappable },
6564
});
6665
pub use fermyon::spin::*;
6766

@@ -264,15 +263,12 @@ impl Context {
264263
}
265264
}
266265

267-
impl IoView for Context {
268-
fn table(&mut self) -> &mut ResourceTable {
269-
&mut self.table
270-
}
271-
}
272-
273266
impl WasiView for Context {
274-
fn ctx(&mut self) -> &mut WasiCtx {
275-
&mut self.wasi
267+
fn ctx(&mut self) -> WasiCtxView<'_> {
268+
WasiCtxView {
269+
ctx: &mut self.wasi,
270+
table: &mut self.table,
271+
}
276272
}
277273
}
278274

@@ -321,7 +317,7 @@ async fn run_command(
321317
// ownership once we return.
322318
let table = ResourceTable::new();
323319
store.data_mut().wasi = WasiCtxBuilder::new().build();
324-
*store.data_mut().table() = table;
320+
*store.data_mut().ctx().table = table;
325321
let stderr =
326322
std::mem::replace(&mut store.data_mut().stderr, MemoryOutputPipe::new(1024));
327323

crates/componentize/src/lib.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,8 @@ mod tests {
267267
component::{Component, Linker},
268268
Config, Engine, Store,
269269
},
270-
wasmtime_wasi::p2::{
271-
bindings::Command, pipe::MemoryInputPipe, IoView, WasiCtx, WasiCtxBuilder, WasiView,
272-
},
273-
wasmtime_wasi::ResourceTable,
270+
wasmtime_wasi::p2::{bindings::Command, pipe::MemoryInputPipe},
271+
wasmtime_wasi::{ResourceTable, WasiCtx, WasiCtxBuilder, WasiCtxView, WasiView},
274272
};
275273

276274
async fn run_spin(module: &[u8]) -> Result<()> {
@@ -359,14 +357,12 @@ mod tests {
359357
ctx: WasiCtx,
360358
table: ResourceTable,
361359
}
362-
impl IoView for Wasi {
363-
fn table(&mut self) -> &mut ResourceTable {
364-
&mut self.table
365-
}
366-
}
367360
impl WasiView for Wasi {
368-
fn ctx(&mut self) -> &mut WasiCtx {
369-
&mut self.ctx
361+
fn ctx(&mut self) -> WasiCtxView<'_> {
362+
WasiCtxView {
363+
ctx: &mut self.ctx,
364+
table: &mut self.table,
365+
}
370366
}
371367
}
372368

crates/factor-outbound-http/src/wasi.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use tokio_rustls::client::TlsStream;
3232
use tower_service::Service;
3333
use tracing::{field::Empty, instrument, Instrument};
3434
use wasmtime::component::HasData;
35-
use wasmtime_wasi::p2::{IoImpl, IoView};
3635
use wasmtime_wasi_http::{
3736
bindings::http::types::ErrorCode,
3837
body::HyperOutgoingBody,
@@ -60,7 +59,7 @@ where
6059
C: spin_factors::InitContext<OutboundHttpFactor>,
6160
{
6261
let (state, table) = C::get_data_with_table(store);
63-
WasiHttpImpl(IoImpl(WasiHttpImplInner { state, table }))
62+
WasiHttpImpl(WasiHttpImplInner { state, table })
6463
}
6564
let get_http = get_http::<C> as fn(&mut C::StoreData) -> WasiHttpImpl<WasiHttpImplInner<'_>>;
6665
let linker = ctx.linker();
@@ -84,7 +83,7 @@ impl OutboundHttpFactor {
8483
runtime_instance_state: &mut impl RuntimeFactorsInstanceState,
8584
) -> Option<WasiHttpImpl<impl WasiHttpView + '_>> {
8685
let (state, table) = runtime_instance_state.get_with_table::<OutboundHttpFactor>()?;
87-
Some(WasiHttpImpl(IoImpl(WasiHttpImplInner { state, table })))
86+
Some(WasiHttpImpl(WasiHttpImplInner { state, table }))
8887
}
8988
}
9089

@@ -123,17 +122,15 @@ pub(crate) struct WasiHttpImplInner<'a> {
123122
table: &'a mut ResourceTable,
124123
}
125124

126-
impl IoView for WasiHttpImplInner<'_> {
127-
fn table(&mut self) -> &mut ResourceTable {
128-
self.table
129-
}
130-
}
131-
132125
impl WasiHttpView for WasiHttpImplInner<'_> {
133126
fn ctx(&mut self) -> &mut WasiHttpCtx {
134127
&mut self.state.wasi_http_ctx
135128
}
136129

130+
fn table(&mut self) -> &mut ResourceTable {
131+
self.table
132+
}
133+
137134
#[instrument(
138135
name = "spin_outbound_http.send_request",
139136
skip_all,

crates/factor-outbound-http/src/wasi_2023_10_18.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ mod bindings {
99
wasmtime::component::bindgen!({
1010
path: "../../wit",
1111
world: "wasi:http/[email protected]",
12-
async: {
13-
// Only need async exports
14-
only_imports: [],
15-
},
12+
imports: { default: trappable },
13+
exports: { default: async },
1614
with: {
1715
"wasi:io/poll/pollable": latest::io::poll::Pollable,
1816
"wasi:io/streams/input-stream": latest::io::streams::InputStream,
@@ -29,7 +27,6 @@ mod bindings {
2927
"wasi:http/types/future-incoming-response": latest::http::types::FutureIncomingResponse,
3028
"wasi:http/types/future-trailers": latest::http::types::FutureTrailers,
3129
},
32-
trappable_imports: true,
3330
});
3431
}
3532

crates/factor-outbound-http/src/wasi_2023_11_10.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ mod bindings {
1212
wasmtime::component::bindgen!({
1313
path: "../../wit",
1414
world: "wasi:http/[email protected]",
15-
async: {
16-
// Only need async exports
17-
only_imports: [],
18-
},
15+
imports: { default: trappable },
16+
exports: { default: async },
1917
with: {
2018
"wasi:io/poll/pollable": latest::io::poll::Pollable,
2119
"wasi:io/streams/input-stream": latest::io::streams::InputStream,
@@ -33,7 +31,6 @@ mod bindings {
3331
"wasi:http/types/future-trailers": latest::http::types::FutureTrailers,
3432
"wasi:http/types/request-options": latest::http::types::RequestOptions,
3533
},
36-
trappable_imports: true,
3734
});
3835
}
3936

crates/factor-outbound-networking/tests/factor_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use spin_factor_variables::VariablesFactor;
44
use spin_factor_wasi::{DummyFilesMounter, WasiFactor};
55
use spin_factors::{anyhow, RuntimeFactors};
66
use spin_factors_test::{toml, TestEnvironment};
7-
use wasmtime_wasi::p2::{bindings::sockets::instance_network::Host, IoView};
7+
use wasmtime_wasi::p2::bindings::sockets::instance_network::Host;
88
use wasmtime_wasi::SocketAddrUse;
99

1010
#[derive(RuntimeFactors)]
@@ -38,7 +38,7 @@ async fn configures_wasi_socket_addr_check() -> anyhow::Result<()> {
3838
let mut wasi = WasiFactor::get_wasi_impl(&mut state).unwrap();
3939

4040
let network_resource = wasi.instance_network()?;
41-
let network = wasi.table().get(&network_resource)?;
41+
let network = wasi.table.get(&network_resource)?;
4242

4343
network
4444
.check_socket_addr(

crates/factor-wasi/src/io.rs

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use std::io::{Read, Write};
1+
use std::io::{self, Read, Write};
2+
use std::pin::Pin;
23
use std::sync::{Arc, Mutex};
4+
use std::task::{Context, Poll};
35

46
use async_trait::async_trait;
57
use spin_factors::anyhow;
6-
use wasmtime_wasi::p2::{
7-
InputStream, OutputStream, Pollable, StdinStream, StdoutStream, StreamError,
8-
};
8+
use tokio::io::{AsyncRead, AsyncWrite};
9+
use wasmtime_wasi::cli::{IsTerminal, StdinStream, StdoutStream};
10+
use wasmtime_wasi::p2::{InputStream, OutputStream, Pollable, StreamError};
911

1012
/// A [`OutputStream`] that writes to a `Write` type.
1113
///
@@ -54,16 +56,37 @@ impl<T: Write + Send + Sync + 'static> OutputStream for PipedWriteStream<T> {
5456
}
5557
}
5658

57-
impl<T: Write + Send + Sync + 'static> StdoutStream for PipedWriteStream<T> {
58-
fn stream(&self) -> Box<dyn OutputStream> {
59-
Box::new(self.clone())
59+
impl<T: Write + Send + Sync + 'static> AsyncWrite for PipedWriteStream<T> {
60+
fn poll_write(
61+
self: Pin<&mut Self>,
62+
_cx: &mut Context<'_>,
63+
buf: &[u8],
64+
) -> Poll<io::Result<usize>> {
65+
Poll::Ready(self.0.lock().unwrap().write(buf))
66+
}
67+
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
68+
Poll::Ready(self.0.lock().unwrap().flush())
6069
}
70+
fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
71+
Poll::Ready(Ok(()))
72+
}
73+
}
6174

62-
fn isatty(&self) -> bool {
75+
impl<T> IsTerminal for PipedWriteStream<T> {
76+
fn is_terminal(&self) -> bool {
6377
false
6478
}
6579
}
6680

81+
impl<T: Write + Send + Sync + 'static> StdoutStream for PipedWriteStream<T> {
82+
fn p2_stream(&self) -> Box<dyn OutputStream> {
83+
Box::new(self.clone())
84+
}
85+
fn async_stream(&self) -> Box<dyn AsyncWrite + Send + Sync> {
86+
Box::new(self.clone())
87+
}
88+
}
89+
6790
#[async_trait]
6891
impl<T: Write + Send + Sync + 'static> Pollable for PipedWriteStream<T> {
6992
async fn ready(&mut self) {}
@@ -95,6 +118,12 @@ impl<T> Clone for PipeReadStream<T> {
95118
}
96119
}
97120

121+
impl<T> IsTerminal for PipeReadStream<T> {
122+
fn is_terminal(&self) -> bool {
123+
false
124+
}
125+
}
126+
98127
impl<T: Read + Send + Sync + 'static> InputStream for PipeReadStream<T> {
99128
fn read(&mut self, size: usize) -> wasmtime_wasi::p2::StreamResult<bytes::Bytes> {
100129
let size = size.min(self.buffer.len());
@@ -113,17 +142,33 @@ impl<T: Read + Send + Sync + 'static> InputStream for PipeReadStream<T> {
113142
}
114143
}
115144

145+
impl<T: Read + Send + Sync + 'static> AsyncRead for PipeReadStream<T> {
146+
fn poll_read(
147+
self: Pin<&mut Self>,
148+
_cx: &mut Context<'_>,
149+
buf: &mut tokio::io::ReadBuf<'_>,
150+
) -> Poll<io::Result<()>> {
151+
let result = self
152+
.inner
153+
.lock()
154+
.unwrap()
155+
.read(buf.initialize_unfilled())
156+
.map(|n| buf.advance(n));
157+
Poll::Ready(result)
158+
}
159+
}
160+
116161
#[async_trait]
117162
impl<T: Read + Send + Sync + 'static> Pollable for PipeReadStream<T> {
118163
async fn ready(&mut self) {}
119164
}
120165

121166
impl<T: Read + Send + Sync + 'static> StdinStream for PipeReadStream<T> {
122-
fn stream(&self) -> Box<dyn InputStream> {
167+
fn p2_stream(&self) -> Box<dyn InputStream> {
123168
Box::new(self.clone())
124169
}
125170

126-
fn isatty(&self) -> bool {
127-
false
171+
fn async_stream(&self) -> Box<dyn AsyncRead + Send + Sync> {
172+
Box::new(self.clone())
128173
}
129174
}

0 commit comments

Comments
 (0)