From 719e6f2d0ae6387232cbf0fe6dd6a2715a2fd4a7 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Wed, 25 Feb 2026 13:21:50 -0800 Subject: [PATCH 1/4] 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 | 4 ++++ README.md | 26 ++++++++++++++++++++++++++ src/hyperlight_wasm/build.rs | 1 + src/hyperlight_wasm_macro/src/lib.rs | 7 ++++++- src/hyperlight_wasm_runtime/build.rs | 1 + 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eca48d8b..bc907126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,12 @@ 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) +### 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 583786b4..cdf01cec 100644 --- a/src/hyperlight_wasm/build.rs +++ b/src/hyperlight_wasm/build.rs @@ -126,6 +126,7 @@ fn build_wasm_runtime() -> PathBuf { println!("cargo::rerun-if-changed={}", runtime_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 aa04b30f..8fc99953 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/hyperlight_wasm_runtime/build.rs b/src/hyperlight_wasm_runtime/build.rs index 5180de2f..1052686b 100644 --- a/src/hyperlight_wasm_runtime/build.rs +++ b/src/hyperlight_wasm_runtime/build.rs @@ -65,6 +65,7 @@ fn main() { cfg.compile("wasmtime-hyperlight-platform"); 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 a317067efe844a4a8b95b0c0bc823ffcdb6da231 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Fri, 6 Mar 2026 17:21:21 -0800 Subject: [PATCH 2/4] Add example Signed-off-by: James Sturtevant --- Cargo.toml | 2 +- Justfile | 13 +- 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 + .../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/hyperlight_wasm_runtime/Cargo.lock | 204 ++++++++-------- .../components/runcomponent-world.wasm | Bin 0 -> 503 bytes 15 files changed, 512 insertions(+), 113 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 create mode 100644 src/tests/c_guests/wasmsamples/components/runcomponent-world.wasm diff --git a/Cargo.toml b/Cargo.toml index 14d8acb3..99d511bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ "src/hyperlight_wasm", "src/examples_common", "src/hyperlight_wasm_aot", "src/hyperlight_wasm_runtime", "src/hyperlight_wasm_macro" ] -exclude = [ "src/rust_wasm_samples", "src/component_sample" ] +exclude = [ "src/rust_wasm_samples", "src/component_sample", "src/greeter_sample" ] resolver = "2" [workspace.package] diff --git a/Justfile b/Justfile index 9f62f148..85afd8b0 100644 --- a/Justfile +++ b/Justfile @@ -48,6 +48,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 @@ -61,6 +63,8 @@ check target=default-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/hyperlight_wasm_runtime && cargo hyperlight check --profile={{ if target == "debug" {"dev"} else { target } }} + cd src/greeter_sample && cargo check --profile={{ if target == "debug" {"dev"} else { target } }} + cd src/hyperlight_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: @@ -68,6 +72,8 @@ fmt-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/hyperlight_wasm_runtime && 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/hyperlight_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: @@ -76,13 +82,17 @@ fmt: cd src/rust_wasm_samples && cargo +nightly fmt -v --all cd src/component_sample && cargo +nightly fmt -v --all cd src/hyperlight_wasm_runtime && cargo +nightly fmt -v --all + cd src/greeter_sample && cargo +nightly fmt -v --all + cd src/hyperlight_wasm_runtime && cargo +nightly fmt -v --all cd src/hyperlight_wasm_macro && cargo +nightly fmt -v --all 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/hyperlight_wasm_runtime && cargo hyperlight 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/hyperlight_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 # TESTING @@ -106,6 +116,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 9123db6c..4228fb1b 100644 --- a/src/hyperlight_wasm/Cargo.toml +++ b/src/hyperlight_wasm/Cargo.toml @@ -51,6 +51,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/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 8a81efa6..3dc4e545 100644 --- a/src/hyperlight_wasm_macro/Cargo.toml +++ b/src/hyperlight_wasm_macro/Cargo.toml @@ -18,7 +18,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.workspace = true diff --git a/src/hyperlight_wasm_macro/src/lib.rs b/src/hyperlight_wasm_macro/src/lib.rs index 8fc99953..fdc497c8 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/hyperlight_wasm_runtime/Cargo.lock b/src/hyperlight_wasm_runtime/Cargo.lock index e767de31..d508190a 100644 --- a/src/hyperlight_wasm_runtime/Cargo.lock +++ b/src/hyperlight_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" diff --git a/src/tests/c_guests/wasmsamples/components/runcomponent-world.wasm b/src/tests/c_guests/wasmsamples/components/runcomponent-world.wasm new file mode 100644 index 0000000000000000000000000000000000000000..4a28778913f7f48a3d1ee2804ec0cc72c2cb9f56 GIT binary patch literal 503 zcmcJM!AiqG5QhIrwggQIB3|?&KESp`@!~1%-8b;E*$ipW-3i%Et%}d+E1C8nJrwcc z?PvJ;hWQ32xG4zP6D<>3DJm&-p$P~IitSnmR3>CLRBiCCaM8=)YaK;nd#PykcYOLQ{=b}z%5IKcb?8qaKPME2qf`NBMQ7}@ rX;{}{1ATmAe$w?)50?8t#TYGzz_qU4X!_bl{qvA)F}uCHpDn%txj>Sc literal 0 HcmV?d00001 From fe3cdeb4d5fae99894eca5eb40e5c708eaf1a95a Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Fri, 6 Mar 2026 17:58:22 -0800 Subject: [PATCH 3/4] Clean up our samples and structue them like upstream HL Signed-off-by: James Sturtevant --- .github/dependabot.yml | 4 +- .github/workflows/dep_build_wasm_examples.yml | 5 +- .github/workflows/dep_rust.yml | 4 - Cargo.toml | 2 +- Justfile | 75 +++++++++------- .../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 | 4 +- .../scripts/build-wasm-examples.sh | 4 +- src/hyperlight_wasm_macro/src/lib.rs | 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 38 files changed, 179 insertions(+), 54 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/.github/dependabot.yml b/.github/dependabot.yml index 441a97fe..7502cfcb 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -32,7 +32,7 @@ updates: - dependency-name: "wasmtime" update-types: ["version-update:semver-minor", "version-update:semver-major"] - package-ecosystem: "cargo" - directory: "/src/rust_wasm_samples" + directory: "/src/tests/rust_guests/rust_wasm_samples" schedule: interval: "daily" time: "03:00" @@ -48,7 +48,7 @@ updates: labels: - "kind/dependencies" - package-ecosystem: "cargo" - directory: "/src/component_sample" + directory: "/src/tests/rust_guests/component_sample" schedule: interval: "daily" time: "03:00" diff --git a/.github/workflows/dep_build_wasm_examples.yml b/.github/workflows/dep_build_wasm_examples.yml index a29f4f8c..71c24f36 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,6 @@ jobs: just ensure-tools just build-wasm-examples release shell: bash - working-directory: src/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" diff --git a/Cargo.toml b/Cargo.toml index 99d511bb..d6eaa73b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ "src/hyperlight_wasm", "src/examples_common", "src/hyperlight_wasm_aot", "src/hyperlight_wasm_runtime", "src/hyperlight_wasm_macro" ] -exclude = [ "src/rust_wasm_samples", "src/component_sample", "src/greeter_sample" ] +exclude = [ "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 85afd8b0..4f234f15 100644 --- a/Justfile +++ b/Justfile @@ -3,11 +3,18 @@ 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" } +wit-world-name-greeter := if os() == "windows" { "$env:WIT_WORLD_NAME=\"greeter-world\";" } else { "WIT_WORLD_NAME=greeter-world" } set windows-shell := ["pwsh.exe", "-NoLogo", "-Command"] +make-vendor-tar: + tar cf ./src/hyperlight_wasm/vendor.tar \ + --owner=0 --group=0 \ + --exclude-vcs-ignores \ + -C ./src wasm_runtime hyperlight_wasm_macro + ensure-tools: cargo install wasm-tools --locked --version 1.235.0 cargo install cargo-component --locked --version 0.21.1 @@ -24,8 +31,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) @@ -34,64 +41,63 @@ 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/hyperlight_wasm_runtime && cargo hyperlight 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/hyperlight_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/hyperlight_wasm_runtime && 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/hyperlight_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/hyperlight_wasm_runtime && 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/hyperlight_wasm_runtime && cargo +nightly fmt -v --all cd src/hyperlight_wasm_macro && cargo +nightly fmt -v --all +export CC_x86_64_unknown_none:= if os() == "windows" { justfile_directory() / "src/hyperlight_wasm_runtime/guest-toolchain/clang" } else { "" } +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/hyperlight_wasm_runtime && cargo hyperlight 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/hyperlight_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 @@ -104,19 +110,20 @@ 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 {{ 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 + {{ wit-world }} {{ wit-world-name-greeter }} 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/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..5170f8f5 100644 --- a/src/hyperlight_wasm/scripts/build-wasm-examples.bat +++ b/src/hyperlight_wasm/scripts/build-wasm-examples.bat @@ -1,6 +1,6 @@ @echo off -pushd %~dp0\..\..\wasmsamples -call :NORMALIZEPATH "..\..\x64\%1" +pushd %~dp0\..\..\tests\c_guests\wasmsamples +call :NORMALIZEPATH "..\..\..\..\x64\%1" echo "%ABSPATH%" call compile-wasm.bat "." "%ABSPATH%" popd diff --git a/src/hyperlight_wasm/scripts/build-wasm-examples.sh b/src/hyperlight_wasm/scripts/build-wasm-examples.sh index 0d714810..433a041c 100755 --- a/src/hyperlight_wasm/scripts/build-wasm-examples.sh +++ b/src/hyperlight_wasm/scripts/build-wasm-examples.sh @@ -4,8 +4,8 @@ set -o errexit set -o nounset set -o pipefail -pushd "$(dirname "${BASH_SOURCE[0]}")/../../wasmsamples" -OUTPUT_DIR="../../x64/${1:-"debug"}" +pushd "$(dirname "${BASH_SOURCE[0]}")/../../tests/c_guests/wasmsamples" +OUTPUT_DIR="../../../../x64/${1:-"debug"}" BUILD_TYPE="${1:-"debug"}" FEATURES="${2:-""}" mkdir -p ${OUTPUT_DIR} diff --git a/src/hyperlight_wasm_macro/src/lib.rs b/src/hyperlight_wasm_macro/src/lib.rs index fdc497c8..8fc99953 100644 --- a/src/hyperlight_wasm_macro/src/lib.rs +++ b/src/hyperlight_wasm_macro/src/lib.rs @@ -48,5 +48,3 @@ pub fn wasm_guest_bindgen(_: proc_macro::TokenStream) -> proc_macro::TokenStream util::emit_decls(decls).into() }) } - - 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 90362138d89ee0e16831d028b3a5268db85cac93 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 10 Mar 2026 14:06:32 -0700 Subject: [PATCH 4/4] Use lastest commit on hyperlight Signed-off-by: James Sturtevant --- Cargo.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ff9bff54..795d2de8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1693,7 +1693,6 @@ dependencies = [ "prettyplease", "proc-macro2", "quote", - "syn", ] [[package]]