Guest function improvements and macros#851
Merged
jprendes merged 9 commits intohyperlight-dev:mainfrom Dec 3, 2025
Merged
Conversation
c198729 to
3e49309
Compare
3e49309 to
db49f17
Compare
b86709b to
870d40b
Compare
jprendes
commented
Dec 2, 2025
jsturtevant
reviewed
Dec 2, 2025
jsturtevant
reviewed
Dec 2, 2025
87b2390 to
da5bad6
Compare
ludfjig
reviewed
Dec 3, 2025
Contributor
ludfjig
left a comment
There was a problem hiding this comment.
Looks good to me. Btw, how does linkme work? xD
da5bad6 to
804f4bf
Compare
simongdavies
previously approved these changes
Dec 3, 2025
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
…uest-bin Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
804f4bf to
62895b2
Compare
Contributor
Author
This is the best explanation I found, other than inspecting the source code :-) |
simongdavies
approved these changes
Dec 3, 2025
jsturtevant
approved these changes
Dec 3, 2025
dblnz
reviewed
Dec 3, 2025
Contributor
dblnz
left a comment
There was a problem hiding this comment.
This looks great! Good work Jorge!
I didn't get to look very thoroughly, but overall it looks good
vshailesh
pushed a commit
to vshailesh/hyperlight
that referenced
this pull request
Dec 7, 2025
* move function type traits to hyperlight_common Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * Use function type traits to improve registration ergonomics Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * Add from_result method to ResultType Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * Add guest macro crate Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * use guest_function and host_function macros in simpleguest Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * update test guests Cargo.lock files Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * Move result unwrap used in host_function macro from hl-common to hl-guest-bin Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * Add comments on tricky areas Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> * update README.md to use new macros Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> --------- Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new
funcmodule to thehyperlight-commoncrate, which is used to providing newregister_fnfunction for guest function registration:register_fn("function_name", the_function). The traits in thefuncmodule are used to specify and constrain the type ofthe_function.It refactors existing function-related code from
hyperlight_hostintohyperlight_common.This pull request also introduces a new
hyperlight_guest_macrocrate that defines two proc-macros:host_functionandguest_function.host_function: This macro is used to declare host functions in a hyperlight guest. The specified function must have no body (like an ffi function declaration), and the signature is used to create a wrapper for a host function call with the correct types.guest_function: This macros is used to declare guest functions in a hyperlight guest. The function signature is used to create a wrapper that takes care of extracting the arguments from theFunctionCalland serializing the result usinginto_flatbuffer_result. The function is also automatically registered before the call tohyperlight_main, removing the need to do manual registration inhyperlight_main.To enable the automatic registration of functions, the MSRV is bumped to 1.89 (which includes rust-lang/rust#137685, which is required as the automatic registration uses linkme)