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
22 changes: 11 additions & 11 deletions ci/vendor-wit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ make_vendor "wasi-config" "config@f4d699b"
make_vendor "wasi-keyvalue" "keyvalue@219ea36"

make_vendor "wasi/src/p3" "
cli@v0.3.0-rc-2025-08-15@wit-0.3.0-draft
clocks@v0.3.0-rc-2025-08-15@wit-0.3.0-draft
filesystem@v0.3.0-rc-2025-08-15@wit-0.3.0-draft
random@v0.3.0-rc-2025-08-15@wit-0.3.0-draft
sockets@v0.3.0-rc-2025-08-15@wit-0.3.0-draft
cli@v0.3.0-rc-2025-09-16@wit-0.3.0-draft
clocks@v0.3.0-rc-2025-09-16@wit-0.3.0-draft
filesystem@v0.3.0-rc-2025-09-16@wit-0.3.0-draft
random@v0.3.0-rc-2025-09-16@wit-0.3.0-draft
sockets@v0.3.0-rc-2025-09-16@wit-0.3.0-draft
"

make_vendor "wasi-http/src/p3" "
cli@v0.3.0-rc-2025-08-15@wit-0.3.0-draft
clocks@v0.3.0-rc-2025-08-15@wit-0.3.0-draft
filesystem@v0.3.0-rc-2025-08-15@wit-0.3.0-draft
http@v0.3.0-rc-2025-08-15@wit-0.3.0-draft
random@v0.3.0-rc-2025-08-15@wit-0.3.0-draft
sockets@v0.3.0-rc-2025-08-15@wit-0.3.0-draft
cli@v0.3.0-rc-2025-09-16@wit-0.3.0-draft
clocks@v0.3.0-rc-2025-09-16@wit-0.3.0-draft
filesystem@v0.3.0-rc-2025-09-16@wit-0.3.0-draft
http@v0.3.0-rc-2025-09-16@wit-0.3.0-draft
random@v0.3.0-rc-2025-09-16@wit-0.3.0-draft
sockets@v0.3.0-rc-2025-09-16@wit-0.3.0-draft
"

rm -rf $cache_dir
Expand Down
11 changes: 9 additions & 2 deletions crates/test-programs/src/bin/cli_p3_hello_stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ export!(Component);
impl exports::wasi::cli::run::Guest for Component {
async fn run() -> Result<(), ()> {
let (mut tx, rx) = wit_stream::new();
wasi::cli::stdout::set_stdout(rx);
tx.write(b"hello, world\n".to_vec()).await;
futures::join!(
async {
wasi::cli::stdout::write_via_stream(rx).await.unwrap();
},
async {
tx.write(b"hello, world\n".to_vec()).await;
drop(tx);
},
);
Ok(())
}
}
Expand Down
15 changes: 10 additions & 5 deletions crates/test-programs/src/bin/cli_p3_much_stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {

let bytes = string_to_write.as_bytes();
let (mut tx, rx) = wit_stream::new();
wasi::cli::stdout::set_stdout(rx);
for _ in 0..times_to_write {
let result = tx.write_all(bytes.to_vec()).await;
assert!(result.is_empty());
}
futures::join!(
async { wasi::cli::stdout::write_via_stream(rx).await.unwrap() },
async {
for _ in 0..times_to_write {
let result = tx.write_all(bytes.to_vec()).await;
assert!(result.is_empty());
}
drop(tx);
}
);
Ok(())
}
}
Expand Down
35 changes: 26 additions & 9 deletions crates/test-programs/src/bin/p3_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,37 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
assert!(terminal_stdout::get_terminal_stdout().is_none());
assert!(terminal_stderr::get_terminal_stderr().is_none());

let mut stdin = stdin::get_stdin();
let (mut stdin, result) = stdin::read_via_stream();
assert!(stdin.next().await.is_none());

let (mut stdout_tx, stdout_rx) = wit_stream::new();
stdout::set_stdout(stdout_rx);
let (res, buf) = stdout_tx.write(b"hello stdout\n".into()).await;
assert_eq!(res, StreamResult::Complete(13));
assert_eq!(buf.into_vec(), []);
futures::join!(
async {
stdout::write_via_stream(stdout_rx).await.unwrap();
},
async {
let (res, buf) = stdout_tx.write(b"hello stdout\n".into()).await;
assert_eq!(res, StreamResult::Complete(13));
assert_eq!(buf.into_vec(), []);
drop(stdout_tx);
}
);

