Conversation
There was a problem hiding this comment.
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.
should we update the existing to use wasip2 target?
Lines 47 to 49 in 192a036
There was a problem hiding this comment.
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.