Skip to content
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ http.workspace = true
itoa.workspace = true
pin-project-lite.workspace = true
slab.workspace = true
wasi.workspace = true
wasip2.workspace = true
wstd-macro.workspace = true

# optional
Expand Down Expand Up @@ -83,7 +83,7 @@ test-log = { version = "0.2", features = ["trace"] }
test-programs = { path = "test-programs" }
test-programs-artifacts = { path = "test-programs/artifacts" }
ureq = { version = "2.12.1", default-features = false }
wasi = "0.14.0"
wasip2 = "1.0"
wstd = { path = "." }
wstd-macro = { path = "macro", version = "=0.5.5" }

Expand Down
8 changes: 4 additions & 4 deletions macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ pub fn attr_macro_http_server(_attr: TokenStream, item: TokenStream) -> TokenStr
quote! {
struct TheServer;

impl ::wstd::wasi::exports::http::incoming_handler::Guest for TheServer {
impl ::wstd::wasip2::exports::http::incoming_handler::Guest for TheServer {
fn handle(
request: ::wstd::wasi::http::types::IncomingRequest,
response_out: ::wstd::wasi::http::types::ResponseOutparam
request: ::wstd::wasip2::http::types::IncomingRequest,
response_out: ::wstd::wasip2::http::types::ResponseOutparam
) {
#(#attrs)*
#vis async fn __run(#inputs) #output {
Expand All @@ -146,7 +146,7 @@ pub fn attr_macro_http_server(_attr: TokenStream, item: TokenStream) -> TokenStr
}
}

::wstd::wasi::http::proxy::export!(TheServer with_types_in ::wstd::wasi);
::wstd::wasip2::http::proxy::export!(TheServer with_types_in ::wstd::wasip2);

// Provide an actual function named `main`.
//
Expand Down
8 changes: 4 additions & 4 deletions src/http/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::io::{AsyncInputStream, AsyncOutputStream, AsyncRead, AsyncWrite, Curs
use crate::runtime::AsyncPollable;
use core::fmt;
use http::header::CONTENT_LENGTH;
use wasi::http::types::IncomingBody as WasiIncomingBody;
use wasip2::http::types::IncomingBody as WasiIncomingBody;

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

impl OutgoingBody {
pub(crate) fn new(stream: AsyncOutputStream, body: wasi::http::types::OutgoingBody) -> Self {
pub(crate) fn new(stream: AsyncOutputStream, body: wasip2::http::types::OutgoingBody) -> Self {
Self {
stream,
body,
dontdrop: DontDropOutgoingBody,
}
}

pub(crate) fn consume(self) -> (AsyncOutputStream, wasi::http::types::OutgoingBody) {
pub(crate) fn consume(self) -> (AsyncOutputStream, wasip2::http::types::OutgoingBody) {
let Self {
stream,
body,
Expand Down
8 changes: 4 additions & 4 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use pin_project_lite::pin_project;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use wasi::http::types::{
use wasip2::http::types::{
FutureIncomingResponse as WasiFutureIncomingResponse, OutgoingBody as WasiOutgoingBody,
RequestOptions as WasiRequestOptions,
};
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Client {
let wasi_stream = wasi_body.write().unwrap();

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

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

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

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

Expand Down Expand Up @@ -141,7 +141,7 @@ impl Client {
None => None,
};

wasi::http::types::OutgoingBody::finish(body, wasi_trailers)
wasip2::http::types::OutgoingBody::finish(body, wasi_trailers)
.expect("body length did not match Content-Length header value");
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/http/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Error {

pub use http::header::{InvalidHeaderName, InvalidHeaderValue};
pub use http::method::InvalidMethod;
pub use wasi::http::types::{ErrorCode as WasiHttpErrorCode, HeaderError as WasiHttpHeaderError};
pub use wasip2::http::types::{ErrorCode as WasiHttpErrorCode, HeaderError as WasiHttpHeaderError};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using semantic versioning for your crate, i.e. v0.5.5 -> v0.6.0 instead of v0.5.6 when changing the public API in a non-backwards compatible way. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be backwards compatible, since the wasi crate is now a thin re-export of the wasip2 crate: https://docs.rs/wasi/latest/src/wasi/lib.rs.html#1-2.

If you're running into compatibility problems, please consider filing an issue with your Cargo lockfile attached.

Copy link

@ignatz ignatz Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get me wrong, this is not a big issue. Easy to fix on the consumer-side, just avoidable. I wouldn't want to file an issue because there's nothing much todo. Mostly an FYI

Yet, v0.5.5 -> v0.5.6

error[E0432]: unresolved import `wstd::wasi`
  --> crates/wasm-runtime-guest/src/lib.rs:46:9
   |
46 | pub use wstd::wasi;
   |         ^^^^^^^^^^ no `wasi` in the root
   |
help: consider importing this module instead
   |
46 - pub use wstd::wasi;
46 + pub use crate::wit::wasi;
   |


impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion src/http/fields.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use http::header::{HeaderMap, HeaderName, HeaderValue};

use super::Error;
use wasi::http::types::{Fields, HeaderError as WasiHttpHeaderError};
use wasip2::http::types::{Fields, HeaderError as WasiHttpHeaderError};

pub(crate) fn header_map_from_wasi(wasi_fields: Fields) -> Result<HeaderMap, Error> {
let mut output = HeaderMap::new();
Expand Down
2 changes: 1 addition & 1 deletion src/http/method.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use wasi::http::types::Method as WasiMethod;
use wasip2::http::types::Method as WasiMethod;

use http::method::InvalidMethod;
pub use http::Method;
Expand Down
6 changes: 3 additions & 3 deletions src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use super::{
Authority, Error, HeaderMap, PathAndQuery, Uri,
};
use crate::io::AsyncInputStream;
use wasi::http::outgoing_handler::OutgoingRequest;
use wasi::http::types::IncomingRequest;
use wasip2::http::outgoing_handler::OutgoingRequest;
use wasip2::http::types::IncomingRequest;

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

Expand Down Expand Up @@ -71,7 +71,7 @@ pub(crate) fn try_into_outgoing<T>(request: Request<T>) -> Result<(OutgoingReque
.uri
.scheme()
.map(to_wasi_scheme)
.unwrap_or(wasi::http::types::Scheme::Https);
.unwrap_or(wasip2::http::types::Scheme::Https);
wasi_req
.set_scheme(Some(&scheme))
.map_err(|()| Error::other(format!("scheme rejected by wasi-http: {scheme:?}")))?;
Expand Down
2 changes: 1 addition & 1 deletion src/http/response.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use wasi::http::types::IncomingResponse;
use wasip2::http::types::IncomingResponse;

use super::{
body::{BodyKind, IncomingBody},
Expand Down
2 changes: 1 addition & 1 deletion src/http/scheme.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use wasi::http::types::Scheme as WasiScheme;
use wasip2::http::types::Scheme as WasiScheme;

pub use http::uri::{InvalidUri, Scheme};
use std::str::FromStr;
Expand Down
6 changes: 3 additions & 3 deletions src/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use super::{
};
use crate::io::{copy, AsyncOutputStream};
use http::header::CONTENT_LENGTH;
use wasi::exports::http::incoming_handler::ResponseOutparam;
use wasi::http::types::OutgoingResponse;
use wasip2::exports::http::incoming_handler::ResponseOutparam;
use wasip2::http::types::OutgoingResponse;

/// This is passed into the [`http_server`] `main` function and holds the state
/// needed for a handler to produce a response, or fail. There are two ways to
Expand Down Expand Up @@ -179,7 +179,7 @@ impl Finished {
let wasi_trailers =
trailers.map(|trailers| header_map_to_wasi(&trailers).expect("header error"));

wasi::http::types::OutgoingBody::finish(body, wasi_trailers)
wasip2::http::types::OutgoingBody::finish(body, wasi_trailers)
.expect("body length did not match Content-Length header value");

Self(())
Expand Down
2 changes: 1 addition & 1 deletion src/io/copy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::io::{AsyncRead, AsyncWrite, Error};
use wasi::io::streams::StreamError;
use wasip2::io::streams::StreamError;

/// Copy bytes from a reader to a writer.
pub async fn copy<R, W>(mut reader: R, mut writer: W) -> crate::io::Result<()>
Expand Down
16 changes: 8 additions & 8 deletions src/io/stdio.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{AsyncInputStream, AsyncOutputStream, AsyncRead, AsyncWrite, Result};
use std::cell::LazyCell;
use wasi::cli::terminal_input::TerminalInput;
use wasi::cli::terminal_output::TerminalOutput;
use wasip2::cli::terminal_input::TerminalInput;
use wasip2::cli::terminal_output::TerminalOutput;

/// Use the program's stdin as an `AsyncInputStream`.
#[derive(Debug)]
Expand All @@ -12,10 +12,10 @@ pub struct Stdin {

/// Get the program's stdin for use as an `AsyncInputStream`.
pub fn stdin() -> Stdin {
let stream = AsyncInputStream::new(wasi::cli::stdin::get_stdin());
let stream = AsyncInputStream::new(wasip2::cli::stdin::get_stdin());
Stdin {
stream,
terminput: LazyCell::new(wasi::cli::terminal_stdin::get_terminal_stdin),
terminput: LazyCell::new(wasip2::cli::terminal_stdin::get_terminal_stdin),
}
}

Expand Down Expand Up @@ -52,10 +52,10 @@ pub struct Stdout {

/// Get the program's stdout for use as an `AsyncOutputStream`.
pub fn stdout() -> Stdout {
let stream = AsyncOutputStream::new(wasi::cli::stdout::get_stdout());
let stream = AsyncOutputStream::new(wasip2::cli::stdout::get_stdout());
Stdout {
stream,
termoutput: LazyCell::new(wasi::cli::terminal_stdout::get_terminal_stdout),
termoutput: LazyCell::new(wasip2::cli::terminal_stdout::get_terminal_stdout),
}
}

Expand Down Expand Up @@ -97,10 +97,10 @@ pub struct Stderr {

/// Get the program's stdout for use as an `AsyncOutputStream`.
pub fn stderr() -> Stderr {
let stream = AsyncOutputStream::new(wasi::cli::stderr::get_stderr());
let stream = AsyncOutputStream::new(wasip2::cli::stderr::get_stderr());
Stderr {
stream,
termoutput: LazyCell::new(wasi::cli::terminal_stderr::get_terminal_stderr),
termoutput: LazyCell::new(wasip2::cli::terminal_stderr::get_terminal_stderr),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/io/streams.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{AsyncPollable, AsyncRead, AsyncWrite};
use std::cell::OnceCell;
use std::io::Result;
use wasi::io::streams::{InputStream, OutputStream, StreamError};
use wasip2::io::streams::{InputStream, OutputStream, StreamError};

/// A wrapper for WASI's `InputStream` resource that provides implementations of `AsyncRead` and
/// `AsyncPollable`.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub use wstd_macro::attr_macro_test as test;

// Re-export the wasi crate for use by the `http_server` macro.
#[doc(hidden)]
pub use wasi;
pub use wasip2;

pub mod prelude {
pub use crate::future::FutureExt as _;
Expand Down
42 changes: 23 additions & 19 deletions src/net/tcp_listener.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use wasi::sockets::network::Ipv4SocketAddress;
use wasi::sockets::tcp::{ErrorCode, IpAddressFamily, IpSocketAddress, TcpSocket};
use wasip2::sockets::network::Ipv4SocketAddress;
use wasip2::sockets::tcp::{ErrorCode, IpAddressFamily, IpSocketAddress, TcpSocket};

use crate::io;
use crate::iter::AsyncIterator;
Expand Down Expand Up @@ -30,8 +30,8 @@ impl TcpListener {
SocketAddr::V6(_) => IpAddressFamily::Ipv6,
};
let socket =
wasi::sockets::tcp_create_socket::create_tcp_socket(family).map_err(to_io_err)?;
let network = wasi::sockets::instance_network::instance_network();
wasip2::sockets::tcp_create_socket::create_tcp_socket(family).map_err(to_io_err)?;
let network = wasip2::sockets::instance_network::instance_network();

let local_address = sockaddr_to_wasi(addr);

Expand Down Expand Up @@ -83,25 +83,29 @@ impl<'a> AsyncIterator for Incoming<'a> {

pub(super) fn to_io_err(err: ErrorCode) -> io::Error {
match err {
wasi::sockets::network::ErrorCode::Unknown => ErrorKind::Other.into(),
wasi::sockets::network::ErrorCode::AccessDenied => ErrorKind::PermissionDenied.into(),
wasi::sockets::network::ErrorCode::NotSupported => ErrorKind::Unsupported.into(),
wasi::sockets::network::ErrorCode::InvalidArgument => ErrorKind::InvalidInput.into(),
wasi::sockets::network::ErrorCode::OutOfMemory => ErrorKind::OutOfMemory.into(),
wasi::sockets::network::ErrorCode::Timeout => ErrorKind::TimedOut.into(),
wasi::sockets::network::ErrorCode::WouldBlock => ErrorKind::WouldBlock.into(),
wasi::sockets::network::ErrorCode::InvalidState => ErrorKind::InvalidData.into(),
wasi::sockets::network::ErrorCode::AddressInUse => ErrorKind::AddrInUse.into(),
wasi::sockets::network::ErrorCode::ConnectionRefused => ErrorKind::ConnectionRefused.into(),
wasi::sockets::network::ErrorCode::ConnectionReset => ErrorKind::ConnectionReset.into(),
wasi::sockets::network::ErrorCode::ConnectionAborted => ErrorKind::ConnectionAborted.into(),
wasi::sockets::network::ErrorCode::ConcurrencyConflict => ErrorKind::AlreadyExists.into(),
wasip2::sockets::network::ErrorCode::Unknown => ErrorKind::Other.into(),
wasip2::sockets::network::ErrorCode::AccessDenied => ErrorKind::PermissionDenied.into(),
wasip2::sockets::network::ErrorCode::NotSupported => ErrorKind::Unsupported.into(),
wasip2::sockets::network::ErrorCode::InvalidArgument => ErrorKind::InvalidInput.into(),
wasip2::sockets::network::ErrorCode::OutOfMemory => ErrorKind::OutOfMemory.into(),
wasip2::sockets::network::ErrorCode::Timeout => ErrorKind::TimedOut.into(),
wasip2::sockets::network::ErrorCode::WouldBlock => ErrorKind::WouldBlock.into(),
wasip2::sockets::network::ErrorCode::InvalidState => ErrorKind::InvalidData.into(),
wasip2::sockets::network::ErrorCode::AddressInUse => ErrorKind::AddrInUse.into(),
wasip2::sockets::network::ErrorCode::ConnectionRefused => {
ErrorKind::ConnectionRefused.into()
}
wasip2::sockets::network::ErrorCode::ConnectionReset => ErrorKind::ConnectionReset.into(),
wasip2::sockets::network::ErrorCode::ConnectionAborted => {
ErrorKind::ConnectionAborted.into()
}
wasip2::sockets::network::ErrorCode::ConcurrencyConflict => ErrorKind::AlreadyExists.into(),
_ => ErrorKind::Other.into(),
}
}

fn sockaddr_from_wasi(addr: IpSocketAddress) -> std::net::SocketAddr {
use wasi::sockets::network::Ipv6SocketAddress;
use wasip2::sockets::network::Ipv6SocketAddress;
match addr {
IpSocketAddress::Ipv4(Ipv4SocketAddress { address, port }) => {
std::net::SocketAddr::V4(std::net::SocketAddrV4::new(
Expand All @@ -127,7 +131,7 @@ fn sockaddr_from_wasi(addr: IpSocketAddress) -> std::net::SocketAddr {
}

fn sockaddr_to_wasi(addr: std::net::SocketAddr) -> IpSocketAddress {
use wasi::sockets::network::Ipv6SocketAddress;
use wasip2::sockets::network::Ipv6SocketAddress;
match addr {
std::net::SocketAddr::V4(addr) => {
let ip = addr.ip().octets();
Expand Down
10 changes: 6 additions & 4 deletions src/net/tcp_stream.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use wasi::{
use wasip2::{
io::streams::{InputStream, OutputStream},
sockets::tcp::TcpSocket,
};
Expand Down Expand Up @@ -36,7 +36,9 @@ impl TcpStream {

impl Drop for TcpStream {
fn drop(&mut self) {
let _ = self.socket.shutdown(wasi::sockets::tcp::ShutdownType::Both);
let _ = self
.socket
.shutdown(wasip2::sockets::tcp::ShutdownType::Both);
}
}

Expand Down Expand Up @@ -104,7 +106,7 @@ impl<'a> Drop for ReadHalf<'a> {
let _ = self
.0
.socket
.shutdown(wasi::sockets::tcp::ShutdownType::Receive);
.shutdown(wasip2::sockets::tcp::ShutdownType::Receive);
}
}

Expand All @@ -128,6 +130,6 @@ impl<'a> Drop for WriteHalf<'a> {
let _ = self
.0
.socket
.shutdown(wasi::sockets::tcp::ShutdownType::Send);
.shutdown(wasip2::sockets::tcp::ShutdownType::Send);
}
}
2 changes: 1 addition & 1 deletion src/rand/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Random number generation.

use wasi::random;
use wasip2::random;

/// Fill the slice with cryptographically secure random bytes.
pub fn get_random_bytes(buf: &mut [u8]) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! The way to use this is to call [`block_on()`]. Inside the future, [`Reactor::current`]
//! will give an instance of the [`Reactor`] running the event loop, which can be
//! to [`AsyncPollable::wait_for`] instances of
//! [`wasi::Pollable`](https://docs.rs/wasi/latest/wasi/io/poll/struct.Pollable.html).
//! [`wasip2::Pollable`](https://docs.rs/wasi/latest/wasi/io/poll/struct.Pollable.html).
//! This will automatically wait for the futures to resolve, and call the
//! necessary wakers to work.

Expand Down
Loading
Loading