let (mut stderr_tx, stderr_rx) = wit_stream::new();
stderr::set_stderr(stderr_rx);
let (res, buf) = stderr_tx.write(b"hello stderr\n".into()).await;
assert_eq!(res, StreamResult::Complete(13));
assert_eq!(buf.into_vec(), []);
futures::join!(
async {
stderr::write_via_stream(stderr_rx).await.unwrap();
},
async {
let (res, buf) = stderr_tx.write(b"hello stderr\n".into()).await;
assert_eq!(res, StreamResult::Complete(13));
assert_eq!(buf.into_vec(), []);
drop(stderr_tx);
}
);

drop(stdin);
result.await.unwrap();

Ok(())
}
Expand Down
6 changes: 2 additions & 4 deletions crates/test-programs/src/bin/p3_http_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ impl Handler for Component {
/// Return a response which echoes the request headers, body, and trailers.
async fn handle(request: Request) -> Result<Response, ErrorCode> {
let headers = request.get_headers();
let (body, trailers) = request.consume_body().unwrap();

// let (headers, body) = Request::into_parts(request);
let (_, result_rx) = wit_future::new(|| Ok(()));
let (body, trailers) = Request::consume_body(request, result_rx);

let (response, _result) = if false {
// This is the easy and efficient way to do it...
Expand Down Expand Up @@ -47,7 +46,6 @@ impl Handler for Component {
drop(pipe_tx);

trailers_tx.write(trailers.await).await.unwrap();
drop(request);
});

Response::new(headers, Some(pipe_rx), trailers_rx)
Expand Down
9 changes: 4 additions & 5 deletions crates/test-programs/src/bin/p3_http_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ impl Handler for Component {
}
_ => true,
});
let (mut body, trailers) = request.consume_body().unwrap();
let (_, result_rx) = wit_future::new(|| Ok(()));
let (mut body, trailers) = Request::consume_body(request, result_rx);

let (body, trailers) = if content_deflated {
// Next, spawn a task to pipe and decode the original request body and trailers into a new request
Expand Down Expand Up @@ -77,8 +78,6 @@ impl Handler for Component {
}

trailers_tx.write(trailers.await).await.unwrap();

drop(request);
});

(pipe_rx, trailers_rx)
Expand Down Expand Up @@ -110,7 +109,8 @@ impl Handler for Component {
headers.push(("content-encoding".into(), b"deflate".into()));
}

let (mut body, trailers) = response.consume_body().unwrap();
let (_, result_rx) = wit_future::new(|| Ok(()));
let (mut body, trailers) = Response::consume_body(response, result_rx);
let (body, trailers) = if accept_deflated {
headers.retain(|(name, _value)| name != "content-length");

Expand Down Expand Up @@ -141,7 +141,6 @@ impl Handler for Component {
}

trailers_tx.write(trailers.await).await.unwrap();
drop(response);
});

