Skip to content

Commit ce5b13b

Browse files
committed
Update to Wasmtime 21.0.0
This commit updates Wasmtime to 21.0.0 from the previous 20.0.2 version. Notable changes here are handling refactorings around `wasmtime-wasi-http` and its types there in addition to how some traits are handled in the `wasmtime-wasi` crate. Signed-off-by: Alex Crichton <[email protected]>
1 parent e078f8d commit ce5b13b

File tree

9 files changed

+318
-306
lines changed

9 files changed

+318
-306
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ hyper = { version = "1.0.0", features = ["full"] }
126126
reqwest = { version = "0.11", features = ["stream", "blocking"] }
127127
tracing = { version = "0.1", features = ["log"] }
128128

129-
wasi-common-preview1 = { version = "20.0.2", package = "wasi-common", features = ["tokio"] }
130-
wasmtime = "20.0.2"
131-
wasmtime-wasi = "20.0.2"
132-
wasmtime-wasi-http = "20.0.2"
129+
wasi-common-preview1 = { version = "21.0.0", package = "wasi-common", features = ["tokio"] }
130+
wasmtime = "21.0.0"
131+
wasmtime-wasi = "21.0.0"
132+
wasmtime-wasi-http = "21.0.0"
133133

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

crates/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cap-primitives = "3.0.0"
1919
tokio = "1.0"
2020
bytes = "1.0"
2121
spin-telemetry = { path = "../telemetry" }
22+
http = "1.0"
2223

2324
[target.'cfg(unix)'.dependencies]
2425
rustix = "0.37.19"

crates/core/src/lib.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ use std::{path::PathBuf, time::Duration};
2020

2121
use anyhow::Result;
2222
use crossbeam_channel::Sender;
23+
use http::Request;
2324
use tracing::{field::Empty, instrument};
2425
use wasmtime::{InstanceAllocationStrategy, PoolingAllocationConfig};
2526
use wasmtime_wasi::ResourceTable;
27+
use wasmtime_wasi_http::body::HyperOutgoingBody;
2628
use wasmtime_wasi_http::types::{default_send_request, WasiHttpCtx, WasiHttpView};
2729

2830
use self::host_component::{HostComponents, HostComponentsBuilder};
@@ -256,18 +258,29 @@ impl<T: Send + OutboundWasiHttpHandler> WasiHttpView for Data<T> {
256258
&mut self.table
257259
}
258260

259-
#[instrument(name = "spin_core.send_request", skip_all, fields(otel.kind = "client", url.full = %request.request.uri(), http.request.method = %request.request.method(), otel.name = %request.request.method(), http.response.status_code = Empty, server.address = Empty, server.port = Empty))]
261+
#[instrument(
262+
name = "spin_core.send_request",
263+
skip_all,
264+
fields(
265+
otel.kind = "client",
266+
url.full = %request.uri(),
267+
http.request.method = %request.method(),
268+
otel.name = %request.method(),
269+
http.response.status_code = Empty,
270+
server.address = Empty,
271+
server.port = Empty,
272+
),
273+
)]
260274
fn send_request(
261275
&mut self,
262-
mut request: wasmtime_wasi_http::types::OutgoingRequest,
263-
) -> wasmtime_wasi_http::HttpResult<
264-
wasmtime::component::Resource<wasmtime_wasi_http::types::HostFutureIncomingResponse>,
265-
>
276+
mut request: Request<HyperOutgoingBody>,
277+
config: wasmtime_wasi_http::types::OutgoingRequestConfig,
278+
) -> wasmtime_wasi_http::HttpResult<wasmtime_wasi_http::types::HostFutureIncomingResponse>
266279
where
267280
Self: Sized,
268281
{
269-
spin_telemetry::inject_trace_context(&mut request.request);
270-
T::send_request(self, request)
282+
spin_telemetry::inject_trace_context(&mut request);
283+
T::send_request(self, request, config)
271284
}
272285
}
273286

@@ -276,25 +289,23 @@ pub trait OutboundWasiHttpHandler {
276289
/// Send the request
277290
fn send_request(
278291
data: &mut Data<Self>,
279-
request: wasmtime_wasi_http::types::OutgoingRequest,
280-
) -> wasmtime_wasi_http::HttpResult<
281-
wasmtime::component::Resource<wasmtime_wasi_http::types::HostFutureIncomingResponse>,
282-
>
292+
request: Request<HyperOutgoingBody>,
293+
config: wasmtime_wasi_http::types::OutgoingRequestConfig,
294+
) -> wasmtime_wasi_http::HttpResult<wasmtime_wasi_http::types::HostFutureIncomingResponse>
283295
where
284296
Self: Sized;
285297
}
286298

