From 53bf1ae3de48e50f511f15d5170d4ead6ca16d86 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 24 Feb 2026 11:25:50 -0800 Subject: [PATCH 1/9] Remove host function definition region dependency Instead of using a shared memory region or a host function callback to provide host function definitions to the guest, the host now pushes the serialized definitions directly as a parameter to InitWasmRuntime. Signed-off-by: James Sturtevant --- CHANGELOG.md | 3 ++ Cargo.lock | 1 + Cargo.toml | 1 + src/hyperlight_wasm/Cargo.toml | 1 + .../src/sandbox/loaded_wasm_sandbox.rs | 23 +++++++++ .../src/sandbox/proto_wasm_sandbox.rs | 47 ++++++++++++++++++- .../src/sandbox/sandbox_builder.rs | 8 ---- src/wasm_runtime/src/hostfuncs.rs | 4 -- src/wasm_runtime/src/module.rs | 33 +++++++++++-- 9 files changed, 102 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0792293..eca48d8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Prerelease] - Unreleased +### Changed +- **BREAKING CHANGE:** Removed `SandboxBuilder::with_function_definition_size`. Host function definitions are now pushed to the guest at runtime load time instead of using a separate memory region. (#388) + ## [v0.12.0] - 2025-12 ### Added diff --git a/Cargo.lock b/Cargo.lock index cb1c1fd9..e87483d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1543,6 +1543,7 @@ dependencies = [ "env_logger", "examples_common", "goblin", + "hyperlight-common", "hyperlight-component-macro", "hyperlight-host", "junction", diff --git a/Cargo.toml b/Cargo.toml index b5ae1597..6959cb6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ readme = "README.md" [workspace.dependencies] hyperlight-host = { version = "0.12.0", default-features = false, features = ["executable_heap", "init-paging"] } +hyperlight-common = { version = "0.12.0", default-features = false } diff --git a/src/hyperlight_wasm/Cargo.toml b/src/hyperlight_wasm/Cargo.toml index b091f863..a469c3d5 100644 --- a/src/hyperlight_wasm/Cargo.toml +++ b/src/hyperlight_wasm/Cargo.toml @@ -61,6 +61,7 @@ test = true [dependencies] hyperlight-host = { workspace = true } +hyperlight-common = { workspace = true } libc = { version = "0.2.182" } once_cell = "1.21.3" tracing = "0.1.44" diff --git a/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs index c926b989..30010878 100644 --- a/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs @@ -425,6 +425,29 @@ mod tests { assert_eq!(r, 0); } + #[test] + fn test_load_module_fails_with_missing_host_function() { + // HostFunction.aot imports "HostFuncWithBufferAndLength" from "env". + // Loading it without registering that host function should fail + // at instantiation time (linker.instantiate) because the import + // cannot be satisfied. + let proto_wasm_sandbox = SandboxBuilder::new().build().unwrap(); + + let wasm_sandbox = proto_wasm_sandbox.load_runtime().unwrap(); + + let result: std::result::Result = { + let mod_path = get_wasm_module_path("HostFunction.aot").unwrap(); + wasm_sandbox.load_module(mod_path) + }; + + let err = result.unwrap_err(); + let err_msg = format!("{:?}", err); + assert!( + err_msg.contains("HostFuncWithBufferAndLength"), + "Error should mention the missing host function, got: {err_msg}" + ); + } + fn call_funcs( mut loaded_wasm_sandbox: LoadedWasmSandbox, iterations: i32, diff --git a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs index 24a7a0f5..0d2e7eea 100644 --- a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs @@ -14,6 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ +use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterType, ReturnType}; +use hyperlight_common::flatbuffer_wrappers::host_function_definition::HostFunctionDefinition; +use hyperlight_common::flatbuffer_wrappers::host_function_details::HostFunctionDetails; use hyperlight_host::func::{HostFunction, ParameterTuple, Registerable, SupportedReturnType}; use hyperlight_host::sandbox::config::SandboxConfiguration; use hyperlight_host::{GuestBinary, Result, UninitializedSandbox, new_error}; @@ -31,6 +34,8 @@ use crate::build_info::BuildInfo; /// With that `WasmSandbox` you can load a Wasm module through the `load_module` method and get a `LoadedWasmSandbox` which can then execute functions defined in the Wasm module. pub struct ProtoWasmSandbox { pub(super) inner: Option, + /// Tracks registered host function definitions for pushing to the guest at load time + host_function_definitions: Vec, } impl Registerable for ProtoWasmSandbox { @@ -39,6 +44,13 @@ impl Registerable for ProtoWasmSandbox { name: &str, hf: impl Into>, ) -> Result<()> { + // Track the host function definition for pushing to guest at load time + self.host_function_definitions.push(HostFunctionDefinition { + function_name: name.to_string(), + parameter_types: Some(Args::TYPE.to_vec()), + return_type: Output::TYPE, + }); + self.inner .as_mut() .ok_or(new_error!("inner sandbox was none")) @@ -65,7 +77,18 @@ impl ProtoWasmSandbox { let inner = UninitializedSandbox::new(guest_binary, cfg)?; metrics::gauge!(METRIC_ACTIVE_PROTO_WASM_SANDBOXES).increment(1); metrics::counter!(METRIC_TOTAL_PROTO_WASM_SANDBOXES).increment(1); - Ok(Self { inner: Some(inner) }) + + // HostPrint is always registered by UninitializedSandbox, so include it by default + let host_function_definitions = vec![HostFunctionDefinition { + function_name: "HostPrint".to_string(), + parameter_types: Some(vec![ParameterType::String]), + return_type: ReturnType::Int, + }]; + + Ok(Self { + inner: Some(inner), + host_function_definitions, + }) } /// Load the Wasm runtime into the sandbox and return a `WasmSandbox` @@ -75,12 +98,22 @@ impl ProtoWasmSandbox { /// The returned `WasmSandbox` can be then be cached and used to load a different Wasm module. /// pub fn load_runtime(mut self) -> Result { + // Serialize host function definitions to push to the guest during InitWasmRuntime + let host_function_definitions = HostFunctionDetails { + host_functions: Some(std::mem::take(&mut self.host_function_definitions)), + }; + + let host_function_definitions_bytes: Vec = (&host_function_definitions) + .try_into() + .map_err(|e| new_error!("Failed to serialize host function details: {:?}", e))?; + let mut sandbox = match self.inner.take() { Some(s) => s.evolve()?, None => return Err(new_error!("No inner sandbox found.")), }; - let res: i32 = sandbox.call("InitWasmRuntime", ())?; + // Pass host function definitions to the guest as a parameter + let res: i32 = sandbox.call("InitWasmRuntime", (host_function_definitions_bytes,))?; if res != 0 { return Err(new_error!( "InitWasmRuntime Failed with error code {:?}", @@ -99,6 +132,13 @@ impl ProtoWasmSandbox { name: impl AsRef, host_func: impl Into>, ) -> Result<()> { + // Track the host function definition for pushing to guest at load time + self.host_function_definitions.push(HostFunctionDefinition { + function_name: name.as_ref().to_string(), + parameter_types: Some(Args::TYPE.to_vec()), + return_type: Output::TYPE, + }); + self.inner .as_mut() .ok_or(new_error!("inner sandbox was none"))? @@ -111,6 +151,9 @@ impl ProtoWasmSandbox { &mut self, print_func: impl Into>, ) -> Result<()> { + // HostPrint definition is already tracked from new() since + // UninitializedSandbox always registers a default HostPrint. + // This method only replaces the implementation, not the definition. self.inner .as_mut() .ok_or(new_error!("inner sandbox was none"))? diff --git a/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs b/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs index 0d2f7710..1c519f59 100644 --- a/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs +++ b/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs @@ -126,14 +126,6 @@ impl SandboxBuilder { self } - /// Set the size of the memory buffer that is made available - /// for serialising host function definitions the minimum value - /// is MIN_FUNCTION_DEFINITION_SIZE - pub fn with_function_definition_size(mut self, size: usize) -> Self { - self.config.set_host_function_definition_size(size); - self - } - /// Build the ProtoWasmSandbox pub fn build(self) -> Result { if !is_hypervisor_present() { diff --git a/src/wasm_runtime/src/hostfuncs.rs b/src/wasm_runtime/src/hostfuncs.rs index e468c557..ebf46df9 100644 --- a/src/wasm_runtime/src/hostfuncs.rs +++ b/src/wasm_runtime/src/hostfuncs.rs @@ -32,10 +32,6 @@ pub(crate) type HostFunctionDefinition = pub(crate) type HostFunctionDetails = hyperlight_common::flatbuffer_wrappers::host_function_details::HostFunctionDetails; -pub(crate) fn get_host_function_details() -> HostFunctionDetails { - hyperlight_guest_bin::host_comm::get_host_function_details() -} - pub(crate) fn hostfunc_type(d: &HostFunctionDefinition, e: &Engine) -> Result { let mut params = Vec::new(); let mut last_was_vec = false; diff --git a/src/wasm_runtime/src/module.rs b/src/wasm_runtime/src/module.rs index 195cf0ca..ba4fe082 100644 --- a/src/wasm_runtime/src/module.rs +++ b/src/wasm_runtime/src/module.rs @@ -96,7 +96,7 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result> { } #[instrument(skip_all, level = "Info")] -fn init_wasm_runtime() -> Result> { +fn init_wasm_runtime(function_call: &FunctionCall) -> Result> { let mut config = Config::new(); config.with_custom_code_memory(Some(alloc::sync::Arc::new(platform::WasmtimeCodeMemory {}))); #[cfg(gdb)] @@ -112,9 +112,32 @@ fn init_wasm_runtime() -> Result> { let mut linker = Linker::new(&engine); wasip1::register_handlers(&mut linker)?; - let hostfuncs = hostfuncs::get_host_function_details() - .host_functions - .unwrap_or_default(); + // Parse host function details pushed by the host as a parameter + let params = function_call.parameters.as_ref().ok_or_else(|| { + HyperlightGuestError::new( + ErrorCode::GuestFunctionParameterTypeMismatch, + "InitWasmRuntime: missing parameters".to_string(), + ) + })?; + + let bytes = match params.first() { + Some(ParameterValue::VecBytes(ref b)) => b, + _ => { + return Err(HyperlightGuestError::new( + ErrorCode::GuestFunctionParameterTypeMismatch, + "InitWasmRuntime: first parameter must be VecBytes".to_string(), + )) + } + }; + + let hfd: hostfuncs::HostFunctionDetails = bytes.as_slice().try_into().map_err(|e| { + HyperlightGuestError::new( + ErrorCode::GuestError, + alloc::format!("Failed to parse host function details: {:?}", e), + ) + })?; + let hostfuncs = hfd.host_functions.unwrap_or_default(); + for hostfunc in hostfuncs.iter() { let captured = hostfunc.clone(); linker.func_new( @@ -210,7 +233,7 @@ pub extern "C" fn hyperlight_main() { register_function(GuestFunctionDefinition::new( "InitWasmRuntime".to_string(), - vec![], + vec![ParameterType::VecBytes], ReturnType::Int, init_wasm_runtime as usize, )); From 011200186deffc9eeee6e3dbe44b538b1981d029 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 24 Feb 2026 11:44:06 -0800 Subject: [PATCH 2/9] Add [workspace] to excluded packages for worktree compatibility rust_wasm_samples, hyperlight_wasm_macro, and component_sample were missing empty [workspace] tables in their Cargo.toml files. Without this, Cargo resolves to the main checkout's workspace root when run from a git worktree, causing 'believes it's in a workspace' errors. wasm_runtime already had this marker. Signed-off-by: James Sturtevant --- src/component_sample/Cargo.toml | 1 + src/hyperlight_wasm_macro/Cargo.toml | 2 ++ src/rust_wasm_samples/Cargo.toml | 2 ++ src/wasm_runtime/src/component.rs | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/component_sample/Cargo.toml b/src/component_sample/Cargo.toml index 43ebd181..8f305af4 100644 --- a/src/component_sample/Cargo.toml +++ b/src/component_sample/Cargo.toml @@ -18,3 +18,4 @@ world = "example" [package.metadata.component.target.dependencies] +[workspace] # indicate that this crate is not part of any workspace diff --git a/src/hyperlight_wasm_macro/Cargo.toml b/src/hyperlight_wasm_macro/Cargo.toml index 19716bb2..b44fde5e 100644 --- a/src/hyperlight_wasm_macro/Cargo.toml +++ b/src/hyperlight_wasm_macro/Cargo.toml @@ -17,3 +17,5 @@ syn = { version = "2.0.117" } itertools = { version = "0.14.0" } prettyplease = { version = "0.2.37" } hyperlight-component-util = { version = "0.12.0" } + +[workspace] # indicate that this crate is not part of any workspace diff --git a/src/rust_wasm_samples/Cargo.toml b/src/rust_wasm_samples/Cargo.toml index 383d2472..b5684eec 100644 --- a/src/rust_wasm_samples/Cargo.toml +++ b/src/rust_wasm_samples/Cargo.toml @@ -14,5 +14,7 @@ opt-level = 'z' strip = true +[workspace] # indicate that this crate is not part of any workspace + [dependencies] diff --git a/src/wasm_runtime/src/component.rs b/src/wasm_runtime/src/component.rs index de07296a..f6439c3f 100644 --- a/src/wasm_runtime/src/component.rs +++ b/src/wasm_runtime/src/component.rs @@ -130,7 +130,7 @@ pub extern "C" fn hyperlight_main() { register_function(GuestFunctionDefinition::new( "InitWasmRuntime".to_string(), - vec![], + vec![ParameterType::VecBytes], ReturnType::Int, init_wasm_runtime as usize, )); From 2610e46aafa92aef80d0701a19f3a05ef96d3aea Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Mon, 2 Mar 2026 17:59:05 -0800 Subject: [PATCH 3/9] Address feedback Signed-off-by: James Sturtevant --- .../src/sandbox/proto_wasm_sandbox.rs | 67 ++++++++++++------- src/wasm_runtime/src/module.rs | 8 ++- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs index 0d2e7eea..91c5ec4b 100644 --- a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +use std::collections::HashMap; + use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterType, ReturnType}; use hyperlight_common::flatbuffer_wrappers::host_function_definition::HostFunctionDefinition; use hyperlight_common::flatbuffer_wrappers::host_function_details::HostFunctionDetails; @@ -34,8 +36,7 @@ use crate::build_info::BuildInfo; /// With that `WasmSandbox` you can load a Wasm module through the `load_module` method and get a `LoadedWasmSandbox` which can then execute functions defined in the Wasm module. pub struct ProtoWasmSandbox { pub(super) inner: Option, - /// Tracks registered host function definitions for pushing to the guest at load time - host_function_definitions: Vec, + host_function_definitions: HashMap, } impl Registerable for ProtoWasmSandbox { @@ -44,17 +45,15 @@ impl Registerable for ProtoWasmSandbox { name: &str, hf: impl Into>, ) -> Result<()> { - // Track the host function definition for pushing to guest at load time - self.host_function_definitions.push(HostFunctionDefinition { - function_name: name.to_string(), - parameter_types: Some(Args::TYPE.to_vec()), - return_type: Output::TYPE, - }); - self.inner .as_mut() .ok_or(new_error!("inner sandbox was none")) - .and_then(|sb| sb.register(name, hf)) + .and_then(|sb| sb.register(name, hf))?; + + // Track the host function definition for pushing to guest at load time. + // matching hyperlight-core's FunctionRegistry behavior. + self.track_host_function_definition(name, Args::TYPE, Output::TYPE); + Ok(()) } } @@ -79,11 +78,15 @@ impl ProtoWasmSandbox { metrics::counter!(METRIC_TOTAL_PROTO_WASM_SANDBOXES).increment(1); // HostPrint is always registered by UninitializedSandbox, so include it by default - let host_function_definitions = vec![HostFunctionDefinition { - function_name: "HostPrint".to_string(), - parameter_types: Some(vec![ParameterType::String]), - return_type: ReturnType::Int, - }]; + let mut host_function_definitions = HashMap::new(); + host_function_definitions.insert( + "HostPrint".to_string(), + HostFunctionDefinition { + function_name: "HostPrint".to_string(), + parameter_types: Some(vec![ParameterType::String]), + return_type: ReturnType::Int, + }, + ); Ok(Self { inner: Some(inner), @@ -100,7 +103,11 @@ impl ProtoWasmSandbox { pub fn load_runtime(mut self) -> Result { // Serialize host function definitions to push to the guest during InitWasmRuntime let host_function_definitions = HostFunctionDetails { - host_functions: Some(std::mem::take(&mut self.host_function_definitions)), + host_functions: Some( + std::mem::take(&mut self.host_function_definitions) + .into_values() + .collect(), + ), }; let host_function_definitions_bytes: Vec = (&host_function_definitions) @@ -132,17 +139,29 @@ impl ProtoWasmSandbox { name: impl AsRef, host_func: impl Into>, ) -> Result<()> { - // Track the host function definition for pushing to guest at load time - self.host_function_definitions.push(HostFunctionDefinition { - function_name: name.as_ref().to_string(), - parameter_types: Some(Args::TYPE.to_vec()), - return_type: Output::TYPE, - }); - self.inner .as_mut() .ok_or(new_error!("inner sandbox was none"))? - .register(name, host_func) + .register(&name, host_func)?; + + self.track_host_function_definition(name.as_ref(), Args::TYPE, Output::TYPE); + Ok(()) + } + + fn track_host_function_definition( + &mut self, + name: &str, + parameter_types: &[ParameterType], + return_type: ReturnType, + ) { + self.host_function_definitions.insert( + name.to_string(), + HostFunctionDefinition { + function_name: name.to_string(), + parameter_types: Some(parameter_types.to_vec()), + return_type, + }, + ); } /// Register the given host printing function `print_func` with `self`. diff --git a/src/wasm_runtime/src/module.rs b/src/wasm_runtime/src/module.rs index ba4fe082..0cd6819a 100644 --- a/src/wasm_runtime/src/module.rs +++ b/src/wasm_runtime/src/module.rs @@ -122,12 +122,18 @@ fn init_wasm_runtime(function_call: &FunctionCall) -> Result> { let bytes = match params.first() { Some(ParameterValue::VecBytes(ref b)) => b, - _ => { + Some(_) => { return Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, "InitWasmRuntime: first parameter must be VecBytes".to_string(), )) } + None => { + return Err(HyperlightGuestError::new( + ErrorCode::GuestFunctionParameterTypeMismatch, + "InitWasmRuntime: expected 1 parameter, got 0".to_string(), + )) + } }; let hfd: hostfuncs::HostFunctionDetails = bytes.as_slice().try_into().map_err(|e| { From fdc9d14e31b6cf2ec7d9755ac8483bd8d5931c3b Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Fri, 6 Mar 2026 14:05:47 -0800 Subject: [PATCH 4/9] Upgrade to Hyperlight 0.13 Signed-off-by: James Sturtevant --- Cargo.lock | 213 +++++++++++------- Cargo.toml | 6 +- src/hyperlight_wasm/Cargo.toml | 2 +- .../examples/component_example/main.rs | 2 +- .../examples/helloworld/main.rs | 2 +- .../examples/interruption/main.rs | 2 +- .../src/sandbox/loaded_wasm_sandbox.rs | 10 +- .../src/sandbox/sandbox_builder.rs | 20 +- .../src/sandbox/wasm_sandbox.rs | 30 +-- src/hyperlight_wasm_macro/Cargo.lock | 87 +++++-- src/hyperlight_wasm_macro/Cargo.toml | 4 +- src/hyperlight_wasm_macro/src/lib.rs | 2 +- src/hyperlight_wasm_macro/src/wasmguest.rs | 4 +- src/wasm_runtime/Cargo.lock | 111 ++++----- src/wasm_runtime/Cargo.toml | 8 +- src/wasm_runtime/src/component.rs | 12 +- src/wasm_runtime/src/module.rs | 17 +- src/wasm_runtime/src/platform.rs | 34 ++- 18 files changed, 338 insertions(+), 228 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e87483d8..51a4e034 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -194,7 +194,7 @@ version = "0.72.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "cexpr", "clang-sys", "itertools 0.13.0", @@ -216,9 +216,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" [[package]] name = "blake3" @@ -231,7 +231,7 @@ dependencies = [ "cc", "cfg-if", "constant_time_eq", - "cpufeatures", + "cpufeatures 0.2.17", ] [[package]] @@ -331,7 +331,7 @@ dependencies = [ "serde", "serde-untagged", "serde-value", - "thiserror 2.0.17", + "thiserror 2.0.18", "toml 0.9.12+spec-1.1.0", "unicode-xid", "url", @@ -348,7 +348,7 @@ dependencies = [ "semver", "serde", "serde_json", - "thiserror 2.0.17", + "thiserror 2.0.18", ] [[package]] @@ -390,6 +390,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chacha20" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.0", +] + [[package]] name = "chrono" version = "0.4.44" @@ -496,7 +507,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" dependencies = [ - "thiserror 2.0.17", + "thiserror 2.0.18", ] [[package]] @@ -569,6 +580,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + [[package]] name = "cranelift-assembler-x64" version = "0.123.6" @@ -1000,11 +1020,11 @@ checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" [[package]] name = "flatbuffers" -version = "25.9.23" +version = "25.12.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b6620799e7340ebd9968d2e0708eb82cf1971e9a16821e2091b6d6e475eed5" +checksum = "35f6839d7b3b98adde531effaf34f0c2badc6f4735d26fe74709d8e513a96ef3" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "rustc_version", ] @@ -1116,11 +1136,11 @@ dependencies = [ [[package]] name = "gdbstub" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72742d2b395902caf8a5d520d0dd3334ba6d1138938429200e58d5174e275f3f" +checksum = "6bf845b08f7c2ef3b5ad19f80779d43ae20d278652b91bb80adda65baf2d8ed6" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "cfg-if", "log", "managed", @@ -1180,6 +1200,7 @@ dependencies = [ "cfg-if", "libc", "r-efi", + "rand_core 0.10.0", "wasip2", "wasip3", ] @@ -1201,7 +1222,7 @@ version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b88256088d75a56f8ecfa070513a775dd9107f6530ef14919dac831af9cfe2b" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "libc", "libgit2-sys", "log", @@ -1280,11 +1301,13 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" dependencies = [ "foldhash 0.2.0", + "serde", + "serde_core", ] [[package]] @@ -1424,23 +1447,24 @@ dependencies = [ [[package]] name = "hyperlight-common" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98f80e9aba9fce2a899c9ff0c62dd39cd479fa2f22ef578faed1d510c5becf94" +checksum = "725ce602c72dce1d83a87f98f3731e7db62f5ca7e1a255eea875e9bad408766f" dependencies = [ "anyhow", "flatbuffers", "log", "spin", - "thiserror 2.0.17", + "thiserror 2.0.18", "tracing", + "tracing-core", ] [[package]] name = "hyperlight-component-macro" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f217d5bbb0d02c9aac81374c3161af2a3a46a5379a604b0799534762a534d75a" +checksum = "951465558e3104075650d27461cca83b9b25115b3bf68c5e9399068d12fa9885" dependencies = [ "env_logger", "hyperlight-component-util", @@ -1449,29 +1473,29 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wasmparser 0.243.0", + "wasmparser 0.245.1", ] [[package]] name = "hyperlight-component-util" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9b3299460dc5f39d37b8233c9aad7fc52c9548d96a76d35cdcc4f4f49ff6662" +checksum = "41501638fd9877bd0c2e0cbbd20ea55d5a532f4e45a870d626de56da9795fc9a" dependencies = [ "itertools 0.14.0", - "log", "prettyplease", "proc-macro2", "quote", "syn", - "wasmparser 0.243.0", + "tracing", + "wasmparser 0.245.1", ] [[package]] name = "hyperlight-guest-tracing" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0f8d1e992b03c778c6c144f94a81060384e823781c84fae6228cba230d449c" +checksum = "266a23a83726db78b114fd177bda2833df84e9e2894e460aed7c7da9a0967a5e" dependencies = [ "hyperlight-common", "spin", @@ -1481,12 +1505,12 @@ dependencies = [ [[package]] name = "hyperlight-host" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f81d712e88785e8860be6b33048fc2c9ad6637864aa50fe95d0037cfa50a4fb" +checksum = "d37f39e7660b0b2173a07595e2049aa6215d73e74757be653ab4da99445e9714" dependencies = [ "anyhow", - "bitflags 2.10.0", + "bitflags 2.11.0", "blake3", "cfg-if", "cfg_aliases", @@ -1509,12 +1533,12 @@ dependencies = [ "mshv-ioctls", "opentelemetry", "page_size", - "rand", + "rand 0.10.0", "rust-embed", "serde_json", "sha256", "termcolor", - "thiserror 2.0.17", + "thiserror 2.0.18", "tracing", "tracing-core", "tracing-log", @@ -1529,7 +1553,7 @@ dependencies = [ [[package]] name = "hyperlight-wasm" -version = "0.12.0" +version = "0.13.0" dependencies = [ "anyhow", "blake3", @@ -1571,7 +1595,7 @@ dependencies = [ [[package]] name = "hyperlight-wasm-aot" -version = "0.12.0" +version = "0.13.0" dependencies = [ "cargo-util-schemas", "cargo_metadata", @@ -1714,12 +1738,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.12.0" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", - "hashbrown 0.16.0", + "hashbrown 0.16.1", "serde", "serde_core", ] @@ -1839,7 +1863,7 @@ version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "333f77a20344a448f3f70664918135fddeb804e938f28a99d685bd92926e0b19" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "kvm-bindings", "libc", "vmm-sys-util", @@ -1897,7 +1921,7 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "libc", "redox_syscall", ] @@ -2007,7 +2031,7 @@ dependencies = [ "metrics-util", "quanta", "rustls", - "thiserror 2.0.17", + "thiserror 2.0.18", "tokio", "tracing", ] @@ -2021,13 +2045,13 @@ dependencies = [ "aho-corasick", "crossbeam-epoch", "crossbeam-utils", - "hashbrown 0.16.0", + "hashbrown 0.16.1", "indexmap", "metrics", "ordered-float 5.1.0", "quanta", "radix_trie", - "rand", + "rand 0.9.2", "rand_xoshiro", "sketches-ddsketch", ] @@ -2069,7 +2093,7 @@ checksum = "748f59f22dccd910080a6315fc692bd04bd8c94ae2fc346957ec34b7d985eaa0" dependencies = [ "libc", "mshv-bindings", - "thiserror 2.0.17", + "thiserror 2.0.18", "vmm-sys-util", ] @@ -2197,7 +2221,7 @@ dependencies = [ "futures-sink", "js-sys", "pin-project-lite", - "thiserror 2.0.17", + "thiserror 2.0.18", "tracing", ] @@ -2227,7 +2251,7 @@ dependencies = [ "opentelemetry_sdk", "prost", "reqwest", - "thiserror 2.0.17", + "thiserror 2.0.18", "tokio", "tonic", ] @@ -2262,8 +2286,8 @@ dependencies = [ "futures-util", "opentelemetry", "percent-encoding", - "rand", - "thiserror 2.0.17", + "rand 0.9.2", + "thiserror 2.0.18", "tokio", "tokio-stream", ] @@ -2475,9 +2499,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.103" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] @@ -2545,9 +2569,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.42" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] @@ -2575,7 +2599,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ "rand_chacha", - "rand_core", + "rand_core 0.9.3", +] + +[[package]] +name = "rand" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8" +dependencies = [ + "chacha20", + "getrandom 0.4.1", + "rand_core 0.10.0", ] [[package]] @@ -2585,7 +2620,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.9.3", ] [[package]] @@ -2597,13 +2632,19 @@ dependencies = [ "getrandom 0.3.4", ] +[[package]] +name = "rand_core" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba" + [[package]] name = "rand_xoshiro" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f703f4665700daf5512dcca5f43afa6af89f09db47fb56be587f80636bda2d41" dependencies = [ - "rand_core", + "rand_core 0.9.3", ] [[package]] @@ -2612,7 +2653,7 @@ version = "11.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "498cd0dc59d73224351ee52a95fee0f1a617a2eae0e7d9d720cc622c73a54186" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", ] [[package]] @@ -2641,7 +2682,7 @@ version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", ] [[package]] @@ -2652,7 +2693,7 @@ checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" dependencies = [ "getrandom 0.2.16", "libredox", - "thiserror 2.0.17", + "thiserror 2.0.18", ] [[package]] @@ -2748,9 +2789,9 @@ dependencies = [ [[package]] name = "rust-embed" -version = "8.9.0" +version = "8.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "947d7f3fad52b283d261c4c99a084937e2fe492248cb9a68a8435a861b8798ca" +checksum = "04113cb9355a377d83f06ef1f0a45b8ab8cd7d8b1288160717d66df5c7988d27" dependencies = [ "rust-embed-impl", "rust-embed-utils", @@ -2803,7 +2844,7 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "errno", "libc", "linux-raw-sys", @@ -2919,7 +2960,7 @@ version = "3.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "core-foundation", "core-foundation-sys", "libc", @@ -3039,7 +3080,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "digest", ] @@ -3149,9 +3190,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.111" +version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" dependencies = [ "proc-macro2", "quote", @@ -3215,11 +3256,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ - "thiserror-impl 2.0.17", + "thiserror-impl 2.0.18", ] [[package]] @@ -3235,9 +3276,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", @@ -3456,7 +3497,7 @@ version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "bytes", "futures-util", "http", @@ -3522,7 +3563,7 @@ dependencies = [ "chrono", "serde", "smallvec", - "thiserror 2.0.17", + "thiserror 2.0.18", "tracing", "tracing-subscriber", "uuid", @@ -3818,7 +3859,7 @@ version = "0.236.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9b1e81f3eb254cf7404a82cee6926a4a3ccc5aad80cc3d43608a070c67aa1d7" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "hashbrown 0.15.5", "indexmap", "semver", @@ -3827,27 +3868,27 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.243.0" +version = "0.244.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d8db401b0528ec316dfbe579e6ab4152d61739cfe076706d2009127970159d" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" dependencies = [ - "bitflags 2.10.0", + "bitflags 2.11.0", "hashbrown 0.15.5", "indexmap", "semver", - "serde", ] [[package]] name = "wasmparser" -version = "0.244.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" dependencies = [ - "bitflags 2.10.0", - "hashbrown 0.15.5", + "bitflags 2.11.0", + "hashbrown 0.16.1", "indexmap", "semver", + "serde", ] [[package]] @@ -3869,7 +3910,7 @@ checksum = "6a2f8736ddc86e03a9d0e4c477a37939cfc53cd1b052ee38a3133679b87ef830" dependencies = [ "addr2line", "anyhow", - "bitflags 2.10.0", + "bitflags 2.11.0", "bumpalo", "cc", "cfg-if", @@ -3982,7 +4023,7 @@ dependencies = [ "pulley-interpreter", "smallvec", "target-lexicon", - "thiserror 2.0.17", + "thiserror 2.0.18", "wasmparser 0.236.1", "wasmtime-environ", "wasmtime-internal-math", @@ -4090,7 +4131,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28dc9efea511598c88564ac1974e0825c07d9c0de902dbf68f227431cd4ff8c" dependencies = [ "anyhow", - "bitflags 2.10.0", + "bitflags 2.11.0", "heck", "indexmap", "wit-parser 0.236.1", @@ -4172,7 +4213,7 @@ dependencies = [ "regalloc2", "smallvec", "target-lexicon", - "thiserror 2.0.17", + "thiserror 2.0.18", "wasmparser 0.236.1", "wasmtime-environ", "wasmtime-internal-cranelift", @@ -4530,7 +4571,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" dependencies = [ "anyhow", - "bitflags 2.10.0", + "bitflags 2.11.0", "indexmap", "log", "serde", diff --git a/Cargo.toml b/Cargo.toml index 6959cb6e..f3741f38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ exclude = [ "src/wasm_runtime", "src/rust_wasm_samples", "src/hyperlight_wasm_m resolver = "2" [workspace.package] -version = "0.12.0" +version = "0.13.0" edition = "2024" rust-version = "1.89" license = "Apache-2.0" @@ -13,5 +13,5 @@ repository = "https://github.com/hyperlight-dev/hyperlight-wasm" readme = "README.md" [workspace.dependencies] -hyperlight-host = { version = "0.12.0", default-features = false, features = ["executable_heap", "init-paging"] } -hyperlight-common = { version = "0.12.0", default-features = false } +hyperlight-host = { version = "0.13.0", default-features = false, features = ["executable_heap", "init-paging"] } +hyperlight-common = { version = "0.13.0", default-features = false } diff --git a/src/hyperlight_wasm/Cargo.toml b/src/hyperlight_wasm/Cargo.toml index a469c3d5..45e5f956 100644 --- a/src/hyperlight_wasm/Cargo.toml +++ b/src/hyperlight_wasm/Cargo.toml @@ -75,7 +75,7 @@ windows = { version = "0.62", features = ["Win32_System_Threading"] } page_size = "0.6.0" [dev-dependencies] -hyperlight-component-macro = { version = "0.12.0" } +hyperlight-component-macro = { version = "0.13.0" } examples_common = { path = "../examples_common" } criterion = { version = "0.8.2", features = ["html_reports"] } crossbeam-queue = "0.3" diff --git a/src/hyperlight_wasm/examples/component_example/main.rs b/src/hyperlight_wasm/examples/component_example/main.rs index ca0b6b65..39592feb 100644 --- a/src/hyperlight_wasm/examples/component_example/main.rs +++ b/src/hyperlight_wasm/examples/component_example/main.rs @@ -48,7 +48,7 @@ fn main() { let mut sb: hyperlight_wasm::ProtoWasmSandbox = hyperlight_wasm::SandboxBuilder::new() .with_guest_input_buffer_size(70000000) .with_guest_heap_size(200000000) - .with_guest_stack_size(100000000) + .with_guest_scratch_size(100 * 1024 * 1024) .build() .unwrap(); let rt = bindings::register_host_functions(&mut sb, state); diff --git a/src/hyperlight_wasm/examples/helloworld/main.rs b/src/hyperlight_wasm/examples/helloworld/main.rs index a5b55453..6b0f693c 100644 --- a/src/hyperlight_wasm/examples/helloworld/main.rs +++ b/src/hyperlight_wasm/examples/helloworld/main.rs @@ -112,7 +112,7 @@ fn main() -> Result<()> { "RoundToInt test case {idx} failed: got {}, expected {}", result, expected_result ); - loaded_wasm_sandbox.restore(&snapshot)? + loaded_wasm_sandbox.restore(snapshot.clone())? } Ok(()) } diff --git a/src/hyperlight_wasm/examples/interruption/main.rs b/src/hyperlight_wasm/examples/interruption/main.rs index 2d14d0d3..af5dd5f1 100644 --- a/src/hyperlight_wasm/examples/interruption/main.rs +++ b/src/hyperlight_wasm/examples/interruption/main.rs @@ -97,7 +97,7 @@ fn main() -> Result<()> { // Recovery option 1: Use restore() to recover the sandbox println!("\n7. Recovering sandbox using restore()..."); - loaded.restore(&snapshot)?; + loaded.restore(snapshot.clone())?; assert!(!loaded.is_poisoned()?); println!(" is_poisoned after restore: {}", loaded.is_poisoned()?); diff --git a/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs index 30010878..9f42647d 100644 --- a/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs @@ -42,7 +42,7 @@ pub struct LoadedWasmSandbox { // because of this we cannot implement drop without making inner an Option (alternatively we could make MultiUseSandbox Copy but that would introduce other issues) inner: Option, // The state the sandbox was in before loading a wasm module. Used for transitioning back to a `WasmSandbox` (unloading the wasm module). - runtime_snapshot: Option, + runtime_snapshot: Option>, } impl LoadedWasmSandbox { @@ -86,7 +86,7 @@ impl LoadedWasmSandbox { /// Returns `Err(HyperlightError::PoisonedSandbox)` if the sandbox is in a /// poisoned state. Use [`restore()`](Self::restore) with a previously /// taken snapshot to recover before taking a new snapshot. - pub fn snapshot(&mut self) -> Result { + pub fn snapshot(&mut self) -> Result> { match &mut self.inner { Some(inner) => inner.snapshot(), None => log_then_return!("No inner MultiUseSandbox to snapshot"), @@ -105,7 +105,7 @@ impl LoadedWasmSandbox { /// 1. Clear the poisoned state /// 2. Reset memory to the snapshot state /// 3. Allow subsequent [`call_guest_function()`](Self::call_guest_function) calls to succeed - pub fn restore(&mut self, snapshot: &Snapshot) -> Result<()> { + pub fn restore(&mut self, snapshot: Arc) -> Result<()> { match &mut self.inner { Some(inner) => inner.restore(snapshot), None => log_then_return!("No inner MultiUseSandbox to restore"), @@ -135,7 +135,7 @@ impl LoadedWasmSandbox { pub(super) fn new( inner: MultiUseSandbox, - runtime_snapshot: Snapshot, + runtime_snapshot: Arc, ) -> Result { metrics::gauge!(METRIC_ACTIVE_LOADED_WASM_SANDBOXES).increment(1); metrics::counter!(METRIC_TOTAL_LOADED_WASM_SANDBOXES).increment(1); @@ -360,7 +360,7 @@ mod tests { #[test] fn test_call_guest_functions_with_custom_config_multiple_times() { let mut sandbox = SandboxBuilder::new() - .with_guest_stack_size(32 * 1024) + .with_guest_scratch_size(32 * 1024) .with_guest_heap_size(128 * 1024) .build() .unwrap(); diff --git a/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs b/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs index 1c519f59..f9b48004 100644 --- a/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs +++ b/src/hyperlight_wasm/src/sandbox/sandbox_builder.rs @@ -22,7 +22,9 @@ use super::proto_wasm_sandbox::ProtoWasmSandbox; // use unreasonably large minimum stack/heap/input data sizes for now to // deal with the size of wasmtime/wasi-libc aot artifacts -pub const MIN_STACK_SIZE: u64 = 64 * 1024; +// use reasonably large minimum scratch/heap/input data sizes +// to deal with the size of wasmtime/wasi-libc aot artifacts +pub const MIN_SCRATCH_SIZE: usize = 2 * 1024 * 1024; pub const MIN_INPUT_DATA_SIZE: usize = 192 * 1024; pub const MIN_HEAP_SIZE: u64 = 1024 * 1024; @@ -39,6 +41,7 @@ impl SandboxBuilder { let mut config: SandboxConfiguration = Default::default(); config.set_input_data_size(MIN_INPUT_DATA_SIZE); config.set_heap_size(MIN_HEAP_SIZE); + config.set_scratch_size(MIN_SCRATCH_SIZE); Self { config, @@ -95,13 +98,14 @@ impl SandboxBuilder { self } - /// Set the guest stack size - /// This is the size of the stack that code executing in the guest can use. - /// If this value is too small then the guest will fail with a stack overflow error - /// The default value (and minimum) is set to the value of the MIN_STACK_SIZE const. - pub fn with_guest_stack_size(mut self, guest_stack_size: u64) -> Self { - if guest_stack_size > MIN_STACK_SIZE { - self.config.set_stack_size(guest_stack_size); + /// Set the guest scratch size in bytes. + /// The scratch region provides writable memory for the guest, including the + /// dynamically-sized stack. Increase this if your guest code needs deep + /// recursion or large local variables. + /// Values smaller than the default (288 KiB) are ignored. + pub fn with_guest_scratch_size(mut self, guest_scratch_size: usize) -> Self { + if guest_scratch_size > MIN_SCRATCH_SIZE { + self.config.set_scratch_size(guest_scratch_size); } self } diff --git a/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs index 074e5754..0dab32e6 100644 --- a/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs @@ -15,8 +15,8 @@ limitations under the License. */ use std::path::Path; +use std::sync::Arc; -use hyperlight_host::mem::memory_region::{MemoryRegion, MemoryRegionFlags, MemoryRegionType}; use hyperlight_host::sandbox::snapshot::Snapshot; use hyperlight_host::{MultiUseSandbox, Result, new_error}; @@ -38,7 +38,7 @@ pub struct WasmSandbox { inner: Option, // Snapshot of state of an initial WasmSandbox (runtime loaded, but no guest module code loaded). // Used for LoadedWasmSandbox to be able restore state back to WasmSandbox - snapshot: Option, + snapshot: Option>, } const MAPPED_BINARY_VA: u64 = 0x1_0000_0000u64; @@ -61,8 +61,11 @@ impl WasmSandbox { /// for example when creating a `WasmSandbox` from a `LoadedWasmSandbox`, since /// the snapshot has already been created in that case. /// Expects a snapshot of the state where wasm runtime is loaded, but no guest module code is loaded. - pub(super) fn new_from_loaded(mut loaded: MultiUseSandbox, snapshot: Snapshot) -> Result { - loaded.restore(&snapshot)?; + pub(super) fn new_from_loaded( + mut loaded: MultiUseSandbox, + snapshot: Arc, + ) -> Result { + loaded.restore(snapshot.clone())?; metrics::gauge!(METRIC_ACTIVE_WASM_SANDBOXES).increment(1); metrics::counter!(METRIC_TOTAL_WASM_SANDBOXES).increment(1); Ok(WasmSandbox { @@ -113,19 +116,8 @@ impl WasmSandbox { .as_mut() .ok_or_else(|| new_error!("WasmSandbox is None"))?; - let guest_base: usize = MAPPED_BINARY_VA as usize; - let rgn = MemoryRegion { - host_region: base as usize..base.wrapping_add(len) as usize, - guest_region: guest_base..guest_base + len, - flags: MemoryRegionFlags::READ | MemoryRegionFlags::EXECUTE, - region_type: MemoryRegionType::Heap, - }; - if let Ok(()) = unsafe { inner.map_region(&rgn) } { - inner.call::<()>("LoadWasmModulePhys", (MAPPED_BINARY_VA, len as u64))?; - } else { - let wasm_bytes = unsafe { std::slice::from_raw_parts(base as *const u8, len).to_vec() }; - load_wasm_module_from_bytes(inner, wasm_bytes)?; - } + let wasm_bytes = unsafe { std::slice::from_raw_parts(base as *const u8, len).to_vec() }; + load_wasm_module_from_bytes(inner, wasm_bytes)?; self.finalize_module_load() } @@ -390,7 +382,7 @@ mod tests { assert!(loaded.is_poisoned()?, "Sandbox should be poisoned"); // Restore should recover the sandbox - loaded.restore(&snapshot)?; + loaded.restore(snapshot)?; assert!( !loaded.is_poisoned()?, @@ -526,7 +518,7 @@ mod tests { let builder = SandboxBuilder::new() .with_guest_input_buffer_size(0x8000) .with_guest_output_buffer_size(0x8000) - .with_guest_stack_size(0x2000) + .with_guest_scratch_size(0x2000) .with_guest_heap_size(0x100000); let mut sandboxes: Vec = Vec::new(); diff --git a/src/hyperlight_wasm_macro/Cargo.lock b/src/hyperlight_wasm_macro/Cargo.lock index db5bf9e7..cabc94db 100644 --- a/src/hyperlight_wasm_macro/Cargo.lock +++ b/src/hyperlight_wasm_macro/Cargo.lock @@ -22,38 +22,39 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "foldhash" -version = "0.1.5" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" [[package]] name = "hashbrown" -version = "0.15.5" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" dependencies = [ "foldhash", "serde", + "serde_core", ] [[package]] name = "hyperlight-component-util" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9b3299460dc5f39d37b8233c9aad7fc52c9548d96a76d35cdcc4f4f49ff6662" +checksum = "41501638fd9877bd0c2e0cbbd20ea55d5a532f4e45a870d626de56da9795fc9a" dependencies = [ "itertools", - "log", "prettyplease", "proc-macro2", "quote", "syn", + "tracing", "wasmparser", ] [[package]] name = "hyperlight-wasm-macro" -version = "0.12.0" +version = "0.13.0" dependencies = [ "hyperlight-component-util", "itertools", @@ -65,13 +66,14 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.11.0" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown", "serde", + "serde_core", ] [[package]] @@ -89,6 +91,18 @@ version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + [[package]] name = "prettyplease" version = "0.2.37" @@ -125,18 +139,27 @@ checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" [[package]] name = "serde" -version = "1.0.219" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -154,6 +177,38 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + [[package]] name = "unicode-ident" version = "1.0.18" @@ -162,9 +217,9 @@ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "wasmparser" -version = "0.243.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d8db401b0528ec316dfbe579e6ab4152d61739cfe076706d2009127970159d" +checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" dependencies = [ "bitflags", "hashbrown", diff --git a/src/hyperlight_wasm_macro/Cargo.toml b/src/hyperlight_wasm_macro/Cargo.toml index b44fde5e..7c683f3e 100644 --- a/src/hyperlight_wasm_macro/Cargo.toml +++ b/src/hyperlight_wasm_macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hyperlight-wasm-macro" -version = "0.12.0" +version = "0.13.0" edition = "2024" description = """ Procedural macros to generate Hyperlight Wasm host and guest bindings from component types @@ -16,6 +16,6 @@ proc-macro2 = { version = "1.0.106" } syn = { version = "2.0.117" } itertools = { version = "0.14.0" } prettyplease = { version = "0.2.37" } -hyperlight-component-util = { version = "0.12.0" } +hyperlight-component-util = { version = "0.13.0" } [workspace] # indicate that this crate is not part of any workspace diff --git a/src/hyperlight_wasm_macro/src/lib.rs b/src/hyperlight_wasm_macro/src/lib.rs index 5ed3f8a2..1eb8765f 100644 --- a/src/hyperlight_wasm_macro/src/lib.rs +++ b/src/hyperlight_wasm_macro/src/lib.rs @@ -29,7 +29,7 @@ mod wasmguest; #[proc_macro] pub fn wasm_guest_bindgen(_: proc_macro::TokenStream) -> proc_macro::TokenStream { let path = std::env::var_os("WIT_WORLD").unwrap(); - util::read_wit_type_from_file(path, |kebab_name, ct| { + util::read_wit_type_from_file(path, None, |kebab_name, ct| { let decls = emit::run_state(true, true, |s| { // Emit type/trait definitions for all instances in the world rtypes::emit_toplevel(s, &kebab_name, ct); diff --git a/src/hyperlight_wasm_macro/src/wasmguest.rs b/src/hyperlight_wasm_macro/src/wasmguest.rs index ba188b61..1ba93341 100644 --- a/src/hyperlight_wasm_macro/src/wasmguest.rs +++ b/src/hyperlight_wasm_macro/src/wasmguest.rs @@ -166,7 +166,7 @@ fn emit_export_extern_decl<'b>( let (function_call, ret) = emit_wasm_function_call(s, &ft.result, pwts, pus); let marshal_result = emit_hl_marshal_result(s, ret.clone(), &ft.result); quote! { - fn #n(fc: &::hyperlight_common::flatbuffer_wrappers::function_call::FunctionCall) -> ::hyperlight_guest::error::Result<::alloc::vec::Vec> { + fn #n(fc: ::hyperlight_common::flatbuffer_wrappers::function_call::FunctionCall) -> ::hyperlight_guest::error::Result<::alloc::vec::Vec> { #(#pds)* let mut store = CUR_STORE.lock(); let mut store = store.as_mut().unwrap(); let instance = CUR_INSTANCE.lock(); let mut instance = instance.unwrap(); @@ -181,7 +181,7 @@ fn emit_export_extern_decl<'b>( #fname.to_string(), ::alloc::vec![#(#pts),*], ::hyperlight_common::flatbuffer_wrappers::function_types::ReturnType::VecBytes, - #n as usize + #n ) ); } diff --git a/src/wasm_runtime/Cargo.lock b/src/wasm_runtime/Cargo.lock index 3344952f..e767de31 100644 --- a/src/wasm_runtime/Cargo.lock +++ b/src/wasm_runtime/Cargo.lock @@ -10,9 +10,9 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "anyhow" -version = "1.0.100" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] name = "arbitrary" @@ -40,11 +40,11 @@ checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "buddy_system_allocator" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1a0108968a3a2dab95b089c0fc3f1afa7759aa5ebe6f1d86d206d6f7ba726eb" +checksum = "b672b945a3e4f4f40bfd4cd5ee07df9e796a42254ce7cd6d2599ad969244c44a" dependencies = [ - "spin 0.9.8", + "spin", ] [[package]] @@ -341,9 +341,9 @@ checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "flatbuffers" -version = "25.9.23" +version = "25.12.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b6620799e7340ebd9968d2e0708eb82cf1971e9a16821e2091b6d6e475eed5" +checksum = "35f6839d7b3b98adde531effaf34f0c2badc6f4735d26fe74709d8e513a96ef3" dependencies = [ "bitflags", "rustc_version", @@ -355,6 +355,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -464,7 +470,7 @@ version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ - "foldhash", + "foldhash 0.1.5", "serde", ] @@ -473,6 +479,11 @@ name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "foldhash 0.2.0", + "serde", + "serde_core", +] [[package]] name = "heck" @@ -583,37 +594,38 @@ dependencies = [ [[package]] name = "hyperlight-common" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98f80e9aba9fce2a899c9ff0c62dd39cd479fa2f22ef578faed1d510c5becf94" +checksum = "725ce602c72dce1d83a87f98f3731e7db62f5ca7e1a255eea875e9bad408766f" dependencies = [ "anyhow", "flatbuffers", "log", - "spin 0.10.0", + "spin", "thiserror", + "tracing-core", ] [[package]] name = "hyperlight-component-util" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9b3299460dc5f39d37b8233c9aad7fc52c9548d96a76d35cdcc4f4f49ff6662" +checksum = "41501638fd9877bd0c2e0cbbd20ea55d5a532f4e45a870d626de56da9795fc9a" dependencies = [ "itertools", - "log", "prettyplease", "proc-macro2", "quote", "syn", - "wasmparser 0.243.0", + "tracing", + "wasmparser 0.245.1", ] [[package]] name = "hyperlight-guest" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc7f3cfaa19d263d4110b6f1d371ad778d544f4f30369be8eca79092bc868840" +checksum = "e9d3e421c1058a950dffaa414dd9e0348d21b18ec218cf2777752c436087bcb0" dependencies = [ "anyhow", "flatbuffers", @@ -625,9 +637,9 @@ dependencies = [ [[package]] name = "hyperlight-guest-bin" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "598a6f53bd1a356cff745af4b20e2e96ff9d4c956d13c52fd7981e91832291d8" +checksum = "ae0b7568c1df39e78f9ee844243ad722ef4990e46950232747e14460379a3930" dependencies = [ "buddy_system_allocator", "cc", @@ -640,15 +652,15 @@ dependencies = [ "hyperlight-guest-tracing", "linkme", "log", - "spin 0.10.0", + "spin", "tracing", ] [[package]] name = "hyperlight-guest-macro" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc0fec4e1154fe4368a5980101d532eede35c622532aaf83a03440d912d55217" +checksum = "f1d7915f27b534dc2c26e215f0372f80b34b172fb8d2507d0c0f0c4616259a42" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -658,19 +670,19 @@ dependencies = [ [[package]] name = "hyperlight-guest-tracing" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0f8d1e992b03c778c6c144f94a81060384e823781c84fae6228cba230d449c" +checksum = "266a23a83726db78b114fd177bda2833df84e9e2894e460aed7c7da9a0967a5e" dependencies = [ "hyperlight-common", - "spin 0.10.0", + "spin", "tracing", "tracing-core", ] [[package]] name = "hyperlight-wasm-macro" -version = "0.12.0" +version = "0.13.0" dependencies = [ "hyperlight-component-util", "itertools", @@ -790,9 +802,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.12.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown 0.16.1", @@ -1025,9 +1037,9 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" dependencies = [ "toml_edit", ] @@ -1408,15 +1420,6 @@ dependencies = [ "windows-sys 0.60.2", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "spin" version = "0.10.0" @@ -1486,18 +1489,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", @@ -1555,18 +1558,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.7.3" +version = "1.0.0+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533" +checksum = "32c2555c699578a4f59f0cc68e5116c8d7cabbd45e1409b989d4be085b53f13e" dependencies = [ "serde_core", ] [[package]] name = "toml_edit" -version = "0.23.9" +version = "0.25.4+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d7cbc3b4b49633d57a0509303158ca50de80ae32c265093b24c414705807832" +checksum = "7193cbd0ce53dc966037f54351dbbcf0d5a642c7f0038c382ef9e677ce8c13f2" dependencies = [ "indexmap", "toml_datetime", @@ -1576,9 +1579,9 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.0.4" +version = "1.0.9+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0cbe268d35bdb4bb5a56a2de88d0ad0eb70af5384a99d648cd4b3d04039800e" +checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4" dependencies = [ "winnow", ] @@ -1796,7 +1799,7 @@ dependencies = [ [[package]] name = "wasm-runtime" -version = "0.12.0" +version = "0.13.0" dependencies = [ "cargo_metadata", "cc", @@ -1807,7 +1810,7 @@ dependencies = [ "hyperlight-guest-bin", "hyperlight-wasm-macro", "reqwest", - "spin 0.10.0", + "spin", "tracing", "wasmtime", ] @@ -1827,12 +1830,12 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.243.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d8db401b0528ec316dfbe579e6ab4152d61739cfe076706d2009127970159d" +checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" dependencies = [ "bitflags", - "hashbrown 0.15.5", + "hashbrown 0.16.1", "indexmap", "semver", "serde", diff --git a/src/wasm_runtime/Cargo.toml b/src/wasm_runtime/Cargo.toml index 730c850a..e846e812 100644 --- a/src/wasm_runtime/Cargo.toml +++ b/src/wasm_runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-runtime" -version = "0.12.0" +version = "0.13.0" edition = "2021" [[bin]] @@ -11,9 +11,9 @@ doctest = false bench = false [dependencies] -hyperlight-common = { version = "0.12.0", default-features = false } -hyperlight-guest-bin = { version = "0.12.0", features = [ "printf" ] } -hyperlight-guest = { version = "0.12.0" } +hyperlight-common = { version = "0.13.0", default-features = false } +hyperlight-guest-bin = { version = "0.13.0", features = [ "printf" ] } +hyperlight-guest = { version = "0.13.0" } wasmtime = { version = "36.0.6", default-features = false, features = [ "runtime", "custom-virtual-memory", "custom-native-signals", "component-model" ] } hyperlight-wasm-macro = { path = "../hyperlight_wasm_macro" } spin = "0.10.0" diff --git a/src/wasm_runtime/src/component.rs b/src/wasm_runtime/src/component.rs index f6439c3f..05afe97c 100644 --- a/src/wasm_runtime/src/component.rs +++ b/src/wasm_runtime/src/component.rs @@ -45,7 +45,7 @@ hyperlight_wasm_macro::wasm_guest_bindgen!(); // dummy for compatibility with the module loading approach #[instrument(skip_all, level = "Info")] -fn init_wasm_runtime(_function_call: &FunctionCall) -> Result> { +fn init_wasm_runtime(_function_call: FunctionCall) -> Result> { Ok(get_flatbuffer_result::(0)) } @@ -62,7 +62,7 @@ fn load_component_common(engine: &Engine, component: Component) -> Result<()> { } #[instrument(skip_all, level = "Info")] -fn load_wasm_module(function_call: &FunctionCall) -> Result> { +fn load_wasm_module(function_call: FunctionCall) -> Result> { if let ( ParameterValue::VecBytes(ref wasm_bytes), ParameterValue::Int(ref _len), @@ -84,7 +84,7 @@ fn load_wasm_module(function_call: &FunctionCall) -> Result> { } #[instrument(skip_all, level = "Info")] -fn load_wasm_module_phys(function_call: &FunctionCall) -> Result> { +fn load_wasm_module_phys(function_call: FunctionCall) -> Result> { if let (ParameterValue::ULong(ref phys), ParameterValue::ULong(ref len), Some(ref engine)) = ( &function_call.parameters.as_ref().unwrap()[0], &function_call.parameters.as_ref().unwrap()[1], @@ -132,19 +132,19 @@ pub extern "C" fn hyperlight_main() { "InitWasmRuntime".to_string(), vec![ParameterType::VecBytes], ReturnType::Int, - init_wasm_runtime as usize, + init_wasm_runtime, )); register_function(GuestFunctionDefinition::new( "LoadWasmModule".to_string(), vec![ParameterType::VecBytes, ParameterType::Int], ReturnType::Int, - load_wasm_module as usize, + load_wasm_module, )); register_function(GuestFunctionDefinition::new( "LoadWasmModulePhys".to_string(), vec![ParameterType::ULong, ParameterType::ULong], ReturnType::Void, - load_wasm_module_phys as usize, + load_wasm_module_phys, )); } diff --git a/src/wasm_runtime/src/module.rs b/src/wasm_runtime/src/module.rs index 0cd6819a..fe198b9f 100644 --- a/src/wasm_runtime/src/module.rs +++ b/src/wasm_runtime/src/module.rs @@ -96,7 +96,7 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result> { } #[instrument(skip_all, level = "Info")] -fn init_wasm_runtime(function_call: &FunctionCall) -> Result> { +fn init_wasm_runtime(function_call: FunctionCall) -> Result> { let mut config = Config::new(); config.with_custom_code_memory(Some(alloc::sync::Arc::new(platform::WasmtimeCodeMemory {}))); #[cfg(gdb)] @@ -162,7 +162,7 @@ fn init_wasm_runtime(function_call: &FunctionCall) -> Result> { } #[instrument(skip_all, level = "Info")] -fn load_wasm_module(function_call: &FunctionCall) -> Result> { +fn load_wasm_module(function_call: FunctionCall) -> Result> { if let ( ParameterValue::VecBytes(ref wasm_bytes), ParameterValue::Int(ref _len), @@ -195,7 +195,7 @@ fn load_wasm_module(function_call: &FunctionCall) -> Result> { } #[instrument(skip_all, level = "Info")] -fn load_wasm_module_phys(function_call: &FunctionCall) -> Result> { +fn load_wasm_module_phys(function_call: FunctionCall) -> Result> { if let (ParameterValue::ULong(ref phys), ParameterValue::ULong(ref len), Some(ref engine)) = ( &function_call.parameters.as_ref().unwrap()[0], &function_call.parameters.as_ref().unwrap()[1], @@ -223,9 +223,8 @@ fn load_wasm_module_phys(function_call: &FunctionCall) -> Result> { } } -// GuestFunctionDefinition expects a function pointer as i64 +// GuestFunctionDefinition expects a function pointer #[no_mangle] -#[allow(clippy::fn_to_numeric_cast)] #[instrument(skip_all, level = "Info")] pub extern "C" fn hyperlight_main() { platform::register_page_fault_handler(); @@ -234,26 +233,26 @@ pub extern "C" fn hyperlight_main() { "PrintOutput".to_string(), vec![ParameterType::String], ReturnType::Int, - print_output_with_host_print as usize, + print_output_with_host_print, )); register_function(GuestFunctionDefinition::new( "InitWasmRuntime".to_string(), vec![ParameterType::VecBytes], ReturnType::Int, - init_wasm_runtime as usize, + init_wasm_runtime, )); register_function(GuestFunctionDefinition::new( "LoadWasmModule".to_string(), vec![ParameterType::VecBytes, ParameterType::Int], ReturnType::Int, - load_wasm_module as usize, + load_wasm_module, )); register_function(GuestFunctionDefinition::new( "LoadWasmModulePhys".to_string(), vec![ParameterType::ULong, ParameterType::ULong], ReturnType::Void, - load_wasm_module_phys as usize, + load_wasm_module_phys, )); } diff --git a/src/wasm_runtime/src/platform.rs b/src/wasm_runtime/src/platform.rs index bcd84cb7..ff6b660f 100644 --- a/src/wasm_runtime/src/platform.rs +++ b/src/wasm_runtime/src/platform.rs @@ -18,7 +18,8 @@ use core::ffi::c_void; use core::ptr::NonNull; use core::sync::atomic::{AtomicPtr, AtomicU64, Ordering}; -use hyperlight_guest_bin::exceptions::handler; +use hyperlight_common::vmem; +use hyperlight_guest_bin::exception::arch; use hyperlight_guest_bin::paging; // Extremely stupid virtual address allocator @@ -28,8 +29,8 @@ use hyperlight_guest_bin::paging; static FIRST_VADDR: AtomicU64 = AtomicU64::new(0x100_0000_0000u64); fn page_fault_handler( _exception_number: u64, - info: *mut handler::ExceptionInfo, - _ctx: *mut handler::Context, + info: *mut arch::ExceptionInfo, + _ctx: *mut arch::Context, page_fault_address: u64, ) -> bool { let error_code = unsafe { (&raw const (*info).error_code).read_volatile() }; @@ -41,12 +42,17 @@ fn page_fault_handler( // structure in hyperlight core if (error_code & 0x1) == 0x0 && page_fault_address >= 0x100_0000_0000u64 { unsafe { - let phys_page = paging::alloc_phys_pages(1); + let phys_page = hyperlight_guest::prim_alloc::alloc_phys_pages(1); let virt_base = (page_fault_address & !0xFFF) as *mut u8; paging::map_region( phys_page, virt_base, hyperlight_guest_bin::OS_PAGE_SIZE as u64, + vmem::MappingKind::Basic(vmem::BasicMapping { + readable: true, + writable: true, + executable: true, + }), ); virt_base.write_bytes(0u8, hyperlight_guest_bin::OS_PAGE_SIZE as usize); } @@ -59,7 +65,7 @@ pub(crate) fn register_page_fault_handler() { // See AMD64 Architecture Programmer's Manual, Volume 2 // §8.2 Vectors, p. 245 // Table 8-1: Interrupt Vector Source and Cause - handler::HANDLERS[14].store(page_fault_handler as usize as u64, Ordering::Release); + arch::HANDLERS[14].store(page_fault_handler as usize as u64, Ordering::Release); } // Wasmtime Embedding Interface @@ -120,8 +126,8 @@ type wasmtime_trap_handler_t = static WASMTIME_REQUESTED_TRAP_HANDLER: AtomicU64 = AtomicU64::new(0); fn wasmtime_trap_handler( exception_number: u64, - info: *mut handler::ExceptionInfo, - ctx: *mut handler::Context, + info: *mut arch::ExceptionInfo, + ctx: *mut arch::Context, _page_fault_address: u64, ) -> bool { let requested_handler = WASMTIME_REQUESTED_TRAP_HANDLER.load(Ordering::Relaxed); @@ -155,7 +161,7 @@ pub extern "C" fn wasmtime_init_traps(handler: wasmtime_trap_handler_t) -> i32 { // See AMD64 Architecture Programmer's Manual, Volume 2 // §8.2 Vectors, p. 245 // Table 8-1: Interrupt Vector Source and Cause - handler::HANDLERS[6].store(wasmtime_trap_handler as usize as u64, Ordering::Release); + arch::HANDLERS[6].store(wasmtime_trap_handler as usize as u64, Ordering::Release); // TODO: Add handlers for any other traps that wasmtime needs, // probably including at least some floating-point // exceptions @@ -233,7 +239,17 @@ pub(crate) unsafe fn map_buffer(phys: u64, len: u64) -> NonNull<[u8]> { // TODO: Use a VA allocator let virt = phys as *mut u8; unsafe { - paging::map_region(phys, virt, len); + paging::map_region( + phys, + virt, + len, + vmem::MappingKind::Basic(vmem::BasicMapping { + readable: true, + writable: true, + executable: true, + }), + ); + paging::barrier::first_valid_same_ctx(); NonNull::new_unchecked(core::ptr::slice_from_raw_parts_mut(virt, len as usize)) } } From 6cba4bd4ca13ab51c104229b42af11ea65bc7c77 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Fri, 6 Mar 2026 14:49:52 -0800 Subject: [PATCH 5/9] Move the HostPrint Registration Signed-off-by: James Sturtevant --- .../src/sandbox/proto_wasm_sandbox.rs | 14 +------------- src/wasm_runtime/src/module.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs index 91c5ec4b..23b54769 100644 --- a/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs +++ b/src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs @@ -77,17 +77,7 @@ impl ProtoWasmSandbox { metrics::gauge!(METRIC_ACTIVE_PROTO_WASM_SANDBOXES).increment(1); metrics::counter!(METRIC_TOTAL_PROTO_WASM_SANDBOXES).increment(1); - // HostPrint is always registered by UninitializedSandbox, so include it by default - let mut host_function_definitions = HashMap::new(); - host_function_definitions.insert( - "HostPrint".to_string(), - HostFunctionDefinition { - function_name: "HostPrint".to_string(), - parameter_types: Some(vec![ParameterType::String]), - return_type: ReturnType::Int, - }, - ); - + let host_function_definitions = HashMap::new(); Ok(Self { inner: Some(inner), host_function_definitions, @@ -170,8 +160,6 @@ impl ProtoWasmSandbox { &mut self, print_func: impl Into>, ) -> Result<()> { - // HostPrint definition is already tracked from new() since - // UninitializedSandbox always registers a default HostPrint. // This method only replaces the implementation, not the definition. self.inner .as_mut() diff --git a/src/wasm_runtime/src/module.rs b/src/wasm_runtime/src/module.rs index fe198b9f..c2b00564 100644 --- a/src/wasm_runtime/src/module.rs +++ b/src/wasm_runtime/src/module.rs @@ -155,6 +155,23 @@ fn init_wasm_runtime(function_call: FunctionCall) -> Result> { .map_err(|e| wasmtime::Error::msg(format!("{:?}", e))) }, )?; + + // Always register HostPrint + let host_print_def = hostfuncs::HostFunctionDefinition { + function_name: "HostPrint".to_string(), + parameter_types: Some(alloc::vec![ParameterType::String]), + return_type: ReturnType::Int, + }; + let captured = host_print_def.clone(); + linker.func_new( + "env", + "HostPrint", + hostfuncs::hostfunc_type(&host_print_def, &engine)?, + move |c, ps, rs| { + hostfuncs::call(&captured, c, ps, rs) + .map_err(|e| wasmtime::Error::msg(format!("{:?}", e))) + }, + )?; } *CUR_ENGINE.lock() = Some(engine); *CUR_LINKER.lock() = Some(linker); From 653cd6daeb9f1b3d55949e6e44b45f28c3f2447c Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Wed, 25 Feb 2026 13:21:50 -0800 Subject: [PATCH 6/9] feat: add world selection for multi-world WIT files Support WIT_WORLD_NAME env var in hyperlight-wasm-macro to select a specific world from WIT files containing multiple worlds. Signed-off-by: James Sturtevant --- CHANGELOG.md | 3 +++ README.md | 26 ++++++++++++++++++++++++++ src/hyperlight_wasm/build.rs | 1 + src/hyperlight_wasm_macro/src/lib.rs | 7 ++++++- src/wasm_runtime/build.rs | 1 + 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eca48d8b..f89df7e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Changed - **BREAKING CHANGE:** Removed `SandboxBuilder::with_function_definition_size`. Host function definitions are now pushed to the guest at runtime load time instead of using a separate memory region. (#388) +### Added +- Added support for selecting a specific world from WIT files with multiple worlds using the `WIT_WORLD_NAME` environment variable (#202) + ## [v0.12.0] - 2025-12 ### Added diff --git a/README.md b/README.md index 6b53ebb5..debd3779 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,32 @@ generate bindings from the same component type in the host. For a complete (albeit small) example of this, see [this example](https://aka.ms/hyperlight-wasm-sockets-sample). +### Selecting a specific world + +If your WIT file contains multiple worlds, you can select which world +to use by setting the `WIT_WORLD_NAME` environment variable to the name +of the desired world. If not set, the last world in the file will be used. + +For example, given a WIT file with multiple worlds: + +```wit +package example:worlds; + +world http-world { + export http-interface; +} + +world queue-world { + export queue-interface; +} +``` + +To generate bindings for `http-world` instead of the default `queue-world`: + +``` +WIT_WORLD=/path/to/output.wasm WIT_WORLD_NAME=http-world cargo build -p hyperlight-wasm +``` + ### Debugging the macro You can get more detailed error messages by expanding the Macro locally: diff --git a/src/hyperlight_wasm/build.rs b/src/hyperlight_wasm/build.rs index ed74b622..315fa0ba 100644 --- a/src/hyperlight_wasm/build.rs +++ b/src/hyperlight_wasm/build.rs @@ -103,6 +103,7 @@ fn build_wasm_runtime() -> PathBuf { println!("cargo::rerun-if-changed={}", in_repo_dir.display()); println!("cargo::rerun-if-env-changed=WIT_WORLD"); + println!("cargo::rerun-if-env-changed=WIT_WORLD_NAME"); // the PROFILE env var unfortunately only gives us 1 bit of "dev or release" let cargo_profile = if profile == "debug" { "dev" } else { "release" }; diff --git a/src/hyperlight_wasm_macro/src/lib.rs b/src/hyperlight_wasm_macro/src/lib.rs index 1eb8765f..19fdea20 100644 --- a/src/hyperlight_wasm_macro/src/lib.rs +++ b/src/hyperlight_wasm_macro/src/lib.rs @@ -26,10 +26,15 @@ mod wasmguest; /// into wasmtime) and registers wasmtime host functions with the /// wasmtime linker for component imports (which are implemented by /// calling to the Hyperlight host). +/// +/// If the WIT file contains multiple worlds, set the `WIT_WORLD_NAME` +/// environment variable to select a specific world by name. If not set, +/// the last world in the file will be used. #[proc_macro] pub fn wasm_guest_bindgen(_: proc_macro::TokenStream) -> proc_macro::TokenStream { let path = std::env::var_os("WIT_WORLD").unwrap(); - util::read_wit_type_from_file(path, None, |kebab_name, ct| { + let world_name = std::env::var("WIT_WORLD_NAME").ok(); + util::read_wit_type_from_file(path, world_name, |kebab_name, ct| { let decls = emit::run_state(true, true, |s| { // Emit type/trait definitions for all instances in the world rtypes::emit_toplevel(s, &kebab_name, ct); diff --git a/src/wasm_runtime/build.rs b/src/wasm_runtime/build.rs index 4b19da63..9a9572c8 100644 --- a/src/wasm_runtime/build.rs +++ b/src/wasm_runtime/build.rs @@ -60,6 +60,7 @@ fn main() { cfg.compile("wasm_runtime"); println!("cargo::rerun-if-env-changed=WIT_WORLD"); + println!("cargo::rerun-if-env-changed=WIT_WORLD_NAME"); println!("cargo::rustc-check-cfg=cfg(component)"); if env::var_os("WIT_WORLD").is_some() { println!("cargo::rustc-cfg=component"); From e52531a4a9cc11e7b1b4779d34877dc7483f35a7 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Fri, 6 Mar 2026 17:21:21 -0800 Subject: [PATCH 7/9] Add example Signed-off-by: James Sturtevant --- Cargo.toml | 2 +- Justfile | 9 +- src/component_sample/wit/example.wit | 8 + src/greeter_sample/Cargo.lock | 25 ++ src/greeter_sample/Cargo.toml | 21 ++ src/greeter_sample/src/bindings.rs | 222 ++++++++++++++++++ src/greeter_sample/src/lib.rs | 18 ++ src/hyperlight_wasm/Cargo.toml | 5 + src/hyperlight_wasm/build.rs | 2 +- .../examples/component_example/main.rs | 4 +- .../component_greeter_example/main.rs | 82 +++++++ src/hyperlight_wasm_macro/Cargo.lock | 17 +- src/hyperlight_wasm_macro/Cargo.toml | 2 +- src/hyperlight_wasm_macro/src/lib.rs | 2 + src/wasm_runtime/Cargo.lock | 204 ++++++++-------- 15 files changed, 509 insertions(+), 114 deletions(-) create mode 100644 src/greeter_sample/Cargo.lock create mode 100644 src/greeter_sample/Cargo.toml create mode 100644 src/greeter_sample/src/bindings.rs create mode 100644 src/greeter_sample/src/lib.rs create mode 100644 src/hyperlight_wasm/examples/component_greeter_example/main.rs diff --git a/Cargo.toml b/Cargo.toml index f3741f38..5b9c7306 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ "src/hyperlight_wasm", "src/examples_common", "src/hyperlight_wasm_aot" ] -exclude = [ "src/wasm_runtime", "src/rust_wasm_samples", "src/hyperlight_wasm_macro", "src/component_sample" ] +exclude = [ "src/wasm_runtime", "src/rust_wasm_samples", "src/hyperlight_wasm_macro", "src/component_sample", "src/greeter_sample" ] resolver = "2" [workspace.package] diff --git a/Justfile b/Justfile index d3686e07..057a7798 100644 --- a/Justfile +++ b/Justfile @@ -54,6 +54,8 @@ build-rust-component-examples target=default-target features="": (compile-wit) rustup target add wasm32-unknown-unknown cd ./src/component_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} 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/component_sample/target/wasm32-unknown-unknown/{{ target }}/component_sample.wasm ./x64/{{ target }}/component_sample.aot + cd ./src/greeter_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} + 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/greeter_sample/target/wasm32-unknown-unknown/{{ target }}/greeter_sample.wasm ./x64/{{ target }}/greeter_sample.aot build-pulley-rust-component-examples target=default-target features="": (compile-wit) # use cargo component so we don't get all the wasi imports https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#relationship-with-wasm32-wasip2 @@ -66,6 +68,7 @@ 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/greeter_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 } }} @@ -73,6 +76,7 @@ fmt-check: rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check cd src/rust_wasm_samples && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check cd src/component_sample && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check + cd src/greeter_sample && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check cd src/wasm_runtime && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check cd src/hyperlight_wasm_macro && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check @@ -81,6 +85,7 @@ fmt: cargo +nightly fmt --all cd src/rust_wasm_samples && cargo +nightly fmt -v --all cd src/component_sample && cargo +nightly fmt -v --all + cd src/greeter_sample && cargo +nightly fmt -v --all cd src/wasm_runtime && cargo +nightly fmt -v --all cd src/hyperlight_wasm_macro && cargo +nightly fmt -v --all @@ -88,9 +93,10 @@ export CC_x86_64_unknown_none:= if os() == "windows" { justfile_directory() / "s export AR_x86_64_unknown_none:= if os() == "windows" { "llvm-ar" } else { "" } clippy target=default-target: (check target) - cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings + cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings cd src/rust_wasm_samples && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings cd src/component_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings + cd src/greeter_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings cd src/wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings cd src/hyperlight_wasm_macro && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings @@ -115,6 +121,7 @@ examples-ci target=default-target features="": (build-rust-wasm-examples target) examples-components target=default-target features="": (build-rust-component-examples target) {{ wit-world }} cargo run {{ if features =="" {''} else {"--no-default-features -F kvm -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example component_example {{ wit-world-c }} cargo run {{ if features =="" {''} else {"--no-default-features -F kvm -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example c-component + {{ wit-world }} WIT_WORLD_NAME=greeter-world cargo run {{ if features =="" {''} else {"--no-default-features -F kvm -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example component_greeter_example # Test a component and a module compiled with pulley examples-pulley target=default-target features="": (build-pulley-rust-component-examples target) (build-pulley-rust-wasm-examples target) diff --git a/src/component_sample/wit/example.wit b/src/component_sample/wit/example.wit index 0d050580..93ddd517 100644 --- a/src/component_sample/wit/example.wit +++ b/src/component_sample/wit/example.wit @@ -1,4 +1,8 @@ package component-sample:example; +world greeter-world { + import host; + export greeter; +} world example { import host; @@ -14,4 +18,8 @@ interface adder { interface host { print: func(message: string); host-function: func(input: string) -> string; +} + +interface greeter { + greet: func(name: string) -> string; } \ No newline at end of file diff --git a/src/greeter_sample/Cargo.lock b/src/greeter_sample/Cargo.lock new file mode 100644 index 00000000..cbc7a4af --- /dev/null +++ b/src/greeter_sample/Cargo.lock @@ -0,0 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "greeter_sample" +version = "0.1.0" +dependencies = [ + "wit-bindgen-rt", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "653c85dd7aee6fe6f4bded0d242406deadae9819029ce6f7d258c920c384358a" +dependencies = [ + "bitflags", +] diff --git a/src/greeter_sample/Cargo.toml b/src/greeter_sample/Cargo.toml new file mode 100644 index 00000000..705ed01e --- /dev/null +++ b/src/greeter_sample/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "greeter_sample" +version = "0.1.0" +edition = "2024" + +[dependencies] +wit-bindgen-rt = { version = "0.44.0", features = ["bitflags"] } + +[lib] +crate-type = ["cdylib"] + +[package.metadata.component] +package = "component-sample:example" + +[package.metadata.component.target] +path = "../component_sample/wit/example.wit" +world = "greeter-world" + +[package.metadata.component.target.dependencies] + +[workspace] diff --git a/src/greeter_sample/src/bindings.rs b/src/greeter_sample/src/bindings.rs new file mode 100644 index 00000000..132963b1 --- /dev/null +++ b/src/greeter_sample/src/bindings.rs @@ -0,0 +1,222 @@ +// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! +// Options used: +// * runtime_path: "wit_bindgen_rt" +#[rustfmt::skip] +#[allow(dead_code, clippy::all)] +pub mod component_sample { + pub mod example { + #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] + pub mod host { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + #[allow(unused_unsafe, clippy::all)] + pub fn print(message: &str) -> () { + unsafe { + let vec0 = message; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component-sample:example/host")] + unsafe extern "C" { + #[link_name = "print"] + fn wit_import1(_: *mut u8, _: usize); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: *mut u8, _: usize) { + unreachable!() + } + unsafe { wit_import1(ptr0.cast_mut(), len0) }; + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn host_function(input: &str) -> _rt::String { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 2 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 2 + * ::core::mem::size_of::<*const u8>()], + ); + let vec0 = input; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component-sample:example/host")] + unsafe extern "C" { + #[link_name = "host-function"] + fn wit_import2(_: *mut u8, _: usize, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import2(_: *mut u8, _: usize, _: *mut u8) { + unreachable!() + } + unsafe { wit_import2(ptr0.cast_mut(), len0, ptr1) }; + let l3 = *ptr1.add(0).cast::<*mut u8>(); + let l4 = *ptr1 + .add(::core::mem::size_of::<*const u8>()) + .cast::(); + let len5 = l4; + let bytes5 = _rt::Vec::from_raw_parts(l3.cast(), len5, len5); + let result6 = _rt::string_lift(bytes5); + result6 + } + } + } + } +} +#[rustfmt::skip] +#[allow(dead_code, clippy::all)] +pub mod exports { + pub mod component_sample { + pub mod example { + #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] + pub mod greeter { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = super::super::super::super::__link_custom_section_describing_imports; + use super::super::super::super::_rt; + #[doc(hidden)] + #[allow(non_snake_case)] + pub unsafe fn _export_greet_cabi( + arg0: *mut u8, + arg1: usize, + ) -> *mut u8 { + #[cfg(target_arch = "wasm32")] _rt::run_ctors_once(); + let len0 = arg1; + let bytes0 = _rt::Vec::from_raw_parts(arg0.cast(), len0, len0); + let result1 = T::greet(_rt::string_lift(bytes0)); + let ptr2 = (&raw mut _RET_AREA.0).cast::(); + let vec3 = (result1.into_bytes()).into_boxed_slice(); + let ptr3 = vec3.as_ptr().cast::(); + let len3 = vec3.len(); + ::core::mem::forget(vec3); + *ptr2.add(::core::mem::size_of::<*const u8>()).cast::() = len3; + *ptr2.add(0).cast::<*mut u8>() = ptr3.cast_mut(); + ptr2 + } + #[doc(hidden)] + #[allow(non_snake_case)] + pub unsafe fn __post_return_greet(arg0: *mut u8) { + let l0 = *arg0.add(0).cast::<*mut u8>(); + let l1 = *arg0 + .add(::core::mem::size_of::<*const u8>()) + .cast::(); + _rt::cabi_dealloc(l0, l1, 1); + } + pub trait Guest { + fn greet(name: _rt::String) -> _rt::String; + } + #[doc(hidden)] + macro_rules! __export_component_sample_example_greeter_cabi { + ($ty:ident with_types_in $($path_to_types:tt)*) => { + const _ : () = { #[unsafe (export_name = + "component-sample:example/greeter#greet")] unsafe extern "C" fn + export_greet(arg0 : * mut u8, arg1 : usize,) -> * mut u8 { unsafe + { $($path_to_types)*:: _export_greet_cabi::<$ty > (arg0, arg1) } + } #[unsafe (export_name = + "cabi_post_component-sample:example/greeter#greet")] unsafe + extern "C" fn _post_return_greet(arg0 : * mut u8,) { unsafe { + $($path_to_types)*:: __post_return_greet::<$ty > (arg0) } } }; + }; + } + #[doc(hidden)] + pub(crate) use __export_component_sample_example_greeter_cabi; + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct _RetArea( + [::core::mem::MaybeUninit< + u8, + >; 2 * ::core::mem::size_of::<*const u8>()], + ); + static mut _RET_AREA: _RetArea = _RetArea( + [::core::mem::MaybeUninit::uninit(); 2 + * ::core::mem::size_of::<*const u8>()], + ); + } + } + } +} +#[rustfmt::skip] +mod _rt { + #![allow(dead_code, clippy::all)] + pub use alloc_crate::string::String; + pub use alloc_crate::vec::Vec; + pub unsafe fn string_lift(bytes: Vec) -> String { + if cfg!(debug_assertions) { + String::from_utf8(bytes).unwrap() + } else { + String::from_utf8_unchecked(bytes) + } + } + #[cfg(target_arch = "wasm32")] + pub fn run_ctors_once() { + wit_bindgen_rt::run_ctors_once(); + } + pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { + if size == 0 { + return; + } + let layout = alloc::Layout::from_size_align_unchecked(size, align); + alloc::dealloc(ptr, layout); + } + extern crate alloc as alloc_crate; + pub use alloc_crate::alloc; +} +/// Generates `#[unsafe(no_mangle)]` functions to export the specified type as +/// the root implementation of all generated traits. +/// +/// For more information see the documentation of `wit_bindgen::generate!`. +/// +/// ```rust +/// # macro_rules! export{ ($($t:tt)*) => (); } +/// # trait Guest {} +/// struct MyType; +/// +/// impl Guest for MyType { +/// // ... +/// } +/// +/// export!(MyType); +/// ``` +#[allow(unused_macros)] +#[doc(hidden)] +macro_rules! __export_greeter_world_impl { + ($ty:ident) => { + self::export!($ty with_types_in self); + }; + ($ty:ident with_types_in $($path_to_types_root:tt)*) => { + $($path_to_types_root)*:: + exports::component_sample::example::greeter::__export_component_sample_example_greeter_cabi!($ty + with_types_in $($path_to_types_root)*:: + exports::component_sample::example::greeter); + }; +} +#[doc(inline)] +pub(crate) use __export_greeter_world_impl as export; +#[cfg(target_arch = "wasm32")] +#[unsafe( + link_section = "component-type:wit-bindgen:0.41.0:component-sample:example:greeter-world:encoded world" +)] +#[doc(hidden)] +#[allow(clippy::octal_escapes)] +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 333] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xc9\x01\x01A\x02\x01\ +A\x04\x01B\x04\x01@\x01\x07messages\x01\0\x04\0\x05print\x01\0\x01@\x01\x05input\ +s\0s\x04\0\x0dhost-function\x01\x01\x03\0\x1dcomponent-sample:example/host\x05\0\ +\x01B\x02\x01@\x01\x04names\0s\x04\0\x05greet\x01\0\x04\0\x20component-sample:ex\ +ample/greeter\x05\x01\x04\0&component-sample:example/greeter-world\x04\0\x0b\x13\ +\x01\0\x0dgreeter-world\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-c\ +omponent\x070.227.1\x10wit-bindgen-rust\x060.41.0"; +#[inline(never)] +#[doc(hidden)] +pub fn __link_custom_section_describing_imports() { + wit_bindgen_rt::maybe_link_cabi_realloc(); +} diff --git a/src/greeter_sample/src/lib.rs b/src/greeter_sample/src/lib.rs new file mode 100644 index 00000000..b568e059 --- /dev/null +++ b/src/greeter_sample/src/lib.rs @@ -0,0 +1,18 @@ +#[allow(warnings)] +#[rustfmt::skip] +mod bindings; + +use bindings::component_sample::example::host::{host_function, print}; +use bindings::exports::component_sample::example::greeter::Guest; + +struct Component {} + +impl Guest for Component { + fn greet(name: String) -> String { + let prefix = host_function("prefix"); + print(&format!("Greeting {name}")); + format!("{prefix} {name}!") + } +} + +bindings::export!(Component with_types_in bindings); diff --git a/src/hyperlight_wasm/Cargo.toml b/src/hyperlight_wasm/Cargo.toml index 45e5f956..302dccf9 100644 --- a/src/hyperlight_wasm/Cargo.toml +++ b/src/hyperlight_wasm/Cargo.toml @@ -59,6 +59,11 @@ name = "interruption" path = "examples/interruption/main.rs" test = true +[[example]] +name = "component_greeter_example" +path = "examples/component_greeter_example/main.rs" +test = true + [dependencies] hyperlight-host = { workspace = true } hyperlight-common = { workspace = true } diff --git a/src/hyperlight_wasm/build.rs b/src/hyperlight_wasm/build.rs index 315fa0ba..9e1e47db 100644 --- a/src/hyperlight_wasm/build.rs +++ b/src/hyperlight_wasm/build.rs @@ -139,7 +139,7 @@ fn build_wasm_runtime() -> PathBuf { } cmd.status() - .unwrap_or_else(|e| panic!("could not run cargo build wasm_runtime: {}", e)); + .unwrap_or_else(|e| panic!("could not run cargo build wasm_runtime: {:?}", e)); let resource = target_dir .join("x86_64-hyperlight-none") diff --git a/src/hyperlight_wasm/examples/component_example/main.rs b/src/hyperlight_wasm/examples/component_example/main.rs index 39592feb..de2a4e11 100644 --- a/src/hyperlight_wasm/examples/component_example/main.rs +++ b/src/hyperlight_wasm/examples/component_example/main.rs @@ -7,7 +7,9 @@ use examples_common::get_wasm_module_path; extern crate alloc; mod bindings { - hyperlight_component_macro::host_bindgen!("../component_sample/wit/component-world.wasm"); + hyperlight_component_macro::host_bindgen!({ + path: "../component_sample/wit/component-world.wasm", + }); } pub struct State {} diff --git a/src/hyperlight_wasm/examples/component_greeter_example/main.rs b/src/hyperlight_wasm/examples/component_greeter_example/main.rs new file mode 100644 index 00000000..a0e3a788 --- /dev/null +++ b/src/hyperlight_wasm/examples/component_greeter_example/main.rs @@ -0,0 +1,82 @@ +#![allow(renamed_and_removed_lints)] +#![allow(unknown_lints)] +#![allow(unused_unit)] + +use bindings::component_sample::example::Greeter; +use examples_common::get_wasm_module_path; + +extern crate alloc; +mod bindings { + // Demonstrate world selection from a multi-world WIT package: + // The same component-world.wasm contains both "example" and "greeter-world", + // and we select "greeter-world" via world_name. + // Both worlds import the same "host" interface, showing interface reuse. + hyperlight_component_macro::host_bindgen!({ + path: "../component_sample/wit/component-world.wasm", + world_name: "greeter-world", + }); +} + +pub struct State { + prefix: String, +} + +impl State { + pub fn new(prefix: &str) -> Self { + State { + prefix: prefix.to_string(), + } + } +} + +// Same Host trait as component_example — shared interface across worlds +impl bindings::component_sample::example::Host for State { + fn r#print(&mut self, message: alloc::string::String) { + println!("[log] {message}"); + } + + fn r#host_function(&mut self, input: alloc::string::String) -> alloc::string::String { + if input == "prefix" { + self.prefix.clone() + } else { + format!("{input} and the host!") + } + } +} + +#[allow(refining_impl_trait)] +impl bindings::component_sample::example::GreeterWorldImports for State { + type Host = State; + + fn r#host(&mut self) -> &mut Self { + self + } +} + +fn main() { + let state = State::new("Hello"); + let mut sb: hyperlight_wasm::ProtoWasmSandbox = hyperlight_wasm::SandboxBuilder::new() + .with_guest_input_buffer_size(70000000) + .with_guest_heap_size(200000000) + .with_guest_scratch_size(100 * 1024 * 1024) + .build() + .unwrap(); + let rt = bindings::register_host_functions(&mut sb, state); + + let sb = sb.load_runtime().unwrap(); + + let mod_path = get_wasm_module_path("greeter_sample.aot").unwrap(); + let sb = sb.load_module(mod_path).unwrap(); + + let mut wrapped = bindings::GreeterWorldSandbox { sb, rt }; + + let instance = bindings::component_sample::example::GreeterWorldExports::greeter(&mut wrapped); + + let result = instance.greet("World".to_string()); + assert_eq!("Hello World!", result); + println!("Greet result: {result}"); + + let result = instance.greet("Hyperlight".to_string()); + assert_eq!("Hello Hyperlight!", result); + println!("Greet result: {result}"); +} diff --git a/src/hyperlight_wasm_macro/Cargo.lock b/src/hyperlight_wasm_macro/Cargo.lock index cabc94db..e5a80350 100644 --- a/src/hyperlight_wasm_macro/Cargo.lock +++ b/src/hyperlight_wasm_macro/Cargo.lock @@ -4,9 +4,9 @@ version = 4 [[package]] name = "bitflags" -version = "2.9.3" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" [[package]] name = "either" @@ -61,7 +61,6 @@ dependencies = [ "prettyplease", "proc-macro2", "quote", - "syn", ] [[package]] @@ -87,9 +86,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.27" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] name = "once_cell" @@ -133,9 +132,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" [[package]] name = "serde" @@ -211,9 +210,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "wasmparser" diff --git a/src/hyperlight_wasm_macro/Cargo.toml b/src/hyperlight_wasm_macro/Cargo.toml index 7c683f3e..e4eb2a54 100644 --- a/src/hyperlight_wasm_macro/Cargo.toml +++ b/src/hyperlight_wasm_macro/Cargo.toml @@ -13,7 +13,7 @@ proc-macro = true [dependencies] quote = { version = "1.0.45" } proc-macro2 = { version = "1.0.106" } -syn = { version = "2.0.117" } + itertools = { version = "0.14.0" } prettyplease = { version = "0.2.37" } hyperlight-component-util = { version = "0.13.0" } diff --git a/src/hyperlight_wasm_macro/src/lib.rs b/src/hyperlight_wasm_macro/src/lib.rs index 19fdea20..a34a5d92 100644 --- a/src/hyperlight_wasm_macro/src/lib.rs +++ b/src/hyperlight_wasm_macro/src/lib.rs @@ -48,3 +48,5 @@ pub fn wasm_guest_bindgen(_: proc_macro::TokenStream) -> proc_macro::TokenStream util::emit_decls(decls).into() }) } + + diff --git a/src/wasm_runtime/Cargo.lock b/src/wasm_runtime/Cargo.lock index e767de31..d508190a 100644 --- a/src/wasm_runtime/Cargo.lock +++ b/src/wasm_runtime/Cargo.lock @@ -34,9 +34,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" [[package]] name = "buddy_system_allocator" @@ -49,9 +49,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.19.0" +version = "3.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" dependencies = [ "allocator-api2", ] @@ -64,9 +64,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] name = "camino" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "276a59bf2b2c967788139340c9f0c5b12d7fd6630315c15c217e559de85d2609" +checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48" dependencies = [ "serde_core", ] @@ -372,9 +372,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" dependencies = [ "futures-core", "futures-sink", @@ -382,33 +382,33 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" [[package]] name = "futures-io" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" [[package]] name = "futures-sink" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" [[package]] name = "futures-task" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" [[package]] name = "futures-util" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" dependencies = [ "futures-core", "futures-io", @@ -416,15 +416,14 @@ dependencies = [ "futures-task", "memchr", "pin-project-lite", - "pin-utils", "slab", ] [[package]] name = "getrandom" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", "js-sys", @@ -570,14 +569,13 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" dependencies = [ "base64", "bytes", "futures-channel", - "futures-core", "futures-util", "http", "http-body", @@ -689,7 +687,6 @@ dependencies = [ "prettyplease", "proc-macro2", "quote", - "syn", ] [[package]] @@ -775,9 +772,9 @@ dependencies = [ [[package]] name = "id-arena" -version = "2.2.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" [[package]] name = "idna" @@ -814,15 +811,15 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.11.0" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" [[package]] name = "iri-string" -version = "0.7.9" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f867b9d1d896b67beb18518eda36fdb77a32ea590de864f1325b294a6d14397" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" dependencies = [ "memchr", "serde", @@ -839,15 +836,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" [[package]] name = "js-sys" -version = "0.3.83" +version = "0.3.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" +checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" dependencies = [ "once_cell", "wasm-bindgen", @@ -861,15 +858,15 @@ checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "libc" -version = "0.2.178" +version = "0.2.182" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" [[package]] name = "libm" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" [[package]] name = "linkme" @@ -893,9 +890,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "litemap" @@ -935,9 +932,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.6" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "memfd" @@ -985,9 +982,9 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "pin-project-lite" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pin-utils" @@ -1168,9 +1165,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.9.3" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" dependencies = [ "getrandom 0.3.4", ] @@ -1237,7 +1234,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom 0.2.16", + "getrandom 0.2.17", "libc", "untrusted", "windows-sys 0.52.0", @@ -1260,9 +1257,9 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.2" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ "bitflags", "errno", @@ -1273,9 +1270,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.35" +version = "0.23.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "533f54bc6a7d4f647e46ad909549eda97bf5afc1585190ef692b4286b198bd8f" +checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" dependencies = [ "once_cell", "ring", @@ -1287,9 +1284,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "708c0f9d5f54ba0272468c1d306a52c495b31fa155e91bc25371e6df7996908c" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" dependencies = [ "web-time", "zeroize", @@ -1297,9 +1294,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.8" +version = "0.103.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" dependencies = [ "ring", "rustls-pki-types", @@ -1314,9 +1311,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" -version = "1.0.20" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" [[package]] name = "scopeguard" @@ -1366,15 +1363,15 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.145" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "itoa", "memchr", - "ryu", "serde", "serde_core", + "zmij", ] [[package]] @@ -1397,9 +1394,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "slab" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" @@ -1412,12 +1409,12 @@ dependencies = [ [[package]] name = "socket2" -version = "0.6.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -1474,9 +1471,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.13.3" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c" +checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca" [[package]] name = "termcolor" @@ -1534,9 +1531,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.48.0" +version = "1.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" dependencies = [ "bytes", "libc", @@ -1588,9 +1585,9 @@ dependencies = [ [[package]] name = "tower" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" dependencies = [ "futures-core", "futures-util", @@ -1671,9 +1668,9 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "unicode-ident" -version = "1.0.22" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "unicode-xid" @@ -1689,9 +1686,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.7" +version = "2.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" dependencies = [ "form_urlencoded", "idna", @@ -1722,18 +1719,18 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasip2" -version = "1.0.1+wasi-0.2.4" +version = "1.0.2+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" dependencies = [ "wit-bindgen", ] [[package]] name = "wasm-bindgen" -version = "0.2.106" +version = "0.2.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" +checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" dependencies = [ "cfg-if", "once_cell", @@ -1744,11 +1741,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.56" +version = "0.4.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c" +checksum = "e9c5522b3a28661442748e09d40924dfb9ca614b21c00d3fd135720e48b67db8" dependencies = [ "cfg-if", + "futures-util", "js-sys", "once_cell", "wasm-bindgen", @@ -1757,9 +1755,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.106" +version = "0.2.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" +checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1767,9 +1765,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.106" +version = "0.2.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" +checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" dependencies = [ "bumpalo", "proc-macro2", @@ -1780,9 +1778,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.106" +version = "0.2.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" +checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" dependencies = [ "unicode-ident", ] @@ -2055,9 +2053,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.83" +version = "0.3.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac" +checksum = "854ba17bb104abfb26ba36da9729addc7ce7f06f5c0f90f3c391f8461cca21f9" dependencies = [ "js-sys", "wasm-bindgen", @@ -2075,9 +2073,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2878ef029c47c6e8cf779119f20fcf52bde7ad42a731b2a304bc221df17571e" +checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" dependencies = [ "rustls-pki-types", ] @@ -2275,18 +2273,18 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" [[package]] name = "winnow" -version = "0.7.14" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" dependencies = [ "memchr", ] [[package]] name = "wit-bindgen" -version = "0.46.0" +version = "0.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" [[package]] name = "wit-parser" @@ -2337,18 +2335,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.31" +version = "0.8.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3" +checksum = "a789c6e490b576db9f7e6b6d661bcc9799f7c0ac8352f56ea20193b2681532e5" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.31" +version = "0.8.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a" +checksum = "f65c489a7071a749c849713807783f70672b28094011623e200cb86dcb835953" dependencies = [ "proc-macro2", "quote", @@ -2414,3 +2412,9 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" From a7cb892ad9f8e199b0e0ad500a2282af7139bd1f Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Fri, 6 Mar 2026 17:58:22 -0800 Subject: [PATCH 8/9] Clean up our samples and structue them like upstream HL Signed-off-by: James Sturtevant --- Cargo.toml | 2 +- Justfile | 59 ++++++------ .../benches/benchmarks_components.rs | 2 +- .../examples/c-component/main.rs | 2 +- .../examples/component_example/main.rs | 2 +- .../component_greeter_example/main.rs | 2 +- .../scripts/build-wasm-examples.bat | 2 +- .../scripts/build-wasm-examples.sh | 2 +- .../c_guests}/wasmsamples/.gitignore | 0 .../c_guests}/wasmsamples/HelloWorld.c | 0 .../c_guests}/wasmsamples/HostFunction.c | 0 .../c_guests}/wasmsamples/RunWasm.c | 0 .../c_guests}/wasmsamples/compile-wasm.bat | 0 .../components/bindings/runcomponent.c | 85 ++++++++++++++++++ .../components/bindings/runcomponent.h | 40 +++++++++ .../bindings/runcomponent_component_type.o | Bin 0 -> 455 bytes .../wasmsamples/components/runcomponent.c | 0 .../wasmsamples/components/runcomponent.wit | 0 .../c_guests}/wasmsamples/dockerfile | 0 .../rust_guests}/component_sample/Cargo.lock | 0 .../rust_guests}/component_sample/Cargo.toml | 0 .../component_sample/src/bindings.rs | 0 .../rust_guests}/component_sample/src/lib.rs | 0 .../component_sample/wit/component-world.wasm | Bin 0 -> 899 bytes .../component_sample/wit/example.wit | 0 .../rust_guests}/greeter_sample/Cargo.lock | 0 .../rust_guests}/greeter_sample/Cargo.toml | 0 .../greeter_sample/src/bindings.rs | 0 .../rust_guests}/greeter_sample/src/lib.rs | 0 .../rust_wasm_samples/.cargo/config.toml | 0 .../rust_guests}/rust_wasm_samples/Cargo.lock | 0 .../rust_guests}/rust_wasm_samples/Cargo.toml | 0 .../rust_guests}/rust_wasm_samples/build.rs | 0 .../rust_guests}/rust_wasm_samples/src/lib.rs | 0 34 files changed, 162 insertions(+), 36 deletions(-) rename src/{ => tests/c_guests}/wasmsamples/.gitignore (100%) rename src/{ => tests/c_guests}/wasmsamples/HelloWorld.c (100%) rename src/{ => tests/c_guests}/wasmsamples/HostFunction.c (100%) rename src/{ => tests/c_guests}/wasmsamples/RunWasm.c (100%) rename src/{ => tests/c_guests}/wasmsamples/compile-wasm.bat (100%) create mode 100644 src/tests/c_guests/wasmsamples/components/bindings/runcomponent.c create mode 100644 src/tests/c_guests/wasmsamples/components/bindings/runcomponent.h create mode 100644 src/tests/c_guests/wasmsamples/components/bindings/runcomponent_component_type.o rename src/{ => tests/c_guests}/wasmsamples/components/runcomponent.c (100%) rename src/{ => tests/c_guests}/wasmsamples/components/runcomponent.wit (100%) rename src/{ => tests/c_guests}/wasmsamples/dockerfile (100%) rename src/{ => tests/rust_guests}/component_sample/Cargo.lock (100%) rename src/{ => tests/rust_guests}/component_sample/Cargo.toml (100%) rename src/{ => tests/rust_guests}/component_sample/src/bindings.rs (100%) rename src/{ => tests/rust_guests}/component_sample/src/lib.rs (100%) create mode 100644 src/tests/rust_guests/component_sample/wit/component-world.wasm rename src/{ => tests/rust_guests}/component_sample/wit/example.wit (100%) rename src/{ => tests/rust_guests}/greeter_sample/Cargo.lock (100%) rename src/{ => tests/rust_guests}/greeter_sample/Cargo.toml (100%) rename src/{ => tests/rust_guests}/greeter_sample/src/bindings.rs (100%) rename src/{ => tests/rust_guests}/greeter_sample/src/lib.rs (100%) rename src/{ => tests/rust_guests}/rust_wasm_samples/.cargo/config.toml (100%) rename src/{ => tests/rust_guests}/rust_wasm_samples/Cargo.lock (100%) rename src/{ => tests/rust_guests}/rust_wasm_samples/Cargo.toml (100%) rename src/{ => tests/rust_guests}/rust_wasm_samples/build.rs (100%) rename src/{ => tests/rust_guests}/rust_wasm_samples/src/lib.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 5b9c7306..68926bf4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ "src/hyperlight_wasm", "src/examples_common", "src/hyperlight_wasm_aot" ] -exclude = [ "src/wasm_runtime", "src/rust_wasm_samples", "src/hyperlight_wasm_macro", "src/component_sample", "src/greeter_sample" ] +exclude = [ "src/wasm_runtime", "src/hyperlight_wasm_macro", "src/tests/rust_guests/rust_wasm_samples", "src/tests/rust_guests/component_sample", "src/tests/rust_guests/greeter_sample" ] resolver = "2" [workspace.package] diff --git a/Justfile b/Justfile index 057a7798..a56fd698 100644 --- a/Justfile +++ b/Justfile @@ -3,8 +3,8 @@ default-tag:= "latest" build-wasm-examples-command := if os() == "windows" { "./src/hyperlight_wasm/scripts/build-wasm-examples.bat" } else { "./src/hyperlight_wasm/scripts/build-wasm-examples.sh" } mkdir-arg := if os() == "windows" { "-Force" } else { "-p" } latest-release:= if os() == "windows" {"$(git tag -l --sort=v:refname | select -last 2 | select -first 1)"} else {`git tag -l --sort=v:refname | tail -n 2 | head -n 1`} -wit-world := if os() == "windows" { "$env:WIT_WORLD=\"" + justfile_directory() + "\\src\\component_sample\\wit\\component-world.wasm" + "\";" } else { "WIT_WORLD=" + justfile_directory() + "/src/component_sample/wit/component-world.wasm" } -wit-world-c := if os() == "windows" { "$env:WIT_WORLD=\"" + justfile_directory() + "\\src\\wasmsamples\\components\\runcomponent-world.wasm" + "\";" } else { "WIT_WORLD=" + justfile_directory() + "/src/wasmsamples/components/runcomponent-world.wasm" } +wit-world := if os() == "windows" { "$env:WIT_WORLD=\"" + justfile_directory() + "\\src\\tests\\rust_guests\\component_sample\\wit\\component-world.wasm" + "\";" } else { "WIT_WORLD=" + justfile_directory() + "/src/tests/rust_guests/component_sample/wit/component-world.wasm" } +wit-world-c := if os() == "windows" { "$env:WIT_WORLD=\"" + justfile_directory() + "\\src\\tests\\c_guests\\wasmsamples\\components\\runcomponent-world.wasm" + "\";" } else { "WIT_WORLD=" + justfile_directory() + "/src/tests/c_guests/wasmsamples/components/runcomponent-world.wasm" } set windows-shell := ["pwsh.exe", "-NoLogo", "-Command"] @@ -30,8 +30,8 @@ mkdir-redist target=default-target: mkdir {{ mkdir-arg }} x64/{{ target }} compile-wit: - wasm-tools component wit ./src/wasmsamples/components/runcomponent.wit -w -o ./src/wasmsamples/components/runcomponent-world.wasm - wasm-tools component wit ./src/component_sample/wit/example.wit -w -o ./src/component_sample/wit/component-world.wasm + wasm-tools component wit ./src/tests/c_guests/wasmsamples/components/runcomponent.wit -w -o ./src/tests/c_guests/wasmsamples/components/runcomponent-world.wasm + wasm-tools component wit ./src/tests/rust_guests/component_sample/wit/example.wit -w -o ./src/tests/rust_guests/component_sample/wit/component-world.wasm build-examples target=default-target features="": (build-wasm-examples target features) (build-rust-wasm-examples target features) (build-rust-component-examples target features) @@ -40,52 +40,52 @@ build-wasm-examples target=default-target features="": (compile-wit) build-rust-wasm-examples target=default-target features="": (mkdir-redist target) rustup target add wasm32-unknown-unknown - cd ./src/rust_wasm_samples && cargo build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} - 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 {""} }} ./src/rust_wasm_samples/target/wasm32-unknown-unknown/{{ target }}/rust_wasm_samples.wasm ./x64/{{ target }}/rust_wasm_samples.aot + cd ./src/tests/rust_guests/rust_wasm_samples && cargo build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} + 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 {""} }} ./src/tests/rust_guests/rust_wasm_samples/target/wasm32-unknown-unknown/{{ target }}/rust_wasm_samples.wasm ./x64/{{ target }}/rust_wasm_samples.aot build-pulley-rust-wasm-examples target=default-target features="": (mkdir-redist target) rustup target add wasm32-unknown-unknown - cd ./src/rust_wasm_samples && cargo build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} - cargo run {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--features " + features } }} -p hyperlight-wasm-aot compile --pulley {{ if features =~ "gdb" {"--debug"} else {""} }} ./src/rust_wasm_samples/target/wasm32-unknown-unknown/{{ target }}/rust_wasm_samples.wasm ./x64/{{ target }}/rust_wasm_samples.aot + cd ./src/tests/rust_guests/rust_wasm_samples && cargo build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} + cargo run {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--features " + features } }} -p hyperlight-wasm-aot compile --pulley {{ if features =~ "gdb" {"--debug"} else {""} }} ./src/tests/rust_guests/rust_wasm_samples/target/wasm32-unknown-unknown/{{ target }}/rust_wasm_samples.wasm ./x64/{{ target }}/rust_wasm_samples.aot build-rust-component-examples target=default-target features="": (compile-wit) # use cargo component so we don't get all the wasi imports https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#relationship-with-wasm32-wasip2 # we also explicitly target wasm32-unknown-unknown since cargo component might try to pull in wasi imports https://github.com/bytecodealliance/cargo-component/issues/290 rustup target add wasm32-unknown-unknown - cd ./src/component_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} - 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/component_sample/target/wasm32-unknown-unknown/{{ target }}/component_sample.wasm ./x64/{{ target }}/component_sample.aot - cd ./src/greeter_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} - 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/greeter_sample/target/wasm32-unknown-unknown/{{ target }}/greeter_sample.wasm ./x64/{{ target }}/greeter_sample.aot + cd ./src/tests/rust_guests/component_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} + 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/tests/rust_guests/component_sample/target/wasm32-unknown-unknown/{{ target }}/component_sample.wasm ./x64/{{ target }}/component_sample.aot + cd ./src/tests/rust_guests/greeter_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} + 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/tests/rust_guests/greeter_sample/target/wasm32-unknown-unknown/{{ target }}/greeter_sample.wasm ./x64/{{ target }}/greeter_sample.aot build-pulley-rust-component-examples target=default-target features="": (compile-wit) # use cargo component so we don't get all the wasi imports https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#relationship-with-wasm32-wasip2 # we also explicitly target wasm32-unknown-unknown since cargo component might try to pull in wasi imports https://github.com/bytecodealliance/cargo-component/issues/290 rustup target add wasm32-unknown-unknown - cd ./src/component_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} - cargo run {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--features " + features } }} -p hyperlight-wasm-aot compile --pulley {{ if features =~ "gdb" {"--debug"} else {""} }} --component ./src/component_sample/target/wasm32-unknown-unknown/{{ target }}/component_sample.wasm ./x64/{{ target }}/component_sample.aot + cd ./src/tests/rust_guests/component_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} + cargo run {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--features " + features } }} -p hyperlight-wasm-aot compile --pulley {{ if features =~ "gdb" {"--debug"} else {""} }} --component ./src/tests/rust_guests/component_sample/target/wasm32-unknown-unknown/{{ target }}/component_sample.wasm ./x64/{{ target }}/component_sample.aot 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/greeter_sample && cargo check --profile={{ if target == "debug" {"dev"} else { target } }} + cd src/tests/rust_guests/rust_wasm_samples && cargo check --profile={{ if target == "debug" {"dev"} else { target } }} + cd src/tests/rust_guests/component_sample && cargo check --profile={{ if target == "debug" {"dev"} else { target } }} + cd src/tests/rust_guests/greeter_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 } }} fmt-check: rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check - cd src/rust_wasm_samples && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check - cd src/component_sample && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check - cd src/greeter_sample && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check + cd src/tests/rust_guests/rust_wasm_samples && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check + cd src/tests/rust_guests/component_sample && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check + cd src/tests/rust_guests/greeter_sample && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check cd src/wasm_runtime && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check cd src/hyperlight_wasm_macro && rustup toolchain install nightly -c rustfmt && cargo +nightly fmt -v --all -- --check fmt: rustup toolchain install nightly -c rustfmt cargo +nightly fmt --all - cd src/rust_wasm_samples && cargo +nightly fmt -v --all - cd src/component_sample && cargo +nightly fmt -v --all - cd src/greeter_sample && cargo +nightly fmt -v --all + cd src/tests/rust_guests/rust_wasm_samples && cargo +nightly fmt -v --all + cd src/tests/rust_guests/component_sample && cargo +nightly fmt -v --all + cd src/tests/rust_guests/greeter_sample && cargo +nightly fmt -v --all cd src/wasm_runtime && cargo +nightly fmt -v --all cd src/hyperlight_wasm_macro && cargo +nightly fmt -v --all @@ -93,10 +93,10 @@ export CC_x86_64_unknown_none:= if os() == "windows" { justfile_directory() / "s export AR_x86_64_unknown_none:= if os() == "windows" { "llvm-ar" } else { "" } clippy target=default-target: (check target) - cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings - cd src/rust_wasm_samples && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings - cd src/component_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings - cd src/greeter_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings + cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings + cd src/tests/rust_guests/rust_wasm_samples && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings + cd src/tests/rust_guests/component_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings + cd src/tests/rust_guests/greeter_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings cd src/wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings cd src/hyperlight_wasm_macro && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings @@ -109,14 +109,15 @@ test target=default-target features="": cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} cargo test test_metrics {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} -- --ignored -examples-ci target=default-target features="": (build-rust-wasm-examples target) +examples-modules target=default-target features="": (build-rust-wasm-examples target) cargo run {{ if features =="" {''} else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example helloworld cargo run {{ if features =="" {''} else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example hostfuncs cargo run {{ if features =="" {''} else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example rust_wasm_examples cargo run {{ if features =="" {''} else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example interruption cargo run {{ if features =="" {''} else {"--no-default-features -F function_call_metrics," + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example metrics cargo run {{ if features =="" {"--no-default-features --features kvm,mshv3"} else {"--no-default-features -F function_call_metrics," + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example metrics - just examples-pulley {{ target }} {{ features }} + +examples-ci target=default-target features="": (examples-modules target features) (examples-components target features) (examples-pulley target features) examples-components target=default-target features="": (build-rust-component-examples target) {{ wit-world }} cargo run {{ if features =="" {''} else {"--no-default-features -F kvm -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} --example component_example diff --git a/src/hyperlight_wasm/benches/benchmarks_components.rs b/src/hyperlight_wasm/benches/benchmarks_components.rs index 289d0e0e..bee15a33 100644 --- a/src/hyperlight_wasm/benches/benchmarks_components.rs +++ b/src/hyperlight_wasm/benches/benchmarks_components.rs @@ -8,7 +8,7 @@ use crate::bindings::example::runcomponent::Guest; extern crate alloc; mod bindings { hyperlight_component_macro::host_bindgen!( - "../../src/wasmsamples/components/runcomponent-world.wasm" + "../../src/tests/c_guests/wasmsamples/components/runcomponent-world.wasm" ); } diff --git a/src/hyperlight_wasm/examples/c-component/main.rs b/src/hyperlight_wasm/examples/c-component/main.rs index 3ebbd61e..2b0ddbed 100644 --- a/src/hyperlight_wasm/examples/c-component/main.rs +++ b/src/hyperlight_wasm/examples/c-component/main.rs @@ -6,7 +6,7 @@ use crate::bindings::example::runcomponent::Guest; extern crate alloc; mod bindings { hyperlight_component_macro::host_bindgen!( - "../../src/wasmsamples/components/runcomponent-world.wasm" + "../../src/tests/c_guests/wasmsamples/components/runcomponent-world.wasm" ); } diff --git a/src/hyperlight_wasm/examples/component_example/main.rs b/src/hyperlight_wasm/examples/component_example/main.rs index de2a4e11..3ccddcf7 100644 --- a/src/hyperlight_wasm/examples/component_example/main.rs +++ b/src/hyperlight_wasm/examples/component_example/main.rs @@ -8,7 +8,7 @@ use examples_common::get_wasm_module_path; extern crate alloc; mod bindings { hyperlight_component_macro::host_bindgen!({ - path: "../component_sample/wit/component-world.wasm", + path: "../tests/rust_guests/component_sample/wit/component-world.wasm", }); } diff --git a/src/hyperlight_wasm/examples/component_greeter_example/main.rs b/src/hyperlight_wasm/examples/component_greeter_example/main.rs index a0e3a788..76cd560b 100644 --- a/src/hyperlight_wasm/examples/component_greeter_example/main.rs +++ b/src/hyperlight_wasm/examples/component_greeter_example/main.rs @@ -12,7 +12,7 @@ mod bindings { // and we select "greeter-world" via world_name. // Both worlds import the same "host" interface, showing interface reuse. hyperlight_component_macro::host_bindgen!({ - path: "../component_sample/wit/component-world.wasm", + path: "../tests/rust_guests/component_sample/wit/component-world.wasm", world_name: "greeter-world", }); } diff --git a/src/hyperlight_wasm/scripts/build-wasm-examples.bat b/src/hyperlight_wasm/scripts/build-wasm-examples.bat index af1975dc..fae3d1ea 100644 --- a/src/hyperlight_wasm/scripts/build-wasm-examples.bat +++ b/src/hyperlight_wasm/scripts/build-wasm-examples.bat @@ -1,5 +1,5 @@ @echo off -pushd %~dp0\..\..\wasmsamples +pushd %~dp0\..\..\tests\c_guests\wasmsamples call :NORMALIZEPATH "..\..\x64\%1" echo "%ABSPATH%" call compile-wasm.bat "." "%ABSPATH%" diff --git a/src/hyperlight_wasm/scripts/build-wasm-examples.sh b/src/hyperlight_wasm/scripts/build-wasm-examples.sh index 0d714810..91fa012b 100755 --- a/src/hyperlight_wasm/scripts/build-wasm-examples.sh +++ b/src/hyperlight_wasm/scripts/build-wasm-examples.sh @@ -4,7 +4,7 @@ set -o errexit set -o nounset set -o pipefail -pushd "$(dirname "${BASH_SOURCE[0]}")/../../wasmsamples" +pushd "$(dirname "${BASH_SOURCE[0]}")/../../tests/c_guests/wasmsamples" OUTPUT_DIR="../../x64/${1:-"debug"}" BUILD_TYPE="${1:-"debug"}" FEATURES="${2:-""}" diff --git a/src/wasmsamples/.gitignore b/src/tests/c_guests/wasmsamples/.gitignore similarity index 100% rename from src/wasmsamples/.gitignore rename to src/tests/c_guests/wasmsamples/.gitignore diff --git a/src/wasmsamples/HelloWorld.c b/src/tests/c_guests/wasmsamples/HelloWorld.c similarity index 100% rename from src/wasmsamples/HelloWorld.c rename to src/tests/c_guests/wasmsamples/HelloWorld.c diff --git a/src/wasmsamples/HostFunction.c b/src/tests/c_guests/wasmsamples/HostFunction.c similarity index 100% rename from src/wasmsamples/HostFunction.c rename to src/tests/c_guests/wasmsamples/HostFunction.c diff --git a/src/wasmsamples/RunWasm.c b/src/tests/c_guests/wasmsamples/RunWasm.c similarity index 100% rename from src/wasmsamples/RunWasm.c rename to src/tests/c_guests/wasmsamples/RunWasm.c diff --git a/src/wasmsamples/compile-wasm.bat b/src/tests/c_guests/wasmsamples/compile-wasm.bat similarity index 100% rename from src/wasmsamples/compile-wasm.bat rename to src/tests/c_guests/wasmsamples/compile-wasm.bat diff --git a/src/tests/c_guests/wasmsamples/components/bindings/runcomponent.c b/src/tests/c_guests/wasmsamples/components/bindings/runcomponent.c new file mode 100644 index 00000000..f3813f35 --- /dev/null +++ b/src/tests/c_guests/wasmsamples/components/bindings/runcomponent.c @@ -0,0 +1,85 @@ +// Generated by `wit-bindgen` 0.43.0. DO NOT EDIT! +#include "runcomponent.h" +#include +#include + +// Imported Functions from `example:runcomponent/host` + +__attribute__((__import_module__("example:runcomponent/host"), __import_name__("get-time-since-boot-microsecond"))) +extern int64_t __wasm_import_example_runcomponent_host_get_time_since_boot_microsecond(void); + +// Exported Functions from `example:runcomponent/guest` + +__attribute__((__weak__, __export_name__("cabi_post_example:runcomponent/guest#echo"))) +void __wasm_export_exports_example_runcomponent_guest_echo_post_return(uint8_t * arg0) { + if ((*((size_t*) (arg0 + sizeof(void*)))) > 0) { + free(*((uint8_t **) (arg0 + 0))); + } +} + + +// Canonical ABI intrinsics + +__attribute__((__weak__, __export_name__("cabi_realloc"))) +void *cabi_realloc(void *ptr, size_t old_size, size_t align, size_t new_size) { + (void) old_size; + if (new_size == 0) return (void*) align; + void *ret = realloc(ptr, new_size); + if (!ret) abort(); + return ret; +} + +__attribute__((__aligned__(sizeof(void*)))) +static uint8_t RET_AREA[(2*sizeof(void*))]; + +// Helper Functions + +void runcomponent_string_set(runcomponent_string_t *ret, const char*s) { + ret->ptr = (uint8_t*) s; + ret->len = strlen(s); +} + +void runcomponent_string_dup(runcomponent_string_t *ret, const char*s) { + ret->len = strlen(s); + ret->ptr = (uint8_t*) cabi_realloc(NULL, 0, 1, ret->len * 1); + memcpy(ret->ptr, s, ret->len * 1); +} + +void runcomponent_string_free(runcomponent_string_t *ret) { + if (ret->len > 0) { + free(ret->ptr); + } + ret->ptr = NULL; + ret->len = 0; +} + +// Component Adapters + +int64_t example_runcomponent_host_get_time_since_boot_microsecond(void) { + int64_t ret = __wasm_import_example_runcomponent_host_get_time_since_boot_microsecond(); + return ret; +} + +__attribute__((__export_name__("example:runcomponent/guest#echo"))) +uint8_t * __wasm_export_exports_example_runcomponent_guest_echo(uint8_t * arg, size_t arg0) { + runcomponent_string_t arg1 = (runcomponent_string_t) { (uint8_t*)(arg), (arg0) }; + runcomponent_string_t ret; + exports_example_runcomponent_guest_echo(&arg1, &ret); + uint8_t *ptr = (uint8_t *) &RET_AREA; + *((size_t*)(ptr + sizeof(void*))) = (ret).len; + *((uint8_t **)(ptr + 0)) = (uint8_t *) (ret).ptr; + return ptr; +} + +__attribute__((__export_name__("example:runcomponent/guest#round-to-nearest-int"))) +int32_t __wasm_export_exports_example_runcomponent_guest_round_to_nearest_int(float arg, float arg0) { + int32_t ret = exports_example_runcomponent_guest_round_to_nearest_int(arg, arg0); + return ret; +} + +// Ensure that the *_component_type.o object is linked in + +extern void __component_type_object_force_link_runcomponent(void); +void __component_type_object_force_link_runcomponent_public_use_in_this_compilation_unit(void) { + __component_type_object_force_link_runcomponent(); +} diff --git a/src/tests/c_guests/wasmsamples/components/bindings/runcomponent.h b/src/tests/c_guests/wasmsamples/components/bindings/runcomponent.h new file mode 100644 index 00000000..d64663e0 --- /dev/null +++ b/src/tests/c_guests/wasmsamples/components/bindings/runcomponent.h @@ -0,0 +1,40 @@ +// Generated by `wit-bindgen` 0.43.0. DO NOT EDIT! +#ifndef __BINDINGS_RUNCOMPONENT_H +#define __BINDINGS_RUNCOMPONENT_H +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +typedef struct runcomponent_string_t { + uint8_t*ptr; + size_t len; +} runcomponent_string_t; + +// Imported Functions from `example:runcomponent/host` +extern int64_t example_runcomponent_host_get_time_since_boot_microsecond(void); + +// Exported Functions from `example:runcomponent/guest` +void exports_example_runcomponent_guest_echo(runcomponent_string_t *msg, runcomponent_string_t *ret); +int32_t exports_example_runcomponent_guest_round_to_nearest_int(float a, float b); + +// Helper Functions + +// Sets the string `ret` to reference the input string `s` without copying it +void runcomponent_string_set(runcomponent_string_t *ret, const char*s); + +// Creates a copy of the input nul-terminated string `s` and +// stores it into the component model string `ret`. +void runcomponent_string_dup(runcomponent_string_t *ret, const char*s); + +// Deallocates the string pointed to by `ret`, deallocating +// the memory behind the string. +void runcomponent_string_free(runcomponent_string_t *ret); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/tests/c_guests/wasmsamples/components/bindings/runcomponent_component_type.o b/src/tests/c_guests/wasmsamples/components/bindings/runcomponent_component_type.o new file mode 100644 index 0000000000000000000000000000000000000000..ad2b0bf369eada74e983d422bcf089347423a697 GIT binary patch literal 455 zcmZvZ&rSj{5XNV^MO5Hoj0t)$K0ud^;Khpz@jdEpcU-D$yJ@=!zN8Q0OISP*NVrYD z`R3nmpzsX>0CIc-NEpH;M+O7HfnzYvWL1fsaUPLg zM!Kyx%6140rnwQ$)XMKlU0}rEHZyf&w9;NUSvQq>R&V_|Ctzh0m`o6ozK#L-ORt0x zDzBAuvQRF-CXFq%|E(hp62!LEnJqoEsPS`C832fj({(Fu86ppmc$mUC52Ur zh#1@*h3ZFo=_zG5bTI?|fdO&FaDAqM_@n_`pRbqlxj$t}?2WB*29s-qbg=e)7mt8{ z{)NGRSwqU^_=gW0OR0npAG-Jg;A+~)?3I>OT4 literal 0 HcmV?d00001 diff --git a/src/component_sample/wit/example.wit b/src/tests/rust_guests/component_sample/wit/example.wit similarity index 100% rename from src/component_sample/wit/example.wit rename to src/tests/rust_guests/component_sample/wit/example.wit diff --git a/src/greeter_sample/Cargo.lock b/src/tests/rust_guests/greeter_sample/Cargo.lock similarity index 100% rename from src/greeter_sample/Cargo.lock rename to src/tests/rust_guests/greeter_sample/Cargo.lock diff --git a/src/greeter_sample/Cargo.toml b/src/tests/rust_guests/greeter_sample/Cargo.toml similarity index 100% rename from src/greeter_sample/Cargo.toml rename to src/tests/rust_guests/greeter_sample/Cargo.toml diff --git a/src/greeter_sample/src/bindings.rs b/src/tests/rust_guests/greeter_sample/src/bindings.rs similarity index 100% rename from src/greeter_sample/src/bindings.rs rename to src/tests/rust_guests/greeter_sample/src/bindings.rs diff --git a/src/greeter_sample/src/lib.rs b/src/tests/rust_guests/greeter_sample/src/lib.rs similarity index 100% rename from src/greeter_sample/src/lib.rs rename to src/tests/rust_guests/greeter_sample/src/lib.rs diff --git a/src/rust_wasm_samples/.cargo/config.toml b/src/tests/rust_guests/rust_wasm_samples/.cargo/config.toml similarity index 100% rename from src/rust_wasm_samples/.cargo/config.toml rename to src/tests/rust_guests/rust_wasm_samples/.cargo/config.toml diff --git a/src/rust_wasm_samples/Cargo.lock b/src/tests/rust_guests/rust_wasm_samples/Cargo.lock similarity index 100% rename from src/rust_wasm_samples/Cargo.lock rename to src/tests/rust_guests/rust_wasm_samples/Cargo.lock diff --git a/src/rust_wasm_samples/Cargo.toml b/src/tests/rust_guests/rust_wasm_samples/Cargo.toml similarity index 100% rename from src/rust_wasm_samples/Cargo.toml rename to src/tests/rust_guests/rust_wasm_samples/Cargo.toml diff --git a/src/rust_wasm_samples/build.rs b/src/tests/rust_guests/rust_wasm_samples/build.rs similarity index 100% rename from src/rust_wasm_samples/build.rs rename to src/tests/rust_guests/rust_wasm_samples/build.rs diff --git a/src/rust_wasm_samples/src/lib.rs b/src/tests/rust_guests/rust_wasm_samples/src/lib.rs similarity index 100% rename from src/rust_wasm_samples/src/lib.rs rename to src/tests/rust_guests/rust_wasm_samples/src/lib.rs From 813ff4e1c6cf85892685cd19d066f4963eba66e0 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Fri, 6 Mar 2026 18:06:01 -0800 Subject: [PATCH 9/9] Remove unneeded just call now that they are consolidated Signed-off-by: James Sturtevant --- .github/workflows/dep_build_wasm_examples.yml | 6 +++--- .github/workflows/dep_rust.yml | 4 ---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dep_build_wasm_examples.yml b/.github/workflows/dep_build_wasm_examples.yml index a29f4f8c..aa5c15cf 100644 --- a/.github/workflows/dep_build_wasm_examples.yml +++ b/.github/workflows/dep_build_wasm_examples.yml @@ -66,8 +66,8 @@ jobs: # Only push if not from a fork, not from pull request, and not from dependabot uses: docker/build-push-action@v6 with: - context: src/wasmsamples - file: src/wasmsamples/dockerfile + context: src/tests/c_guests/wasmsamples + file: src/tests/c_guests/wasmsamples/dockerfile load: true push: ${{ env.DO_PUSH }} build-args: | @@ -81,7 +81,7 @@ jobs: just ensure-tools just build-wasm-examples release shell: bash - working-directory: src/wasmsamples + working-directory: src/tests/c_guests/wasmsamples - name: Upload Wasm Modules uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/dep_rust.yml b/.github/workflows/dep_rust.yml index 540d77cc..38104bd4 100644 --- a/.github/workflows/dep_rust.yml +++ b/.github/workflows/dep_rust.yml @@ -120,10 +120,6 @@ jobs: # required for gh cli when downloading GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Test Component Model Examples - run: just examples-components ${{ matrix.config }} - working-directory: ./src/hyperlight_wasm - ### Benchmarks ### - name: Download benchmarks from "latest"