(pipe_rx, trailers_rx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ mod bindings {
package local:local;

world middleware-with-chain {
include wasi:http/proxy@0.3.0-rc-2025-08-15;
include wasi:http/proxy@0.3.0-rc-2025-09-16;

import chain-http;
}

interface chain-http {
use wasi:http/types@0.3.0-rc-2025-08-15.{request, response, error-code};
use wasi:http/types@0.3.0-rc-2025-09-16.{request, response, error-code};

handle: async func(request: request) -> result<response, error-code>;
}
Expand Down
29 changes: 29 additions & 0 deletions crates/test-programs/src/bin/preview1_fd_readdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,34 @@ unsafe fn test_fd_readdir_unicode_boundary(dir_fd: wasip1::Fd) {
wasip1::path_unlink_file(dir_fd, filename).expect("removing a file");
}

unsafe fn test_fd_readdir_past_end(dir_fd: wasip1::Fd) {
let file_fd = wasip1::path_open(
dir_fd,
0,
"a",
wasip1::OFLAGS_CREAT,
wasip1::RIGHTS_FD_READ | wasip1::RIGHTS_FD_WRITE,
0,
0,
)
.expect("failed to create file");
wasip1::fd_close(file_fd).expect("closing a file");

let mut buf = vec![0; 128];
let len = wasip1::fd_readdir(dir_fd, buf.as_mut_ptr(), buf.capacity(), 0).unwrap();

let next = ReadDir::from_slice(&buf[..len])
.last()
.unwrap()
.dirent
.d_next;

let len = wasip1::fd_readdir(dir_fd, buf.as_mut_ptr(), buf.capacity(), next + 1).unwrap();
assert_eq!(len, 0);

wasip1::path_unlink_file(dir_fd, "a").expect("removing a file");
}

fn main() {
let mut args = env::args();
let prog = args.next().unwrap();
Expand All @@ -264,4 +292,5 @@ fn main() {
unsafe { test_fd_readdir(dir_fd) }
unsafe { test_fd_readdir_lots(dir_fd) }
unsafe { test_fd_readdir_unicode_boundary(dir_fd) }
unsafe { test_fd_readdir_past_end(dir_fd) }
}
5 changes: 2 additions & 3 deletions crates/test-programs/src/p3/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ pub async fn request(
let response = handler::handle(request).await?;
let status = response.get_status_code();
let headers = response.get_headers().copy_all();
let (body_rx, trailers_rx) = response
.consume_body()
.expect("failed to get response body");
let (_, result_rx) = wit_future::new(|| Ok(()));
let (body_rx, trailers_rx) = types::Response::consume_body(response, result_rx);
let ((), rx) = join!(
async {
if let Some(buf) = body {
Expand Down
29 changes: 14 additions & 15 deletions crates/test-programs/src/p3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ wit_bindgen::generate!({
package wasmtime:test;

world testp3 {
include wasi:cli/imports@0.3.0-rc-2025-08-15;
include wasi:http/imports@0.3.0-rc-2025-08-15;
include wasi:cli/imports@0.3.0-rc-2025-09-16;
include wasi:http/imports@0.3.0-rc-2025-09-16;

export wasi:cli/run@0.3.0-rc-2025-08-15;
export wasi:cli/run@0.3.0-rc-2025-09-16;
}
",
path: "../wasi-http/src/p3/wit",
world: "wasmtime:test/testp3",
default_bindings_module: "test_programs::p3",
pub_export_macro: true,
async: [
"wasi:cli/run@0.3.0-rc-2025-08-15#run",
],
generate_all,
});

Expand All @@ -28,22 +25,24 @@ pub mod proxy {
package wasmtime:test;

world proxyp3 {
include wasi:http/proxy@0.3.0-rc-2025-08-15;
include wasi:http/proxy@0.3.0-rc-2025-09-16;
}
",
path: "../wasi-http/src/p3/wit",
world: "wasmtime:test/proxyp3",
default_bindings_module: "test_programs::p3::proxy",
pub_export_macro: true,
with: {
"wasi:http/handler@0.3.0-rc-2025-08-15": generate,
"wasi:http/types@0.3.0-rc-2025-08-15": crate::p3::wasi::http::types,
"wasi:random/random@0.3.0-rc-2025-08-15": crate::p3::wasi::random::random,
"wasi:cli/stdout@0.3.0-rc-2025-08-15": crate::p3::wasi::cli::stdout,
"wasi:cli/stderr@0.3.0-rc-2025-08-15": crate::p3::wasi::cli::stderr,
"wasi:cli/stdin@0.3.0-rc-2025-08-15": crate::p3::wasi::cli::stdin,
"wasi:clocks/monotonic-clock@0.3.0-rc-2025-08-15": crate::p3::wasi::clocks::monotonic_clock,
"wasi:clocks/wall-clock@0.3.0-rc-2025-08-15": crate::p3::wasi::clocks::wall_clock,
"wasi:http/handler@0.3.0-rc-2025-09-16": generate,
"wasi:http/types@0.3.0-rc-2025-09-16": crate::p3::wasi::http::types,
"wasi:random/random@0.3.0-rc-2025-09-16": crate::p3::wasi::random::random,
"wasi:cli/stdout@0.3.0-rc-2025-09-16": crate::p3::wasi::cli::stdout,
"wasi:cli/stderr@0.3.0-rc-2025-09-16": crate::p3::wasi::cli::stderr,
"wasi:cli/stdin@0.3.0-rc-2025-09-16": crate::p3::wasi::cli::stdin,
"wasi:cli/types@0.3.0-rc-2025-09-16": crate::p3::wasi::cli::types,
"wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16": crate::p3::wasi::clocks::monotonic_clock,
"wasi:clocks/wall-clock@0.3.0-rc-2025-09-16": crate::p3::wasi::clocks::wall_clock,
"wasi:clocks/types@0.3.0-rc-2025-09-16": crate::p3::wasi::clocks::types,
},
});
}
4 changes: 2 additions & 2 deletions crates/wasi-http/src/p3/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ mod generated {
"wasi:http/handler/[async]handle": async | store | trappable | tracing,
"wasi:http/types/[drop]request": store | trappable | tracing,
"wasi:http/types/[drop]response": store | trappable | tracing,
"wasi:http/types/[method]request.consume-body": async | store | trappable | tracing,
"wasi:http/types/[method]response.consume-body": async | store | trappable | tracing,
"wasi:http/types/[static]request.consume-body": async | store | trappable | tracing,
"wasi:http/types/[static]request.new": async | store | trappable | tracing,
"wasi:http/types/[static]response.consume-body": async | store | trappable | tracing,
"wasi:http/types/[static]response.new": async | store | trappable | tracing,
default: trappable | tracing,
},
Expand Down
Loading
Loading