Skip to content

Commit 3ba676b

Browse files
committed
feat(wasi): add support for wasi:[email protected]
Signed-off-by: Roman Volosatovs <[email protected]>
1 parent a1e2bfc commit 3ba676b

19 files changed

+875
-7
lines changed

ci/vendor-wit.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ make_vendor "wasi/src/p2" "
4545
4646
"
4747

48+
make_vendor "wasi/src/p3" "
49+
50+
"
51+
4852
make_vendor "wasi-http/src/p2" "
4953
5054

crates/test-programs/artifacts/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ fn build_and_generate_tests() {
7171
s if s.starts_with("http_") => "http",
7272
s if s.starts_with("preview1_") => "preview1",
7373
s if s.starts_with("preview2_") => "preview2",
74+
s if s.starts_with("preview3_") => "preview3",
7475
s if s.starts_with("cli_") => "cli",
7576
s if s.starts_with("api_") => "api",
7677
s if s.starts_with("nn_") => "nn",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use test_programs::wasi::random;
1+
use test_programs::wasi::random0_2_3 as random;
22

33
fn main() {
44
let mut bytes = [0_u8; 256];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use test_programs::wasi::random0_3_0 as random;
2+
3+
fn main() {
4+
let mut bytes = [0_u8; 256];
5+
getrandom::getrandom(&mut bytes).unwrap();
6+
7+
assert!(bytes.iter().any(|x| *x != 0));
8+
9+
// Acquired random bytes should be of the expected length.
10+
let array = random::random::get_random_bytes(100);
11+
assert_eq!(array.len(), 100);
12+
13+
// It shouldn't take 100+ tries to get a nonzero random integer.
14+
for i in 0.. {
15+
if random::random::get_random_u64() == 0 {
16+
continue;
17+
}
18+
assert!(i < 100);
19+
break;
20+
}
21+
22+
// The `insecure_seed` API should return the same result each time.
23+
let (a1, b1) = random::insecure_seed::insecure_seed();
24+
let (a2, b2) = random::insecure_seed::insecure_seed();
25+
assert_eq!(a1, a2);
26+
assert_eq!(b1, b2);
27+
28+
// Acquired random bytes should be of the expected length.
29+
let array = random::insecure::get_insecure_random_bytes(100);
30+
assert_eq!(array.len(), 100);
31+
32+
// It shouldn't take 100+ tries to get a nonzero random integer.
33+
for i in 0.. {
34+
if random::insecure::get_insecure_random_u64() == 0 {
35+
continue;
36+
}
37+
assert!(i < 100);
38+
break;
39+
}
40+
}

crates/test-programs/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ wit_bindgen::generate!({
1212
include wasi:http/[email protected];
1313
include wasi:config/[email protected];
1414
include wasi:keyvalue/[email protected];
15+
16+
include wasi:random/[email protected];
1517
}
1618
",
1719
path: [
20+
"../wasi/src/p3/wit",
1821
"../wasi-http/src/p2/wit",
1922
"../wasi-config/src/p2/wit",
2023
"../wasi-keyvalue/src/p2/wit",
@@ -33,7 +36,7 @@ pub mod proxy {
3336
with: {
3437
"wasi:http/[email protected]": crate::wasi::http::types,
3538
"wasi:http/[email protected]": crate::wasi::http::outgoing_handler,
36-
"wasi:random/[email protected]": crate::wasi::random::random,
39+
"wasi:random/[email protected]": crate::wasi::random0_2_3::random,
3740
"wasi:io/[email protected]": crate::wasi::io::error,
3841
"wasi:io/[email protected]": crate::wasi::io::poll,
3942
"wasi:io/[email protected]": crate::wasi::io::streams,

crates/test-programs/src/sockets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::wasi::clocks::monotonic_clock;
22
use crate::wasi::io::poll::{self, Pollable};
33
use crate::wasi::io::streams::{InputStream, OutputStream, StreamError};
4-
use crate::wasi::random;
4+
use crate::wasi::random0_2_3 as random;
55
use crate::wasi::sockets::instance_network;
66
use crate::wasi::sockets::ip_name_lookup;
77
use crate::wasi::sockets::network::{

crates/wasi/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ default = [ "preview1"]
5757
preview1 = [
5858
"dep:wiggle",
5959
]
60+
# Enables experimental, unstable and incomplete support for wasip3
61+
p3 = []
6062

6163
[[test]]
6264
name = "process_stdin"

crates/wasi/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ mod filesystem;
190190
mod ip_name_lookup;
191191
mod network;
192192
pub mod p2;
193+
#[cfg(feature = "p3")]
194+
pub mod p3;
193195
pub mod pipe;
194196
mod poll;
195197
#[cfg(feature = "preview1")]

0 commit comments

Comments
 (0)