Skip to content

Commit d122fec

Browse files
committed
switch from using wasi crate to wasip2
1 parent 8158a83 commit d122fec

23 files changed

+83
-83
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ http.workspace = true
2222
itoa.workspace = true
2323
pin-project-lite.workspace = true
2424
slab.workspace = true
25-
wasi.workspace = true
25+
wasip2.workspace = true
2626
wstd-macro.workspace = true
2727

2828
# optional
@@ -83,7 +83,7 @@ test-log = { version = "0.2", features = ["trace"] }
8383
test-programs = { path = "test-programs" }
8484
test-programs-artifacts = { path = "test-programs/artifacts" }
8585
ureq = { version = "2.12.1", default-features = false }
86-
wasi = "0.14.0"
86+
wasip2 = "1.0"
8787
wstd = { path = "." }
8888
wstd-macro = { path = "macro", version = "=0.5.4" }
8989

macro/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ pub fn attr_macro_http_server(_attr: TokenStream, item: TokenStream) -> TokenStr
126126
quote! {
127127
struct TheServer;
128128

129-
impl ::wstd::wasi::exports::http::incoming_handler::Guest for TheServer {
129+
impl ::wstd::wasip2::exports::http::incoming_handler::Guest for TheServer {
130130
fn handle(
131-
request: ::wstd::wasi::http::types::IncomingRequest,
132-
response_out: ::wstd::wasi::http::types::ResponseOutparam
131+
request: ::wstd::wasip2::http::types::IncomingRequest,
132+
response_out: ::wstd::wasip2::http::types::ResponseOutparam
133133
) {
134134
#(#attrs)*
135135
#vis async fn __run(#inputs) #output {
@@ -146,7 +146,7 @@ pub fn attr_macro_http_server(_attr: TokenStream, item: TokenStream) -> TokenStr
146146
}
147147
}
148148

149-
::wstd::wasi::http::proxy::export!(TheServer with_types_in ::wstd::wasi);
149+
::wstd::wasip2::http::proxy::export!(TheServer with_types_in ::wstd::wasi);
150150

151151
// Provide an actual function named `main`.
152152
//

src/http/body.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::io::{AsyncInputStream, AsyncOutputStream, AsyncRead, AsyncWrite, Curs
55
use crate::runtime::AsyncPollable;
66
use core::fmt;
77
use http::header::CONTENT_LENGTH;
8-
use wasi::http::types::IncomingBody as WasiIncomingBody;
8+
use wasip2::http::types::IncomingBody as WasiIncomingBody;
99

1010
#[cfg(feature = "json")]
1111
use serde::de::DeserializeOwned;
@@ -274,20 +274,20 @@ pub struct OutgoingBody {
274274
// IMPORTANT: the order of these fields here matters. `stream` must
275275
// be dropped before `body`.
276276
stream: AsyncOutputStream,
277-
body: wasi::http::types::OutgoingBody,
277+
body: wasip2::http::types::OutgoingBody,
278278
dontdrop: DontDropOutgoingBody,
279279
}
280280

281281
impl OutgoingBody {
282-
pub(crate) fn new(stream: AsyncOutputStream, body: wasi::http::types::OutgoingBody) -> Self {
282+
pub(crate) fn new(stream: AsyncOutputStream, body: wasip2::http::types::OutgoingBody) -> Self {
283283
Self {
284284
stream,
285285
body,
286286
dontdrop: DontDropOutgoingBody,
287287
}
288288
}
289289

290-
pub(crate) fn consume(self) -> (AsyncOutputStream, wasi::http::types::OutgoingBody) {
290+
pub(crate) fn consume(self) -> (AsyncOutputStream, wasip2::http::types::OutgoingBody) {
291291
let Self {
292292
stream,
293293
body,

src/http/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use pin_project_lite::pin_project;
1212
use std::future::Future;
1313
use std::pin::Pin;
1414
use std::task::{Context, Poll};
15-
use wasi::http::types::{
15+
use wasip2::http::types::{
1616
FutureIncomingResponse as WasiFutureIncomingResponse, OutgoingBody as WasiOutgoingBody,
1717
RequestOptions as WasiRequestOptions,
1818
};
@@ -50,7 +50,7 @@ impl Client {
5050
let wasi_stream = wasi_body.write().unwrap();
5151

5252
// 1. Start sending the request head
53-
let res = wasi::http::outgoing_handler::handle(wasi_req, self.wasi_options()?).unwrap();
53+
let res = wasip2::http::outgoing_handler::handle(wasi_req, self.wasi_options()?).unwrap();
5454

5555
// 2. Start sending the request body
5656
io::copy(body, AsyncOutputStream::new(wasi_stream)).await?;
@@ -86,7 +86,7 @@ impl Client {
8686
let wasi_stream = wasi_body.write().unwrap();
8787

8888
// Start sending the request head.
89-
let res = wasi::http::outgoing_handler::handle(wasi_req, self.wasi_options()?).unwrap();
89+
let res = wasip2::http::outgoing_handler::handle(wasi_req, self.wasi_options()?).unwrap();
9090

9191
let outgoing_body = OutgoingBody::new(AsyncOutputStream::new(wasi_stream), wasi_body);
9292

@@ -141,7 +141,7 @@ impl Client {
141141
None => None,
142142
};
143143

144-
wasi::http::types::OutgoingBody::finish(body, wasi_trailers)
144+
wasip2::http::types::OutgoingBody::finish(body, wasi_trailers)
145145
.expect("body length did not match Content-Length header value");
146146
Ok(())
147147
}

src/http/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Error {
1212

1313
pub use http::header::{InvalidHeaderName, InvalidHeaderValue};
1414
pub use http::method::InvalidMethod;
15-
pub use wasi::http::types::{ErrorCode as WasiHttpErrorCode, HeaderError as WasiHttpHeaderError};
15+
pub use wasip2::http::types::{ErrorCode as WasiHttpErrorCode, HeaderError as WasiHttpHeaderError};
1616

1717
impl fmt::Debug for Error {
1818
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

src/http/fields.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub use http::header::{HeaderMap, HeaderName, HeaderValue};
22

33
use super::Error;
4-
use wasi::http::types::{Fields, HeaderError as WasiHttpHeaderError};
4+
use wasip2::http::types::{Fields, HeaderError as WasiHttpHeaderError};
55

66
pub(crate) fn header_map_from_wasi(wasi_fields: Fields) -> Result<HeaderMap, Error> {
77
let mut output = HeaderMap::new();

src/http/method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use wasi::http::types::Method as WasiMethod;
1+
use wasip2::http::types::Method as WasiMethod;
22

33
use http::method::InvalidMethod;
44
pub use http::Method;

src/http/request.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use super::{
77
Authority, Error, HeaderMap, PathAndQuery, Uri,
88
};
99
use crate::io::AsyncInputStream;
10-
use wasi::http::outgoing_handler::OutgoingRequest;
11-
use wasi::http::types::IncomingRequest;
10+
use wasip2::http::outgoing_handler::OutgoingRequest;
11+
use wasip2::http::types::IncomingRequest;
1212

1313
pub use http::request::{Builder, Request};
1414

@@ -71,7 +71,7 @@ pub(crate) fn try_into_outgoing<T>(request: Request<T>) -> Result<(OutgoingReque
7171
.uri
7272
.scheme()
7373
.map(to_wasi_scheme)
74-
.unwrap_or(wasi::http::types::Scheme::Https);
74+
.unwrap_or(wasip2::http::types::Scheme::Https);
7575
wasi_req
7676
.set_scheme(Some(&scheme))
7777
.map_err(|()| Error::other(format!("scheme rejected by wasi-http: {scheme:?}")))?;

src/http/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use wasi::http::types::IncomingResponse;
1+
use wasip2::http::types::IncomingResponse;
22

33
use super::{
44
body::{BodyKind, IncomingBody},

src/http/scheme.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use wasi::http::types::Scheme as WasiScheme;
1+
use wasip2::http::types::Scheme as WasiScheme;
22

33
pub use http::uri::{InvalidUri, Scheme};
44
use std::str::FromStr;

0 commit comments

Comments
 (0)