Skip to content

Commit a106ab8

Browse files
[37.0.0] Final (?) crop of backports (#11706)
* async: add stream/future producers and blanket impl for `Future` (#11684) * async: add `EmptyProducer` and blanket impl for `Future` Signed-off-by: Roman Volosatovs <[email protected]> * move more future/stream producers to `wasmtime` crate Signed-off-by: Roman Volosatovs <[email protected]> * async: allow blanket `Future` impl to trap Signed-off-by: Roman Volosatovs <[email protected]> * async: remove the need for `{Ready,Empty}Producer` Signed-off-by: Roman Volosatovs <[email protected]> --------- Signed-off-by: Roman Volosatovs <[email protected]> * Fix a missing outparam write in the p1 adapter (#11702) This fixes an issue found through #11701, notably the "release mode infinite loops" behavior that was seen. The cause was when `fd_readdir` returned after skipping all directory entries it forgot to write the final `*bufused = 0` out-param in the early-exit, unlike the end of the function which already sets this. * feat(p3-http): implement `consume-body` changes (#11653) * feat(p3-http): implement `consume-body` changes Signed-off-by: Roman Volosatovs <[email protected]> * Update WITs to the latest snapshot * Use the 2025-09-16 tag instead of 2025-08-15. * Pulls in `wasi:http` updates "officially". * Pulls in minor `wasi:cli` updates, and that's implemented here as well. --------- Signed-off-by: Roman Volosatovs <[email protected]> Co-authored-by: Alex Crichton <[email protected]> --------- Signed-off-by: Roman Volosatovs <[email protected]> Co-authored-by: Roman Volosatovs <[email protected]>
1 parent cda1743 commit a106ab8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1056
-728
lines changed

ci/vendor-wit.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ make_vendor "wasi-config" "config@f4d699b"
7070
make_vendor "wasi-keyvalue" "keyvalue@219ea36"
7171

7272
make_vendor "wasi/src/p3" "
73-
[email protected]08-15@wit-0.3.0-draft
74-
[email protected]08-15@wit-0.3.0-draft
75-
[email protected]08-15@wit-0.3.0-draft
76-
[email protected]08-15@wit-0.3.0-draft
77-
[email protected]08-15@wit-0.3.0-draft
73+
[email protected]09-16@wit-0.3.0-draft
74+
[email protected]09-16@wit-0.3.0-draft
75+
[email protected]09-16@wit-0.3.0-draft
76+
[email protected]09-16@wit-0.3.0-draft
77+
[email protected]09-16@wit-0.3.0-draft
7878
"
7979

8080
make_vendor "wasi-http/src/p3" "
81-
[email protected]08-15@wit-0.3.0-draft
82-
[email protected]08-15@wit-0.3.0-draft
83-
[email protected]08-15@wit-0.3.0-draft
84-
[email protected]08-15@wit-0.3.0-draft
85-
[email protected]08-15@wit-0.3.0-draft
86-
[email protected]08-15@wit-0.3.0-draft
81+
[email protected]09-16@wit-0.3.0-draft
82+
[email protected]09-16@wit-0.3.0-draft
83+
[email protected]09-16@wit-0.3.0-draft
84+
[email protected]09-16@wit-0.3.0-draft
85+
[email protected]09-16@wit-0.3.0-draft
86+
[email protected]09-16@wit-0.3.0-draft
8787
"
8888

8989
rm -rf $cache_dir

crates/test-programs/src/bin/cli_p3_hello_stdout.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ export!(Component);
77
impl exports::wasi::cli::run::Guest for Component {
88
async fn run() -> Result<(), ()> {
99
let (mut tx, rx) = wit_stream::new();
10-
wasi::cli::stdout::set_stdout(rx);
11-
tx.write(b"hello, world\n".to_vec()).await;
10+
futures::join!(
11+
async {
12+
wasi::cli::stdout::write_via_stream(rx).await.unwrap();
13+
},
14+
async {
15+
tx.write(b"hello, world\n".to_vec()).await;
16+
drop(tx);
17+
},
18+
);
1219
Ok(())
1320
}
1421
}

crates/test-programs/src/bin/cli_p3_much_stdout.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
1212

1313
let bytes = string_to_write.as_bytes();
1414
let (mut tx, rx) = wit_stream::new();
15-
wasi::cli::stdout::set_stdout(rx);
16-
for _ in 0..times_to_write {
17-
let result = tx.write_all(bytes.to_vec()).await;
18-
assert!(result.is_empty());
19-
}
15+
futures::join!(
16+
async { wasi::cli::stdout::write_via_stream(rx).await.unwrap() },
17+
async {
18+
for _ in 0..times_to_write {
19+
let result = tx.write_all(bytes.to_vec()).await;
20+
assert!(result.is_empty());
21+
}
22+
drop(tx);
23+
}
24+
);
2025
Ok(())
2126
}
2227
}

crates/test-programs/src/bin/p3_cli.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,37 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
1818
assert!(terminal_stdout::get_terminal_stdout().is_none());
1919
assert!(terminal_stderr::get_terminal_stderr().is_none());
2020

21-
let mut stdin = stdin::get_stdin();
21+
let (mut stdin, result) = stdin::read_via_stream();
2222
assert!(stdin.next().await.is_none());
2323

2424
let (mut stdout_tx, stdout_rx) = wit_stream::new();
25-
stdout::set_stdout(stdout_rx);
26-
let (res, buf) = stdout_tx.write(b"hello stdout\n".into()).await;
27-
assert_eq!(res, StreamResult::Complete(13));
28-
assert_eq!(buf.into_vec(), []);
25+
futures::join!(
26+
async {
27+
stdout::write_via_stream(stdout_rx).await.unwrap();
28+
},
29+
async {
30+
let (res, buf) = stdout_tx.write(b"hello stdout\n".into()).await;
31+
assert_eq!(res, StreamResult::Complete(13));
32+
assert_eq!(buf.into_vec(), []);
33+
drop(stdout_tx);
34+
}
35+
);
2936

3037
let (mut stderr_tx, stderr_rx) = wit_stream::new();
31-
stderr::set_stderr(stderr_rx);
32-
let (res, buf) = stderr_tx.write(b"hello stderr\n".into()).await;
33-
assert_eq!(res, StreamResult::Complete(13));
34-
assert_eq!(buf.into_vec(), []);
38+
futures::join!(
39+
async {
40+
stderr::write_via_stream(stderr_rx).await.unwrap();
41+
},
42+
async {
43+
let (res, buf) = stderr_tx.write(b"hello stderr\n".into()).await;
44+
assert_eq!(res, StreamResult::Complete(13));
45+
assert_eq!(buf.into_vec(), []);
46+
drop(stderr_tx);
47+
}
48+
);
49+
50+
drop(stdin);
51+
result.await.unwrap();
3552

3653
Ok(())
3754
}

crates/test-programs/src/bin/p3_http_echo.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ impl Handler for Component {
1515
/// Return a response which echoes the request headers, body, and trailers.
1616
async fn handle(request: Request) -> Result<Response, ErrorCode> {
1717
let headers = request.get_headers();
18-
let (body, trailers) = request.consume_body().unwrap();
19-
20-
// let (headers, body) = Request::into_parts(request);
18+
let (_, result_rx) = wit_future::new(|| Ok(()));
19+
let (body, trailers) = Request::consume_body(request, result_rx);
2120

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

4948
trailers_tx.write(trailers.await).await.unwrap();
50-
drop(request);
5149
});
5250

5351
Response::new(headers, Some(pipe_rx), trailers_rx)

crates/test-programs/src/bin/p3_http_middleware.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ impl Handler for Component {
4848
}
4949
_ => true,
5050
});
51-
let (mut body, trailers) = request.consume_body().unwrap();
51+
let (_, result_rx) = wit_future::new(|| Ok(()));
52+
let (mut body, trailers) = Request::consume_body(request, result_rx);
5253

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

7980
trailers_tx.write(trailers.await).await.unwrap();
80-
81-
drop(request);
8281
});
8382

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

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

@@ -141,7 +141,6 @@ impl Handler for Component {
141141
}
142142

143143
trailers_tx.write(trailers.await).await.unwrap();
144-
drop(response);
145144
});
146145

147146
(pipe_rx, trailers_rx)

