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
604 changes: 378 additions & 226 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 12 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,18 @@ 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.14.0", default-features = false }
hyperlight-component-macro = { version = "0.14.0" }
hyperlight-host = { version = "0.14.0", default-features = false, features = ["executable_heap"] }
hyperlight-wasm = { git = "https://github.com/jsturtevant/hyperlight-wasm", rev = "13906096edc2e014220c11a040242070ce6dee90" } #branch util-compont-fixes
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" }
pyo3 = { version = "0.29", features = ["extension-module"] }

# hyperlight-wasm 0.13.1 (git) depends on hyperlight-* from the hyperlight-dev
# GitHub org. Redirect those to the published 0.14.0 crates.io versions.
[patch."https://github.com/hyperlight-dev/hyperlight"]
hyperlight-common = { version = "0.14.0" }
hyperlight-guest = { version = "=0.14.0" }
hyperlight-guest-bin = { version = "=0.14.0" }
hyperlight-host = { version = "0.14.0" }
hyperlight-component-util = { git = "https://github.com/jsturtevant/hyperlight-1", rev="cdbed80af127b4d74e2633511cadb07bfea0160e", package = "hyperlight-component-util" }

[patch.crates-io]
hyperlight-component-util = { git = "https://github.com/jsturtevant/hyperlight-1", rev="cdbed80af127b4d74e2633511cadb07bfea0160e", package = "hyperlight-component-util" }
# 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" }
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 = "dd118685db5da1aca3c22c51752ab1816de311cb" }
hyperlight-js = { git = "https://github.com/hyperlight-dev/hyperlight-js.git", rev = "915608fbc30e922c7ed03aa08b05c3a3a5614f39" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

Expand Down
4 changes: 2 additions & 2 deletions src/wasm_sandbox/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ ensure-tools:
# (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 13906096edc2e014220c11a040242070ce6dee90
--rev 447c5893fc916f1e9faf9aaac59afc45e6591d1f

[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 13906096edc2e014220c11a040242070ce6dee90
cargo install hyperlight-wasm-aot --locked --force --git https://github.com/jsturtevant/hyperlight-wasm --rev 447c5893fc916f1e9faf9aaac59afc45e6591d1f

guest-build-wasm: ensure-tools
cd {{repo-root}}/src/wasm_sandbox/guests/python && uv run componentize-py \
Expand Down
22 changes: 9 additions & 13 deletions src/wasm_sandbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ impl bindings::root::component::RootImports for HostState {
self
}

type WasiFilesystemTypes = HostState;
fn wasi_filesystem_types(&mut self) -> &mut Self {
type WasiFilesystemTypesV020 = HostState;
fn wasi_filesystem_types_v0_2_0(&mut self) -> &mut Self {
self
}

type WasiHttpTypes = HostState;
fn wasi_http_types(&mut self) -> &mut Self {
type WasiHttpTypesV020 = HostState;
fn wasi_http_types_v0_2_0(&mut self) -> &mut Self {
self
}

Expand Down Expand Up @@ -197,22 +197,18 @@ impl bindings::root::component::RootImports for HostState {
}

impl bindings::hyperlight::sandbox::Tools for HostState {
fn dispatch(
&mut self,
name: String,
args_json: String,
) -> Result<Result<String, String>, hyperlight_host::HyperlightError> {
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,
Err(error) => return Ok(Err(error.to_string())),
Err(error) => return Err(error.to_string()),
};
Ok(match self.tools.dispatch(&name, args) {
match self.tools.dispatch(&name, args) {
Ok(v) => match serde_json::to_string(&v) {
Ok(s) => Ok(s),
Err(e) => Err(format!("serialization failed: {e}")),
},
Err(e) => Err(e.to_string()),
})
}
}
}

Expand Down Expand Up @@ -270,7 +266,7 @@ impl WasmComponentSandbox {
}

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

self.fs
.lock()
Expand Down
26 changes: 11 additions & 15 deletions src/wasm_sandbox/src/wasi_impl/cli.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
//! CLI trait implementations: Environment, Exit, Stdin/Stdout/Stderr, Terminals.
#![allow(unused_variables)]

use hyperlight_host::HyperlightError;

use crate::HostState;
use crate::bindings::wasi;
use crate::wasi_impl::resource::Resource;
use crate::wasi_impl::types::stream::Stream;

type HlResult<T> = Result<T, HyperlightError>;
type HlResult<T> = T;

// ---------------------------------------------------------------------------
// CLI: Environment, Exit, Stdin/Stdout/Stderr
// ---------------------------------------------------------------------------

impl wasi::cli::Environment for HostState {
fn get_environment(&mut self) -> HlResult<Vec<(String, String)>> {
Ok(Vec::new())
Vec::new()
}
fn get_arguments(&mut self) -> HlResult<Vec<String>> {
Ok(Vec::new())
Vec::new()
}
fn initial_cwd(&mut self) -> HlResult<Option<String>> {
Ok(None)
None
}
}

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

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

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

impl wasi::cli::Stderr<Resource<Stream>> for HostState {
fn get_stderr(&mut self) -> HlResult<Resource<Stream>> {
Ok(Resource::new(Stream::new()))
Resource::new(Stream::new())
}
}

Expand All @@ -66,18 +62,18 @@ impl wasi::cli::TerminalOutput for HostState {}

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

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

impl wasi::cli::TerminalStderr<u32> for HostState {
fn get_terminal_stderr(&mut self) -> HlResult<Option<u32>> {
Ok(None)
None
}
}
25 changes: 11 additions & 14 deletions src/wasm_sandbox/src/wasi_impl/clocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
use std::sync::LazyLock;
use std::time::Duration;

use hyperlight_host::HyperlightError;
use wasi::clocks::{monotonic_clock, wall_clock};

use crate::HostState;
use crate::bindings::wasi;
use crate::wasi_impl::resource::Resource;
use crate::wasi_impl::types::pollable::AnyPollable;

type HlResult<T> = Result<T, HyperlightError>;
type HlResult<T> = T;

static EPOCH: LazyLock<std::time::Instant> = LazyLock::new(std::time::Instant::now);

Expand All @@ -22,28 +21,26 @@ fn now() -> u64 {

impl wasi::clocks::MonotonicClock<Resource<AnyPollable>> for HostState {
fn now(&mut self) -> HlResult<monotonic_clock::Instant> {
Ok(now())
now()
}
fn resolution(&mut self) -> HlResult<monotonic_clock::Duration> {
Ok(1)
1
}
fn subscribe_instant(
&mut self,
when: monotonic_clock::Instant,
) -> HlResult<Resource<AnyPollable>> {
Ok(Resource::new(AnyPollable::future(
tokio::time::sleep_until(
tokio::time::Instant::now() + Duration::from_nanos(when.saturating_sub(now())),
),
Resource::new(AnyPollable::future(tokio::time::sleep_until(
tokio::time::Instant::now() + Duration::from_nanos(when.saturating_sub(now())),
)))
}
fn subscribe_duration(
&mut self,
when: monotonic_clock::Duration,
) -> HlResult<Resource<AnyPollable>> {
Ok(Resource::new(AnyPollable::future(tokio::time::sleep(
Resource::new(AnyPollable::future(tokio::time::sleep(
Duration::from_nanos(when),
))))
)))
}
}

Expand All @@ -52,15 +49,15 @@ impl wasi::clocks::WallClock for HostState {
let d = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default();
Ok(wall_clock::Datetime {
wall_clock::Datetime {
seconds: d.as_secs(),
nanoseconds: d.subsec_nanos(),
})
}
}
fn resolution(&mut self) -> HlResult<wall_clock::Datetime> {
Ok(wall_clock::Datetime {
wall_clock::Datetime {
seconds: 0,
nanoseconds: 1,
})
}
}
}
Loading
Loading