-
Notifications
You must be signed in to change notification settings - Fork 33
Add wasi p2 example using rustc native p2 target #344
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a Monte Carlo Pi estimation example demonstrating the use of the native wasm32-wasip2 Rust target with wit-bindgen (as an alternative to cargo-component). The example showcases host-guest interaction where the guest component depends on the host to provide random numbers for the Monte Carlo simulation.
Changes:
- Adds a new
wasip2_guestcrate that builds a WASI P2 component using nativewasm32-wasip2target - Implements a Monte Carlo Pi estimator as the guest component that imports a random number interface from the host
- Adds host example
monte_carlo_examplethat provides random number generation to the guest and runs the estimation
Reviewed changes
Copilot reviewed 6 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/wasip2_guest/wit/monte-carlo.wit |
WIT interface definition for the Monte Carlo estimator with random number import |
src/wasip2_guest/src/lib.rs |
Guest component implementation of Monte Carlo Pi estimation in no_std mode |
src/wasip2_guest/Cargo.toml |
Package configuration for the WASI P2 guest component |
src/wasip2_guest/Cargo.lock |
Dependency lock file for the standalone guest workspace |
src/hyperlight_wasm/examples/monte_carlo_example/main.rs |
Host example that provides RNG and runs the Monte Carlo estimation |
src/hyperlight_wasm/Cargo.toml |
Adds monte_carlo_example entry and rand 0.8 dependency |
Justfile |
Adds build and run targets for the Monte Carlo example |
Cargo.lock |
Updates workspace dependencies including rand 0.8.5 |
.gitignore |
Broadens pattern to ignore all .wasm files instead of specific paths |
Comments suppressed due to low confidence (1)
Justfile:67
- The
wasip2_guestcrate should be included in thechecktarget for consistency with other guest crates. Add a check command for wasip2_guest similar to how component_sample and rust_wasm_samples are checked.
check target=default-target:
cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/rust_wasm_samples && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/component_sample && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/wasm_runtime && cargo hyperlight check --profile={{ if target == "debug" {"dev"} else { target } }}
cd src/hyperlight_wasm_macro && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
| # Always build in release mode to avoid WASI dependencies (debug mode pulls in entire WASI for some reason) | ||
| rustup target add wasm32-wasip2 | ||
| cd ./src/wasip2_guest && cargo build --lib --target wasm32-wasip2 --release | ||
| cargo run {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--features " + features } }} -p hyperlight-wasm-aot compile {{ if features =~ "gdb" {"--debug"} else {""} }} --component ./src/wasip2_guest/target/wasm32-wasip2/release/monte_carlo.wasm ./x64/release/monte_carlo.aot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we update the existing to use wasip2 target?
Lines 47 to 49 in 192a036
| # use cargo component so we don't get all the wasi imports https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#relationship-with-wasm32-wasip2 | |
| # we also explicitly target wasm32-unknown-unknown since cargo component might try to pull in wasi imports https://github.com/bytecodealliance/cargo-component/issues/290 | |
| rustup target add wasm32-unknown-unknown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently it only works in release mode, so I would say let's wait a bit longer. in debug profile, it still does bring in entire wasi
No description provided.