-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: begin wasip3 implementation #11221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexcrichton
merged 10 commits into
bytecodealliance:main
from
rvolosatovs:feat/wasip3-part1
Jul 16, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
db8d92b
ci: add subdir support
rvolosatovs f2de7e7
feat: extract common `WasiCtxBuilder`
rvolosatovs ef81b5d
chore: vendor p3 WIT
rvolosatovs 5f347a0
feat: begin wasip3 implementation
rvolosatovs b5fcbf5
chore(wasip3): remove now-redundant async stubs
rvolosatovs 046e026
test(wasip3): link wasip2
rvolosatovs 78cb76a
refactor: `allow` -> `expect`
rvolosatovs 0cfdb2e
chore: add bindgen `tracing` issue ref
rvolosatovs ae81493
chore: adapt to `Accessor` API changes
rvolosatovs 63a9517
doc: add a link to p3 `add_to_linker`
rvolosatovs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,18 +19,18 @@ make_vendor() { | |
| mkdir -p $path | ||
|
|
||
| for package in $packages; do | ||
| IFS='@' read -r repo tag <<< "$package" | ||
| mkdir -p $path/$repo | ||
| IFS='@' read -r repo tag subdir <<< "$package" | ||
| mkdir -p "$path/$repo" | ||
| cached_extracted_dir="$cache_dir/$repo-$tag" | ||
|
|
||
| if [[ ! -d $cached_extracted_dir ]]; then | ||
| mkdir -p $cached_extracted_dir | ||
| curl -sL https://github.com/WebAssembly/wasi-$repo/archive/$tag.tar.gz | \ | ||
| tar xzf - --strip-components=1 -C $cached_extracted_dir | ||
| rm -rf $cached_extracted_dir/wit/deps* | ||
| rm -rf $cached_extracted_dir/${subdir:-"wit"}/deps* | ||
| fi | ||
|
|
||
| cp -r $cached_extracted_dir/wit/* $path/$repo | ||
| cp -r $cached_extracted_dir/${subdir:-"wit"}/* $path/$repo | ||
| done | ||
| } | ||
|
|
||
|
|
@@ -68,6 +68,14 @@ make_vendor "wasi-config" "config@f4d699b" | |
|
|
||
| make_vendor "wasi-keyvalue" "keyvalue@219ea36" | ||
|
|
||
| make_vendor "wasi/src/p3" " | ||
| cli@[email protected] | ||
| clocks@[email protected] | ||
| filesystem@[email protected] | ||
| random@[email protected] | ||
| sockets@[email protected] | ||
| " | ||
|
|
||
| rm -rf $cache_dir | ||
|
|
||
| # Separately (for now), vendor the `wasi-nn` WIT files since their retrieval is | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| use core::future::Future as _; | ||
| use core::pin::pin; | ||
| use core::task::{Context, Poll, Waker}; | ||
|
|
||
| use test_programs::p3::wasi::clocks::monotonic_clock; | ||
|
|
||
| struct Component; | ||
|
|
||
| test_programs::p3::export!(Component); | ||
|
|
||
| impl test_programs::p3::exports::wasi::cli::run::Guest for Component { | ||
| async fn run() -> Result<(), ()> { | ||
| sleep_10ms().await; | ||
| sleep_0ms(); | ||
| sleep_backwards_in_time(); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| async fn sleep_10ms() { | ||
| let dur = 10_000_000; | ||
| monotonic_clock::wait_until(monotonic_clock::now() + dur).await; | ||
| monotonic_clock::wait_for(dur).await; | ||
| } | ||
|
|
||
| fn sleep_0ms() { | ||
| let mut cx = Context::from_waker(Waker::noop()); | ||
|
|
||
| assert_eq!( | ||
| pin!(monotonic_clock::wait_until(monotonic_clock::now())).poll(&mut cx), | ||
| Poll::Ready(()), | ||
| "waiting until now() is ready immediately", | ||
| ); | ||
| assert_eq!( | ||
| pin!(monotonic_clock::wait_for(0)).poll(&mut cx), | ||
| Poll::Ready(()), | ||
| "waiting for 0 is ready immediately", | ||
| ); | ||
| } | ||
|
|
||
| fn sleep_backwards_in_time() { | ||
| let mut cx = Context::from_waker(Waker::noop()); | ||
|
|
||
| assert_eq!( | ||
| pin!(monotonic_clock::wait_until(monotonic_clock::now() - 1)).poll(&mut cx), | ||
| Poll::Ready(()), | ||
| "waiting until instant which has passed is ready immediately", | ||
| ); | ||
| } | ||
|
|
||
| fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| use test_programs::p3::wasi::random; | ||
|
|
||
| struct Component; | ||
|
|
||
| test_programs::p3::export!(Component); | ||
|
|
||
| impl test_programs::p3::exports::wasi::cli::run::Guest for Component { | ||
| async fn run() -> Result<(), ()> { | ||
| // Acquired random bytes should be of the expected length. | ||
| let array = random::random::get_random_bytes(100); | ||
| assert_eq!(array.len(), 100); | ||
|
|
||
| // It shouldn't take 100+ tries to get a nonzero random integer. | ||
| for i in 0.. { | ||
| if random::random::get_random_u64() == 0 { | ||
| continue; | ||
| } | ||
| assert!(i < 100); | ||
| break; | ||
| } | ||
|
|
||
| // The `insecure_seed` API should return the same result each time. | ||
| let (a1, b1) = random::insecure_seed::insecure_seed(); | ||
| let (a2, b2) = random::insecure_seed::insecure_seed(); | ||
| assert_eq!(a1, a2); | ||
| assert_eq!(b1, b2); | ||
|
|
||
| // Acquired random bytes should be of the expected length. | ||
| let array = random::insecure::get_insecure_random_bytes(100); | ||
| assert_eq!(array.len(), 100); | ||
|
|
||
| // It shouldn't take 100+ tries to get a nonzero random integer. | ||
| for i in 0.. { | ||
| if random::insecure::get_insecure_random_u64() == 0 { | ||
| continue; | ||
| } | ||
| assert!(i < 100); | ||
| break; | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| pub mod async_; | ||
| pub mod http; | ||
| pub mod nn; | ||
| pub mod p3; | ||
| pub mod preview1; | ||
| pub mod sockets; | ||
| pub mod tls; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| wit_bindgen::generate!({ | ||
| inline: " | ||
| package wasmtime:test; | ||
|
|
||
| world testp3 { | ||
| include wasi:cli/[email protected]; | ||
|
|
||
| export wasi:cli/[email protected]; | ||
| } | ||
| ", | ||
| path: "../wasi/src/p3/wit", | ||
| world: "wasmtime:test/testp3", | ||
| default_bindings_module: "test_programs::p3", | ||
| pub_export_macro: true, | ||
| async: [ | ||
| "wasi:cli/[email protected]#run", | ||
| ], | ||
| generate_all | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.