Skip to content

Commit 1154682

Browse files
authored
Merge pull request #2887 from itowlson/world3
Spin 3 world
2 parents ed8ab6f + fd4c89e commit 1154682

File tree

15 files changed

+76
-58
lines changed

15 files changed

+76
-58
lines changed

crates/world/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ wasmtime::component::bindgen!({
88
world host {
99
include fermyon:spin/host;
1010
include fermyon:spin/[email protected];
11+
include fermyon:spin/[email protected];
1112
}
1213
"#,
1314
path: "../../wit",

tests/test-components/components/tcp-sockets/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bindings::wasi::{
2-
io0_2_0_rc_2023_10_18::poll,
3-
sockets0_2_0_rc_2023_10_18::{
2+
io0_2_0::poll,
3+
sockets0_2_0::{
44
instance_network,
55
network::{
66
ErrorCode, IpAddressFamily, IpSocketAddress, Ipv4SocketAddress, Ipv6SocketAddress,
@@ -43,7 +43,7 @@ impl Component {
4343

4444
let (rx, tx) = loop {
4545
match client.finish_connect() {
46-
Err(ErrorCode::WouldBlock) => poll::poll_one(&client.subscribe()),
46+
Err(ErrorCode::WouldBlock) => { poll::poll(&[&client.subscribe()]); },
4747
result => break ensure_ok!(result),
4848
}
4949
};

tests/test-components/helper/src/lib.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#[cfg(feature = "define-component")]
22
pub mod bindings {
33
wit_bindgen::generate!({
4-
world: "platform-rc20231018",
4+
world: "fermyon:spin/platform@3.0.0",
55
path: "../../../wit",
66
runtime_path: "::wit_bindgen::rt"
77
});
88
}
99

1010
#[cfg(feature = "define-component")]
11-
use bindings::wasi::http0_2_0_rc_2023_10_18::types::{
12-
Error, Headers, OutgoingBody, OutgoingResponse, ResponseOutparam,
11+
use bindings::wasi::http0_2_0::types::{
12+
ErrorCode, Fields, OutgoingBody, OutgoingResponse, ResponseOutparam,
1313
};
1414
#[cfg(feature = "define-component")]
15-
use bindings::wasi::io0_2_0_rc_2023_10_18::streams::OutputStream;
15+
use bindings::wasi::io0_2_0::streams::OutputStream;
1616

1717
#[cfg(feature = "define-component")]
1818
#[macro_export]
@@ -23,15 +23,15 @@ macro_rules! define_component {
2323
// For now, this assumes the crate using this macro has `wit-bindgen` as a dependency
2424
mod bindings {
2525
$crate::wit_bindgen::generate!({
26-
world: "http-trigger-rc20231018",
26+
world: "fermyon:spin/http-trigger@3.0.0",
2727
path: "../../../../wit",
2828
exports: {
29-
"wasi:http/[email protected]-rc-2023-10-18": super::Component
29+
"wasi:http/[email protected]": super::Component
3030
},
3131
});
3232
}
3333

34-
use bindings::exports::wasi::http0_2_0_rc_2023_10_18::incoming_handler::{Guest, IncomingRequest, ResponseOutparam};
34+
use bindings::exports::wasi::http0_2_0::incoming_handler::{Guest, IncomingRequest, ResponseOutparam};
3535
struct $name;
3636

3737
impl Guest for $name {
@@ -40,7 +40,7 @@ macro_rules! define_component {
4040
}
4141
}
4242

43-
impl From<ResponseOutparam> for $crate::bindings::wasi::http0_2_0_rc_2023_10_18::types::ResponseOutparam {
43+
impl From<ResponseOutparam> for $crate::bindings::wasi::http0_2_0::types::ResponseOutparam {
4444
fn from(value: ResponseOutparam) -> Self {
4545
unsafe { Self::from_handle(value.into_handle()) }
4646
}
@@ -50,27 +50,31 @@ macro_rules! define_component {
5050

5151
#[cfg(feature = "define-component")]
5252
pub fn handle(response_out: ResponseOutparam, result: Result<(), String>) {
53-
let response = |status| OutgoingResponse::new(status, &Headers::new(&[]));
53+
let response = |status| {
54+
let resp = OutgoingResponse::new(Fields::new());
55+
resp.set_status_code(status).expect("should have set status code");
56+
resp
57+
};
5458
match result {
5559
Ok(()) => ResponseOutparam::set(response_out, Ok(response(200))),
5660
Err(err) => {
5761
let resp = response(500);
58-
let body = resp.write().expect("response body was already taken");
62+
let body = resp.body().unwrap();
5963
ResponseOutparam::set(response_out, Ok(resp));
6064
outgoing_body(body, err.into_bytes()).unwrap();
6165
}
6266
}
6367
}
6468

6569
#[cfg(feature = "define-component")]
66-
pub fn outgoing_body(body: OutgoingBody, buffer: Vec<u8>) -> Result<(), Error> {
70+
pub fn outgoing_body(body: OutgoingBody, buffer: Vec<u8>) -> Result<(), ErrorCode> {
6771
struct Outgoing(Option<(OutputStream, OutgoingBody)>);
6872

6973
impl Drop for Outgoing {
7074
fn drop(&mut self) {
7175
if let Some((stream, body)) = self.0.take() {
7276
drop(stream);
73-
OutgoingBody::finish(body, None);
77+
OutgoingBody::finish(body, None).expect("should have finished OutgoingBody");
7478
}
7579
}
7680
}
@@ -101,11 +105,11 @@ pub fn outgoing_body(body: OutgoingBody, buffer: Vec<u8>) -> Result<(), Error> {
101105
Ok(()) => {
102106
offset += count;
103107
}
104-
Err(e) => return Err(Error::ProtocolError(format!("I/O error: {e}"))),
108+
Err(e) => return Err(ErrorCode::InternalError(Some(format!("I/O error: {e}")))),
105109
}
106110
}
107111
}
108-
Err(e) => return Err(Error::ProtocolError(format!("I/O error: {e}"))),
112+
Err(e) => return Err(ErrorCode::InternalError(Some(format!("I/O error: {e}")))),
109113
}
110114
}
111115
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)