Remove host function definition region dependency #389
Remove host function definition region dependency #389jsturtevant wants to merge 3 commits intohyperlight-dev:mainfrom
Conversation
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 <jsturtevant@gmail.com>
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 <jsturtevant@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR removes the guest’s dependency on a dedicated “host function definition region” by having the host serialize host function definitions and pass them directly into the guest’s InitWasmRuntime call, aligning with upstream HL-core changes (issue #388).
Changes:
- Update the guest wasm runtime to parse
HostFunctionDetailsfromInitWasmRuntimeparameters (VecBytes) instead of reading from a shared region / callback. - Update the host sandbox initialization to track + serialize registered host function definitions and pass them into
InitWasmRuntime. - Remove
SandboxBuilder::with_function_definition_sizeand document the breaking change; add[workspace]stanzas to excluded crates to avoid workspace resolution issues.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/wasm_runtime/src/module.rs | InitWasmRuntime now expects a VecBytes parameter containing serialized host function details and registers host funcs from it. |
| src/wasm_runtime/src/hostfuncs.rs | Removes the old get_host_function_details() path. |
| src/wasm_runtime/src/component.rs | Updates InitWasmRuntime signature in the component runtime interface (now takes VecBytes). |
| src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs | Tracks host function definitions as they’re registered; serializes and passes them to InitWasmRuntime. |
| src/hyperlight_wasm/src/sandbox/sandbox_builder.rs | Removes the builder API for host function definition region sizing. |
| src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs | Adds a regression test ensuring missing host functions fail module load. |
| src/hyperlight_wasm/Cargo.toml | Adds hyperlight-common dependency used for flatbuffer wrapper types. |
| Cargo.toml | Adds hyperlight-common to workspace dependencies. |
| Cargo.lock | Locks hyperlight-common dependency. |
| src/rust_wasm_samples/Cargo.toml | Adds [workspace] to make the crate a standalone workspace root when built directly. |
| src/hyperlight_wasm_macro/Cargo.toml | Adds [workspace] to make the crate a standalone workspace root when built directly. |
| src/component_sample/Cargo.toml | Adds [workspace] to make the crate a standalone workspace root when built directly. |
| CHANGELOG.md | Documents the breaking removal of SandboxBuilder::with_function_definition_size. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
dblnz
left a comment
There was a problem hiding this comment.
LGTM!
I left some small comments that are not necessary to be addressed in this PR.
|
|
||
| [package.metadata.component.target.dependencies] | ||
|
|
||
| [workspace] # indicate that this crate is not part of any workspace |
There was a problem hiding this comment.
This is to avoid building it with the main workspace?
| prettyplease = { version = "0.2.37" } | ||
| hyperlight-component-util = { version = "0.12.0" } | ||
|
|
||
| [workspace] # indicate that this crate is not part of any workspace |
There was a problem hiding this comment.
The same reason as the other added [workspace], to avoid building with the entire project?
There was a problem hiding this comment.
I think these were already in the exclude table in the workspace root Cargo.toml, which means that it was just a bit broken to have that but not this.
|
|
||
| #[instrument(skip_all, level = "Info")] | ||
| fn init_wasm_runtime() -> Result<Vec<u8>> { | ||
| fn init_wasm_runtime(function_call: &FunctionCall) -> Result<Vec<u8>> { |
There was a problem hiding this comment.
Nit: This could be done in another PR for all guest functions, but as we've touched this, can we switch to using the macros?
I think it'll be a nicer format, easier for reviewing changes and removes the need for checking the FunctionCall ourselves.
#[guest_function("InitWasmRuntime")]
fn init_wasm_runtime(hfd: hostfuncs::HostFunctionDetails) -> i32 {
Note: I am not sure the deserialization to HostFunctionDetails will work out of the box, but still, a big part of the logic below goes awa.
There was a problem hiding this comment.
I've just seen the comment Ludvig left about this, it's on the same thing, so disregard it
syntactically
left a comment
There was a problem hiding this comment.
Mostly LGTM, except for the comment about HostPrint.
| Ok(Self { inner: Some(inner) }) | ||
|
|
||
| // HostPrint is always registered by UninitializedSandbox, so include it by default | ||
| let host_function_definitions = vec![HostFunctionDefinition { |
There was a problem hiding this comment.
I'm not convinced this should be here. HostPrint is sort of an internal implementation detail? I don't think that wasm modules should be able to just import it automatically with no way to remove that.
|
|
||
| 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; |
There was a problem hiding this comment.
I guess the only place where these structs cross the host/guest boundary is now hlwasm/hljs downstreams, which makes it feel a little weird that they are still defined in hlcommon. I don't think we need to do anything about this right now since IIRC it's pretty urgent to get this in so we can prepare for release, but perhaps it's worth thinking about...
| prettyplease = { version = "0.2.37" } | ||
| hyperlight-component-util = { version = "0.12.0" } | ||
|
|
||
| [workspace] # indicate that this crate is not part of any workspace |
There was a problem hiding this comment.
I think these were already in the exclude table in the workspace root Cargo.toml, which means that it was just a bit broken to have that but not this.
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.
fixes #388