Open
Conversation
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
c5de5f5 to
73b9b86
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the host-side WASI implementation into a dedicated wasi_impl module, introduces a reusable sandbox pool, and upgrades Hyperlight dependencies to 0.12.0, enabling both CLI run and HTTP serve modes with optional environment-variable passthrough.
Changes:
- Added
sandbox_pooland updatedmain.rsto use aclap-basedrun/serveCLI and a shared sandbox pool. - Introduced new WASI HTTP support types (
Headers,Buffer,FutureHttp) and reorganized imports undercrate::wasi_impl. - Bumped Hyperlight crate versions / tooling versions and updated documentation/run commands.
Reviewed changes
Copilot reviewed 28 out of 34 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/wasi_impl/worker.rs | Adds a global Tokio runtime used across host components. |
| src/wasi_impl/mod.rs | Introduces the wasi_impl module boundary and re-exports Resource. |
| src/wasi_impl/resource.rs | Updates module paths and continues to centralize async/blocking helpers. |
| src/wasi_impl/types.rs | Extends WasiImpl state (env vars) and adjusts imports for new module layout. |
| src/wasi_impl/types/* | Repoints imports to crate::wasi_impl and adds new HTTP helper types. |
| src/sandbox_pool.rs | Adds a sandbox pool and sandbox construction logic (including env parsing). |
| src/main.rs | Replaces one-off sandbox setup with clap CLI + sandbox pool; adds run/serve. |
| Cargo.toml / Cargo.lock | Upgrades Hyperlight and adds CLI/pooling dependencies. |
| justfile | Updates hyperlight-wasm-aot version and run commands. |
| README.md | Updates run instructions for new CLI interface. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+28
to
+44
| pub fn get_sandbox(&mut self) -> RootSandbox<WasiImpl, LoadedWasmSandbox> { | ||
| if let Some(sandbox) = self.pool.pop() { | ||
| sandbox | ||
| } else { | ||
| println!("Sandbox pool is empty, building a new sandbox"); | ||
| build_sandbox( | ||
| &self | ||
| .options | ||
| .as_ref() | ||
| .expect("SandboxPool not initialized with options"), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| pub fn return_sandbox(&mut self, sandbox: RootSandbox<WasiImpl, LoadedWasmSandbox>) { | ||
| self.pool.push(sandbox); | ||
| } |
Comment on lines
+68
to
+83
| fn build_sandbox(options: &CliOptions) -> RootSandbox<WasiImpl, LoadedWasmSandbox> { | ||
| let wasm_size = std::fs::metadata(&options.wasm_file) | ||
| .unwrap_or_else(|e| panic!("cannot stat wasm file '{}': {e}", options.wasm_file)) | ||
| .len(); | ||
|
|
||
| let builder = builder(wasm_size); | ||
| let mut sb = builder.build().unwrap(); | ||
|
|
||
| let mut state = WasiImpl::new(); | ||
| state.env_vars = parse_envs(&options.envs); | ||
|
|
||
| let rt = wasi_impl::bindings::register_host_functions(&mut sb, state); | ||
|
|
||
| let sb = sb.load_runtime().unwrap(); | ||
| let sb = sb.load_module(&options.wasm_file).unwrap(); | ||
|
|
| let mut sb = sb.lock().await; | ||
| let inst = bindings::root::component::RootExports::incoming_handler(&mut *sb); | ||
| let mut sb = SANDBOX_POOL.lock().await.get_sandbox(); | ||
| let snapshot = sb.sb.snapshot().unwrap(); |
Comment on lines
203
to
+211
| tokio::task::block_in_place(|| { | ||
| inst.handle(req, outparam.clone()); | ||
| }); | ||
|
|
||
| sb.sb.restore(&snapshot).unwrap(); | ||
|
|
||
| // Return the sandbox to the pool immediately after the call, so it's available for the next | ||
| // request while we wait for the guest to produce a response. | ||
| SANDBOX_POOL.lock().await.return_sandbox(sb); |
Comment on lines
+1
to
+4
| use crate::CliOptions; | ||
| use crate::WasiImpl; | ||
| use crate::wasi_impl; | ||
| use crate::wasi_impl::bindings::RootSandbox; |
Comment on lines
95
to
103
| Rust: | ||
| ```sh | ||
| cargo run -- out/sample_wasi_http_rust.aot | ||
| cargo run -- serve --addr 0.0.0.0:9999 {{ OUT_DIR }}/sample_wasi_http_rust.aot | ||
| ``` | ||
|
|
||
| JS: | ||
| ```sh | ||
| cargo run -- out/sample_wasi_http_js.aot | ||
| cargo run -- serve --addr 0.0.0.0:8888 {{ OUT_DIR }}/sample_wasi_http_js.aot | ||
| ``` |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR:
modulehyperlight-wasm-http-sampletool to allow awasmtimelike CLI