crates/test-programs/src/bin/p3_http_middleware_with_chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ mod bindings {
66
package local:local;
77
88
world middleware-with-chain {
9-
include wasi:http/[email protected]08-15;
9+
include wasi:http/[email protected]09-16;
1010
1111
import chain-http;
1212
}
1313
1414
interface chain-http {
15-
use wasi:http/[email protected]08-15.{request, response, error-code};
15+
use wasi:http/[email protected]09-16.{request, response, error-code};
1616
1717
handle: async func(request: request) -> result<response, error-code>;
1818
}

crates/test-programs/src/bin/preview1_fd_readdir.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,34 @@ unsafe fn test_fd_readdir_unicode_boundary(dir_fd: wasip1::Fd) {
241241
wasip1::path_unlink_file(dir_fd, filename).expect("removing a file");
242242
}
243243

244+
unsafe fn test_fd_readdir_past_end(dir_fd: wasip1::Fd) {
245+
let file_fd = wasip1::path_open(
246+
dir_fd,
247+
0,
248+
"a",
249+
wasip1::OFLAGS_CREAT,
250+
wasip1::RIGHTS_FD_READ | wasip1::RIGHTS_FD_WRITE,
251+
0,
252+
0,
253+
)
254+
.expect("failed to create file");
255+
wasip1::fd_close(file_fd).expect("closing a file");
256+
257+
let mut buf = vec![0; 128];
258+
let len = wasip1::fd_readdir(dir_fd, buf.as_mut_ptr(), buf.capacity(), 0).unwrap();
259+
260+
let next = ReadDir::from_slice(&buf[..len])
261+
.last()
262+
.unwrap()
263+
.dirent
264+
.d_next;
265+
266+
let len = wasip1::fd_readdir(dir_fd, buf.as_mut_ptr(), buf.capacity(), next + 1).unwrap();
267+
assert_eq!(len, 0);
268+
269+
wasip1::path_unlink_file(dir_fd, "a").expect("removing a file");
270+
}
271+
244272
fn main() {
245273
let mut args = env::args();
246274
let prog = args.next().unwrap();
@@ -264,4 +292,5 @@ fn main() {
264292
unsafe { test_fd_readdir(dir_fd) }
265293
unsafe { test_fd_readdir_lots(dir_fd) }
266294
unsafe { test_fd_readdir_unicode_boundary(dir_fd) }
295+
unsafe { test_fd_readdir_past_end(dir_fd) }
267296
}

crates/test-programs/src/p3/http.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ pub async fn request(
9494
let response = handler::handle(request).await?;
9595
let status = response.get_status_code();
9696
let headers = response.get_headers().copy_all();
97-
let (body_rx, trailers_rx) = response
98-
.consume_body()
99-
.expect("failed to get response body");
97+
let (_, result_rx) = wit_future::new(|| Ok(()));
98+
let (body_rx, trailers_rx) = types::Response::consume_body(response, result_rx);
10099
let ((), rx) = join!(
101100
async {
102101
if let Some(buf) = body {

crates/test-programs/src/p3/mod.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ wit_bindgen::generate!({
66
package wasmtime:test;
77
88
world testp3 {
9-
include wasi:cli/[email protected]08-15;
10-
include wasi:http/[email protected]08-15;
9+
include wasi:cli/[email protected]09-16;
10+
include wasi:http/[email protected]09-16;
1111
12-
export wasi:cli/[email protected]08-15;
12+
export wasi:cli/[email protected]09-16;
1313
}
1414
",
1515
path: "../wasi-http/src/p3/wit",
1616
world: "wasmtime:test/testp3",
1717
default_bindings_module: "test_programs::p3",
1818
pub_export_macro: true,
19-
async: [
20-
"wasi:cli/[email protected]#run",
21-
],
2219
generate_all,
2320
});
2421

@@ -28,22 +25,24 @@ pub mod proxy {
2825
package wasmtime:test;
2926
3027
world proxyp3 {
31-
include wasi:http/[email protected]08-15;
28+
include wasi:http/[email protected]09-16;
3229
}
3330
",
3431
path: "../wasi-http/src/p3/wit",
3532
world: "wasmtime:test/proxyp3",
3633
default_bindings_module: "test_programs::p3::proxy",
3734
pub_export_macro: true,
3835
with: {
39-
"wasi:http/[email protected]": generate,
40-
"wasi:http/[email protected]": crate::p3::wasi::http::types,
41-
"wasi:random/[email protected]": crate::p3::wasi::random::random,
42-
"wasi:cli/[email protected]": crate::p3::wasi::cli::stdout,
43-
"wasi:cli/[email protected]": crate::p3::wasi::cli::stderr,
44-
"wasi:cli/[email protected]": crate::p3::wasi::cli::stdin,
45-
"wasi:clocks/[email protected]": crate::p3::wasi::clocks::monotonic_clock,
46-
"wasi:clocks/[email protected]": crate::p3::wasi::clocks::wall_clock,
36+
"wasi:http/[email protected]": generate,
37+
"wasi:http/[email protected]": crate::p3::wasi::http::types,
38+
"wasi:random/[email protected]": crate::p3::wasi::random::random,
39+
"wasi:cli/[email protected]": crate::p3::wasi::cli::stdout,
40+
"wasi:cli/[email protected]": crate::p3::wasi::cli::stderr,
41+
"wasi:cli/[email protected]": crate::p3::wasi::cli::stdin,
42+
"wasi:cli/[email protected]": crate::p3::wasi::cli::types,
43+
"wasi:clocks/[email protected]": crate::p3::wasi::clocks::monotonic_clock,
44+
"wasi:clocks/[email protected]": crate::p3::wasi::clocks::wall_clock,
45+
"wasi:clocks/[email protected]": crate::p3::wasi::clocks::types,
4746
},
4847
});
4948
}

0 commit comments

Comments
 (0)