Skip to content

Refactor and update dependencies#10

Open
dblnz wants to merge 3 commits intohyperlight-dev:mainfrom
dblnz:refactor-and-update-dependencies
Open

Refactor and update dependencies#10
dblnz wants to merge 3 commits intohyperlight-dev:mainfrom
dblnz:refactor-and-update-dependencies

Conversation

@dblnz
Copy link
Contributor

@dblnz dblnz commented Mar 17, 2026

This PR:

  • refactors the application to move the wasi implementation related code to a specific module
  • changes the hyperlight-wasm-http-sample tool to allow a wasmtime like CLI
  • updates the hyperlight and hyperlight-wasm versions

dblnz added 3 commits March 17, 2026 23:34
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>
@dblnz dblnz force-pushed the refactor-and-update-dependencies branch from c5de5f5 to 73b9b86 Compare March 17, 2026 21:35
@dblnz dblnz requested a review from Copilot March 18, 2026 15:05
Copy link

Copilot AI left a 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 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_pool and updated main.rs to use a clap-based run/serve CLI and a shared sandbox pool.
  • Introduced new WASI HTTP support types (Headers, Buffer, FutureHttp) and reorganized imports under crate::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
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants