Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
273 changes: 228 additions & 45 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@ resolver = "2"
[workspace.package]
version = "0.5.0"
edition = "2024"
rust-version = "1.89"
rust-version = "1.94"
license = "Apache-2.0"

[workspace.dependencies]
hyperlight-sandbox = { path = "src/hyperlight_sandbox" }
hyperlight-javascript-sandbox = { path = "src/javascript_sandbox" }
hyperlight-wasm-sandbox = { path = "src/wasm_sandbox" }
hyperlight-sandbox-pyo3-common = { path = "src/sdk/python/pyo3_common" }
hyperlight-common = { version = "0.15.0", default-features = false }
hyperlight-component-macro = { version = "0.15.0" }
hyperlight-host = { version = "0.15.0", default-features = false, features = ["executable_heap"] }
# https://github.com/jsturtevant/hyperlight-wasm/tree/sandbox-component-bindgen-prs
hyperlight-wasm = { git = "https://github.com/jsturtevant/hyperlight-wasm", rev = "447c5893fc916f1e9faf9aaac59afc45e6591d1f" }
hyperlight-common = { git = "https://github.com/hyperlight-dev/hyperlight", rev = "cfa020441d880d599cc516a050e6cf10236ca5c4", default-features = false }
hyperlight-component-macro = { git = "https://github.com/hyperlight-dev/hyperlight", rev = "cfa020441d880d599cc516a050e6cf10236ca5c4" }
hyperlight-host = { git = "https://github.com/hyperlight-dev/hyperlight", rev = "cfa020441d880d599cc516a050e6cf10236ca5c4", default-features = false, features = ["executable_heap"] }
# https://github.com/hyperlight-dev/hyperlight-wasm/pull/520
hyperlight-wasm = { git = "https://github.com/hyperlight-dev/hyperlight-wasm", rev = "2757fb9ff3e117c1513c325b3b32d3abd9918e9d" }
pyo3 = { version = "0.29", features = ["extension-module"] }

[patch.crates-io]
# https://github.com/jsturtevant/hyperlight-1/tree/sandbox-component-bindgen-prs
hyperlight-common = { git = "https://github.com/jsturtevant/hyperlight-1", rev = "2640a824b59d18e633e706e5639c7da30e7ad5fc", package = "hyperlight-common" }
hyperlight-component-macro = { git = "https://github.com/jsturtevant/hyperlight-1", rev = "2640a824b59d18e633e706e5639c7da30e7ad5fc", package = "hyperlight-component-macro" }
hyperlight-component-util = { git = "https://github.com/jsturtevant/hyperlight-1", rev = "2640a824b59d18e633e706e5639c7da30e7ad5fc", package = "hyperlight-component-util" }
hyperlight-guest = { git = "https://github.com/jsturtevant/hyperlight-1", rev = "2640a824b59d18e633e706e5639c7da30e7ad5fc", package = "hyperlight-guest" }
hyperlight-guest-bin = { git = "https://github.com/jsturtevant/hyperlight-1", rev = "2640a824b59d18e633e706e5639c7da30e7ad5fc", package = "hyperlight-guest-bin" }
hyperlight-host = { git = "https://github.com/jsturtevant/hyperlight-1", rev = "2640a824b59d18e633e706e5639c7da30e7ad5fc", package = "hyperlight-host" }
hyperlight-common = { git = "https://github.com/hyperlight-dev/hyperlight", rev = "cfa020441d880d599cc516a050e6cf10236ca5c4" }
hyperlight-component-macro = { git = "https://github.com/hyperlight-dev/hyperlight", rev = "cfa020441d880d599cc516a050e6cf10236ca5c4" }
hyperlight-component-util = { git = "https://github.com/hyperlight-dev/hyperlight", rev = "cfa020441d880d599cc516a050e6cf10236ca5c4" }
hyperlight-guest = { git = "https://github.com/hyperlight-dev/hyperlight", rev = "cfa020441d880d599cc516a050e6cf10236ca5c4" }
hyperlight-guest-bin = { git = "https://github.com/hyperlight-dev/hyperlight", rev = "cfa020441d880d599cc516a050e6cf10236ca5c4" }
hyperlight-host = { git = "https://github.com/hyperlight-dev/hyperlight", rev = "cfa020441d880d599cc516a050e6cf10236ca5c4" }
2 changes: 1 addition & 1 deletion src/javascript_sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "Hyperlight JS guest for hyperlight-sandbox"
hyperlight-sandbox.workspace = true
anyhow = "1"
url = "2"
hyperlight-js = { git = "https://github.com/hyperlight-dev/hyperlight-js.git", rev = "915608fbc30e922c7ed03aa08b05c3a3a5614f39" }
hyperlight-js = { git = "https://github.com/hyperlight-dev/hyperlight-js.git", rev = "b96774e7e19ce1945775498cd83d305a915e28df" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

Expand Down
6 changes: 3 additions & 3 deletions src/wasm_sandbox/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ ensure-tools:
# even if the cached binary was compiled with different dependency versions
# (e.g. a stale wasmtime patch from the CI Cargo bin cache).
cargo install hyperlight-wasm-aot --locked --force \
--git https://github.com/jsturtevant/hyperlight-wasm \
--rev 447c5893fc916f1e9faf9aaac59afc45e6591d1f
--git https://github.com/hyperlight-dev/hyperlight-wasm \
--rev 2757fb9ff3e117c1513c325b3b32d3abd9918e9d

[windows]
ensure-tools:
if (-not (Get-Command clang -ErrorAction SilentlyContinue)) { Write-Error 'clang not found — install with: winget install LLVM.LLVM'; exit 1 }; \
if (-not (Get-Command wasm-tools -ErrorAction SilentlyContinue)) { cargo install wasm-tools --locked }; \
cargo install hyperlight-wasm-aot --locked --force --git https://github.com/jsturtevant/hyperlight-wasm --rev 447c5893fc916f1e9faf9aaac59afc45e6591d1f
cargo install hyperlight-wasm-aot --locked --force --git https://github.com/hyperlight-dev/hyperlight-wasm --rev 2757fb9ff3e117c1513c325b3b32d3abd9918e9d

guest-build-wasm: ensure-tools
cd {{repo-root}}/src/wasm_sandbox/guests/python && uv run componentize-py \
Expand Down
10 changes: 6 additions & 4 deletions src/wasm_sandbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use hyperlight_wasm::{

mod wasi_impl;

type HostBindings = hyperlight_common::component::Negative;

pub(crate) mod bindings {
hyperlight_component_macro::host_bindgen!("wit/sandbox-world.wasm");
}
Expand Down Expand Up @@ -44,7 +46,7 @@ pub struct HostState {
}

#[allow(refining_impl_trait)]
impl bindings::root::component::RootImports for HostState {
impl bindings::root::component::RootImports<HostBindings> for HostState {
type Tools = HostState;
fn tools(&mut self) -> &mut Self {
self
Expand Down Expand Up @@ -196,7 +198,7 @@ impl bindings::root::component::RootImports for HostState {
}
}

impl bindings::hyperlight::sandbox::Tools for HostState {
impl bindings::hyperlight::sandbox::Tools<HostBindings> for HostState {
fn dispatch(&mut self, name: String, args_json: String) -> Result<String, String> {
let args: serde_json::Value = match serde_json::from_str(&args_json) {
Ok(args) => args,
Expand Down Expand Up @@ -249,7 +251,7 @@ impl WasmComponentSandbox {
.build()
.context("failed to build ProtoWasmSandbox")?;

let rt = bindings::register_host_functions(&mut proto, state);
let rt = bindings::register_host_functions(&mut proto, state)?;

let wasm_sandbox = proto
.load_runtime()
Expand All @@ -266,7 +268,7 @@ impl WasmComponentSandbox {
}

fn run_impl(&mut self, code: &str) -> Result<ExecutionResult> {
use bindings::hyperlight::sandbox::ExecutorExports;
use bindings::hyperlight::sandbox::Executor;

self.fs
.lock()
Expand Down
24 changes: 12 additions & 12 deletions src/wasm_sandbox/src/wasi_impl/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type HlResult<T> = T;
// CLI: Environment, Exit, Stdin/Stdout/Stderr
// ---------------------------------------------------------------------------

impl wasi::cli::Environment for HostState {
impl wasi::cli::Environment<crate::HostBindings> for HostState {
fn get_environment(&mut self) -> HlResult<Vec<(String, String)>> {
Vec::new()
}
Expand All @@ -24,23 +24,23 @@ impl wasi::cli::Environment for HostState {
}
}

impl wasi::cli::Exit for HostState {
impl wasi::cli::Exit<crate::HostBindings> for HostState {
fn exit(&mut self, _status: Result<(), ()>) -> HlResult<()> {}
}

impl wasi::cli::Stdin<Resource<Stream>> for HostState {
impl wasi::cli::Stdin<crate::HostBindings, Resource<Stream>> for HostState {
fn get_stdin(&mut self) -> HlResult<Resource<Stream>> {
Resource::new(Stream::new())
}
}

impl wasi::cli::Stdout<Resource<Stream>> for HostState {
impl wasi::cli::Stdout<crate::HostBindings, Resource<Stream>> for HostState {
fn get_stdout(&mut self) -> HlResult<Resource<Stream>> {
Resource::new(Stream::new())
}
}

impl wasi::cli::Stderr<Resource<Stream>> for HostState {
impl wasi::cli::Stderr<crate::HostBindings, Resource<Stream>> for HostState {
fn get_stderr(&mut self) -> HlResult<Resource<Stream>> {
Resource::new(Stream::new())
}
Expand All @@ -50,29 +50,29 @@ impl wasi::cli::Stderr<Resource<Stream>> for HostState {
// CLI: Terminals (stubs — no terminal support)
// ---------------------------------------------------------------------------

impl wasi::cli::terminal_input::TerminalInput for HostState {
impl wasi::cli::terminal_input::TerminalInput<crate::HostBindings> for HostState {
type T = u32;
}
impl wasi::cli::TerminalInput for HostState {}
impl wasi::cli::TerminalInput<crate::HostBindings> for HostState {}

impl wasi::cli::terminal_output::TerminalOutput for HostState {
impl wasi::cli::terminal_output::TerminalOutput<crate::HostBindings> for HostState {
type T = u32;
}
impl wasi::cli::TerminalOutput for HostState {}
impl wasi::cli::TerminalOutput<crate::HostBindings> for HostState {}

impl wasi::cli::TerminalStdin<u32> for HostState {
impl wasi::cli::TerminalStdin<crate::HostBindings, u32> for HostState {
fn get_terminal_stdin(&mut self) -> HlResult<Option<u32>> {
None
}
}

impl wasi::cli::TerminalStdout<u32> for HostState {
impl wasi::cli::TerminalStdout<crate::HostBindings, u32> for HostState {
fn get_terminal_stdout(&mut self) -> HlResult<Option<u32>> {
None
}
}

impl wasi::cli::TerminalStderr<u32> for HostState {
impl wasi::cli::TerminalStderr<crate::HostBindings, u32> for HostState {
fn get_terminal_stderr(&mut self) -> HlResult<Option<u32>> {
None
}
Expand Down
4 changes: 2 additions & 2 deletions src/wasm_sandbox/src/wasi_impl/clocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn now() -> u64 {
std::time::Instant::now().duration_since(*EPOCH).as_nanos() as u64
}

impl wasi::clocks::MonotonicClock<Resource<AnyPollable>> for HostState {
impl wasi::clocks::MonotonicClock<crate::HostBindings, Resource<AnyPollable>> for HostState {
fn now(&mut self) -> HlResult<monotonic_clock::Instant> {
now()
}
Expand All @@ -44,7 +44,7 @@ impl wasi::clocks::MonotonicClock<Resource<AnyPollable>> for HostState {
}
}

impl wasi::clocks::WallClock for HostState {
impl wasi::clocks::WallClock<crate::HostBindings> for HostState {
fn now(&mut self) -> HlResult<wall_clock::Datetime> {
let d = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
Expand Down
23 changes: 17 additions & 6 deletions src/wasm_sandbox/src/wasi_impl/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl From<FsError> for fs_types::ErrorCode {
// DirectoryEntryStream
// ---------------------------------------------------------------------------

impl fs_types::DirectoryEntryStream for HostState {
impl fs_types::DirectoryEntryStream<crate::HostBindings> for HostState {
type T = u32;
fn read_directory_entry(
&mut self,
Expand Down Expand Up @@ -64,8 +64,14 @@ impl fs_types::DirectoryEntryStream for HostState {
// Descriptor
// ---------------------------------------------------------------------------

impl fs_types::Descriptor<wall_clock::Datetime, u32, Resource<Stream>, Resource<Stream>>
for HostState
impl
fs_types::Descriptor<
crate::HostBindings,
wall_clock::Datetime,
u32,
Resource<Stream>,
Resource<Stream>,
> for HostState
{
type T = u32;

Expand Down Expand Up @@ -380,8 +386,13 @@ impl fs_types::Descriptor<wall_clock::Datetime, u32, Resource<Stream>, Resource<
}

impl
wasi::filesystem::Types<wall_clock::Datetime, anyhow::Error, Resource<Stream>, Resource<Stream>>
for HostState
wasi::filesystem::Types<
crate::HostBindings,
wall_clock::Datetime,
anyhow::Error,
Resource<Stream>,
Resource<Stream>,
> for HostState
{
fn filesystem_error_code(
&mut self,
Expand All @@ -391,7 +402,7 @@ impl
}
}

impl wasi::filesystem::Preopens<u32> for HostState {
impl wasi::filesystem::Preopens<crate::HostBindings, u32> for HostState {
fn get_directories(&mut self) -> HlResult<Vec<(u32, String)>> {
let Ok(fs) = self.fs.lock() else {
return Vec::new();
Expand Down
52 changes: 38 additions & 14 deletions src/wasm_sandbox/src/wasi_impl/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl From<HeaderError> for http_types::HeaderError {
}
}

impl http_types::Fields for HostState {
impl http_types::Fields<crate::HostBindings> for HostState {
type T = Resource<Headers>;

fn new(&mut self) -> Resource<Headers> {
Expand Down Expand Up @@ -115,7 +115,9 @@ impl http_types::Fields for HostState {
// IncomingRequest
// ---------------------------------------------------------------------------

impl http_types::IncomingRequest<Resource<Headers>, Resource<IncomingBody>> for HostState {
impl http_types::IncomingRequest<crate::HostBindings, Resource<Headers>, Resource<IncomingBody>>
for HostState
{
type T = Resource<IncomingRequest>;
fn method(
&mut self,
Expand Down Expand Up @@ -164,7 +166,9 @@ impl http_types::IncomingRequest<Resource<Headers>, Resource<IncomingBody>> for
// OutgoingRequest
// ---------------------------------------------------------------------------

impl http_types::OutgoingRequest<Resource<Headers>, Resource<OutgoingBody>> for HostState {
impl http_types::OutgoingRequest<crate::HostBindings, Resource<Headers>, Resource<OutgoingBody>>
for HostState
{
type T = Resource<OutgoingRequest>;
fn new(&mut self, headers: Resource<Headers>) -> Resource<OutgoingRequest> {
Resource::new(OutgoingRequest::new(headers))
Expand Down Expand Up @@ -248,7 +252,7 @@ fn as_u64_nanos_saturating(duration: &std::time::Duration) -> u64 {
duration.as_nanos().min(u64::MAX as u128) as u64
}

impl http_types::RequestOptions<u64> for HostState {
impl http_types::RequestOptions<crate::HostBindings, u64> for HostState {
type T = Resource<RequestOptions>;
fn new(&mut self) -> Resource<RequestOptions> {
Resource::default()
Expand Down Expand Up @@ -317,7 +321,7 @@ impl http_types::RequestOptions<u64> for HostState {
// ResponseOutparam
// ---------------------------------------------------------------------------

impl http_types::ResponseOutparam<Resource<OutgoingResponse>> for HostState {
impl http_types::ResponseOutparam<crate::HostBindings, Resource<OutgoingResponse>> for HostState {
type T = Resource<ResponseOutparam>;
fn set(
&mut self,
Expand All @@ -332,7 +336,9 @@ impl http_types::ResponseOutparam<Resource<OutgoingResponse>> for HostState {
// IncomingResponse
// ---------------------------------------------------------------------------

impl http_types::IncomingResponse<Resource<Headers>, Resource<IncomingBody>> for HostState {
impl http_types::IncomingResponse<crate::HostBindings, Resource<Headers>, Resource<IncomingBody>>
for HostState
{
type T = Resource<IncomingResponse>;
fn status(
&mut self,
Expand Down Expand Up @@ -363,7 +369,9 @@ impl http_types::IncomingResponse<Resource<Headers>, Resource<IncomingBody>> for
// IncomingBody
// ---------------------------------------------------------------------------

impl http_types::IncomingBody<Resource<FutureHeaders>, Resource<Stream>> for HostState {
impl http_types::IncomingBody<crate::HostBindings, Resource<FutureHeaders>, Resource<Stream>>
for HostState
{
type T = Resource<IncomingBody>;
fn stream(
&mut self,
Expand All @@ -385,7 +393,9 @@ impl http_types::IncomingBody<Resource<FutureHeaders>, Resource<Stream>> for Hos
// OutgoingBody
// ---------------------------------------------------------------------------

impl http_types::OutgoingBody<Resource<Headers>, Resource<Stream>> for HostState {
impl http_types::OutgoingBody<crate::HostBindings, Resource<Headers>, Resource<Stream>>
for HostState
{
type T = Resource<OutgoingBody>;
fn write(
&mut self,
Expand Down Expand Up @@ -415,7 +425,9 @@ impl http_types::OutgoingBody<Resource<Headers>, Resource<Stream>> for HostState
// OutgoingResponse
// ---------------------------------------------------------------------------

impl http_types::OutgoingResponse<Resource<Headers>, Resource<OutgoingBody>> for HostState {
impl http_types::OutgoingResponse<crate::HostBindings, Resource<Headers>, Resource<OutgoingBody>>
for HostState
{
type T = Resource<OutgoingResponse>;
fn new(&mut self, headers: Resource<Headers>) -> Resource<OutgoingResponse> {
Resource::new(OutgoingResponse::new(headers))
Expand Down Expand Up @@ -453,7 +465,9 @@ impl http_types::OutgoingResponse<Resource<Headers>, Resource<OutgoingBody>> for
// FutureTrailers
// ---------------------------------------------------------------------------

impl http_types::FutureTrailers<Resource<Headers>, Resource<AnyPollable>> for HostState {
impl http_types::FutureTrailers<crate::HostBindings, Resource<Headers>, Resource<AnyPollable>>
for HostState
{
type T = Resource<FutureHeaders>;
fn subscribe(
&mut self,
Expand All @@ -480,8 +494,12 @@ impl http_types::FutureTrailers<Resource<Headers>, Resource<AnyPollable>> for Ho
// FutureIncomingResponse
// ---------------------------------------------------------------------------

impl http_types::FutureIncomingResponse<Resource<IncomingResponse>, Resource<AnyPollable>>
for HostState
impl
http_types::FutureIncomingResponse<
crate::HostBindings,
Resource<IncomingResponse>,
Resource<AnyPollable>,
> for HostState
{
type T = Resource<FutureIncomingResponse>;
fn subscribe(
Expand All @@ -504,8 +522,14 @@ impl http_types::FutureIncomingResponse<Resource<IncomingResponse>, Resource<Any
// ---------------------------------------------------------------------------

impl
wasi::http::Types<u64, anyhow::Error, Resource<Stream>, Resource<Stream>, Resource<AnyPollable>>
for HostState
wasi::http::Types<
crate::HostBindings,
u64,
anyhow::Error,
Resource<Stream>,
Resource<Stream>,
Resource<AnyPollable>,
> for HostState
{
fn http_error_code(
&mut self,
Expand Down
1 change: 1 addition & 0 deletions src/wasm_sandbox/src/wasi_impl/http_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn wasi_method_to_http_method(

impl
wasi::http::OutgoingHandler<
crate::HostBindings,
ErrorCode,
Resource<FutureIncomingResponse>,
Resource<OutgoingRequest>,
Expand Down
Loading
Loading