287299
impl OutboundWasiHttpHandler for () {
288300
fn send_request(
289-
data: &mut Data<Self>,
290-
request: wasmtime_wasi_http::types::OutgoingRequest,
291-
) -> wasmtime_wasi_http::HttpResult<
292-
wasmtime::component::Resource<wasmtime_wasi_http::types::HostFutureIncomingResponse>,
293-
>
301+
_data: &mut Data<Self>,
302+
request: Request<HyperOutgoingBody>,
303+
config: wasmtime_wasi_http::types::OutgoingRequestConfig,
304+
) -> wasmtime_wasi_http::HttpResult<wasmtime_wasi_http::types::HostFutureIncomingResponse>
294305
where
295306
Self: Sized,
296307
{
297-
default_send_request(data, request)
308+
Ok(default_send_request(request, config))
298309
}
299310
}
300311

crates/core/src/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ impl WasiCtxBuilder {
610610
WasiCtxBuilder::Preview1(ctx) => Wasi::Preview1(ctx),
611611
WasiCtxBuilder::Preview2(mut b) => Wasi::Preview2 {
612612
wasi_ctx: b.build(),
613-
wasi_http_ctx: WasiHttpCtx,
613+
wasi_http_ctx: WasiHttpCtx::new(),
614614
},
615615
}
616616
}

crates/core/src/wasi_2023_10_18.rs

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ mod bindings {
102102
"wasi:http/types/future-incoming-response": latest::http::types::FutureIncomingResponse,
103103
"wasi:http/types/future-trailers": latest::http::types::FutureTrailers,
104104
},
105+
trappable_imports: true,
106+
skip_mut_forwarding_impls: true,
105107
});
106108
}
107109

@@ -149,35 +151,42 @@ where
149151
T: WasiView + WasiHttpView,
150152
{
151153
// interfaces from the "command" world
152-
wasi::clocks::monotonic_clock::add_to_linker(linker, |t| t)?;
153-
wasi::clocks::wall_clock::add_to_linker(linker, |t| t)?;
154-
wasi::filesystem::types::add_to_linker(linker, |t| t)?;
155-
wasi::filesystem::preopens::add_to_linker(linker, |t| t)?;
156-
wasi::io::poll::add_to_linker(linker, |t| t)?;
157-
wasi::io::streams::add_to_linker(linker, |t| t)?;
158-
wasi::random::random::add_to_linker(linker, |t| t)?;
159-
wasi::random::insecure::add_to_linker(linker, |t| t)?;
160-
wasi::random::insecure_seed::add_to_linker(linker, |t| t)?;
161-
wasi::cli::exit::add_to_linker(linker, |t| t)?;
162-
wasi::cli::environment::add_to_linker(linker, |t| t)?;
163-
wasi::cli::stdin::add_to_linker(linker, |t| t)?;
164-
wasi::cli::stdout::add_to_linker(linker, |t| t)?;
165-
wasi::cli::stderr::add_to_linker(linker, |t| t)?;
166-
wasi::cli::terminal_input::add_to_linker(linker, |t| t)?;
167-
wasi::cli::terminal_output::add_to_linker(linker, |t| t)?;
168-
wasi::cli::terminal_stdin::add_to_linker(linker, |t| t)?;
169-
wasi::cli::terminal_stdout::add_to_linker(linker, |t| t)?;
170-
wasi::cli::terminal_stderr::add_to_linker(linker, |t| t)?;
171-
wasi::sockets::tcp::add_to_linker(linker, |t| t)?;
172-
wasi::sockets::tcp_create_socket::add_to_linker(linker, |t| t)?;
173-
wasi::sockets::udp::add_to_linker(linker, |t| t)?;
174-
wasi::sockets::udp_create_socket::add_to_linker(linker, |t| t)?;
175-
wasi::sockets::instance_network::add_to_linker(linker, |t| t)?;
176-
wasi::sockets::network::add_to_linker(linker, |t| t)?;
177-
wasi::sockets::ip_name_lookup::add_to_linker(linker, |t| t)?;
178-
179-
wasi::http::types::add_to_linker(linker, |t| t)?;
180-
wasi::http::outgoing_handler::add_to_linker(linker, |t| t)?;
154+
fn project<T, F>(f: F) -> F
155+
where
156+
F: Fn(&mut T) -> &mut T,
157+
{
158+
f
159+
}
160+
let closure = project::<T, _>(|t| t);
161+
wasi::clocks::monotonic_clock::add_to_linker_get_host(linker, closure)?;
162+
wasi::clocks::wall_clock::add_to_linker_get_host(linker, closure)?;
163+
wasi::filesystem::types::add_to_linker_get_host(linker, closure)?;
164+
wasi::filesystem::preopens::add_to_linker_get_host(linker, closure)?;
165+
wasi::io::poll::add_to_linker_get_host(linker, closure)?;
166+
wasi::io::streams::add_to_linker_get_host(linker, closure)?;
167+
wasi::random::random::add_to_linker_get_host(linker, closure)?;
168+
wasi::random::insecure::add_to_linker_get_host(linker, closure)?;
169+
wasi::random::insecure_seed::add_to_linker_get_host(linker, closure)?;
170+
wasi::cli::exit::add_to_linker_get_host(linker, closure)?;
171+
wasi::cli::environment::add_to_linker_get_host(linker, closure)?;
172+
wasi::cli::stdin::add_to_linker_get_host(linker, closure)?;
173+
wasi::cli::stdout::add_to_linker_get_host(linker, closure)?;
174+
wasi::cli::stderr::add_to_linker_get_host(linker, closure)?;
175+
wasi::cli::terminal_input::add_to_linker_get_host(linker, closure)?;
176+
wasi::cli::terminal_output::add_to_linker_get_host(linker, closure)?;
177+
wasi::cli::terminal_stdin::add_to_linker_get_host(linker, closure)?;
178+
wasi::cli::terminal_stdout::add_to_linker_get_host(linker, closure)?;
179+
wasi::cli::terminal_stderr::add_to_linker_get_host(linker, closure)?;
180+
wasi::sockets::tcp::add_to_linker_get_host(linker, closure)?;
181+
wasi::sockets::tcp_create_socket::add_to_linker_get_host(linker, closure)?;
182+
wasi::sockets::udp::add_to_linker_get_host(linker, closure)?;
183+
wasi::sockets::udp_create_socket::add_to_linker_get_host(linker, closure)?;
184+
wasi::sockets::instance_network::add_to_linker_get_host(linker, closure)?;
185+
wasi::sockets::network::add_to_linker_get_host(linker, closure)?;
186+
wasi::sockets::ip_name_lookup::add_to_linker_get_host(linker, closure)?;
187+
188+
wasi::http::types::add_to_linker_get_host(linker, closure)?;
189+
wasi::http::outgoing_handler::add_to_linker_get_host(linker, closure)?;
181190
Ok(())
182191
}
183192

@@ -1694,11 +1703,11 @@ where
16941703
}
16951704
}
16961705

1697-
impl<T> wasi::http::types::Host for T where T: WasiHttpView {}
1706+
impl<T> wasi::http::types::Host for T where T: WasiHttpView + Send {}
16981707

16991708
impl<T> wasi::http::types::HostFields for T
17001709
where
1701-
T: WasiHttpView,
1710+
T: WasiHttpView + Send,
17021711
{
17031712
fn new(
17041713
&mut self,
@@ -1768,7 +1777,7 @@ where
17681777

17691778
impl<T> wasi::http::types::HostIncomingRequest for T
17701779
where
1771-
T: WasiHttpView,
1780+
T: WasiHttpView + Send,
17721781
{
17731782
fn method(
17741783
&mut self,
@@ -1823,7 +1832,7 @@ where
18231832

18241833
impl<T> wasi::http::types::HostIncomingResponse for T
18251834
where
1826-
T: WasiHttpView,
1835+
T: WasiHttpView + Send,
18271836
{
18281837
fn status(
18291838
&mut self,
@@ -1856,7 +1865,7 @@ where
18561865

18571866
impl<T> wasi::http::types::HostIncomingBody for T
18581867
where
1859-
T: WasiHttpView,
1868+
T: WasiHttpView + Send,
18601869
{
18611870
fn stream(
18621871
&mut self,
@@ -1879,7 +1888,7 @@ where
18791888

18801889
impl<T> wasi::http::types::HostOutgoingRequest for T
18811890
where
1882-
T: WasiHttpView,
1891+
T: WasiHttpView + Send,
18831892
{
18841893
fn new(
18851894
&mut self,
@@ -1956,7 +1965,7 @@ where
19561965

19571966
impl<T> wasi::http::types::HostOutgoingResponse for T
19581967
where
1959-
T: WasiHttpView,
1968+
T: WasiHttpView + Send,
19601969
{
19611970
fn new(
19621971
&mut self,
@@ -1996,7 +2005,7 @@ where
19962005

19972006
impl<T> wasi::http::types::HostOutgoingBody for T
19982007
where
1999-
T: WasiHttpView,
2008+
T: WasiHttpView + Send,
20002009
{
20012010
fn write(
20022011
&mut self,
@@ -2021,7 +2030,7 @@ where
20212030

20222031
impl<T> wasi::http::types::HostResponseOutparam for T
20232032
where
2024-
T: WasiHttpView,
2033+
T: WasiHttpView + Send,
20252034
{
20262035
fn set(
20272036
&mut self,
@@ -2053,7 +2062,7 @@ where
20532062

20542063
impl<T> wasi::http::types::HostFutureTrailers for T
20552064
where
2056-
T: WasiHttpView,
2065+
T: WasiHttpView + Send,
20572066
{
20582067
fn subscribe(
20592068
&mut self,
@@ -2084,7 +2093,7 @@ where
20842093

20852094
impl<T> wasi::http::types::HostFutureIncomingResponse for T
20862095
where
2087-
T: WasiHttpView,
2096+
T: WasiHttpView + Send,
20882097
{
20892098
fn get(
20902099
&mut self,
@@ -2117,7 +2126,7 @@ where
21172126

21182127
impl<T> wasi::http::outgoing_handler::Host for T
21192128
where
2120-
T: WasiHttpView,
2129+
T: WasiHttpView + Send,
21212130
{
21222131
fn handle(
21232132
&mut self,

0 commit comments

Comments
 (0)