Skip to content

Conversation

@jprendes
Copy link
Contributor

@jprendes jprendes commented Sep 2, 2025

This pull request introduces a new func module to the hyperlight-common crate, which is used to providing new register_fn function for guest function registration: register_fn("function_name", the_function). The traits in the func module are used to specify and constrain the type of the_function.

It refactors existing function-related code from hyperlight_host into hyperlight_common.

This pull request also introduces a new hyperlight_guest_macro crate that defines two proc-macros: host_function and guest_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 the FunctionCall and serializing the result using into_flatbuffer_result. The function is also automatically registered before the call to hyperlight_main, removing the need to do manual registration in hyperlight_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)

@jprendes jprendes added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Sep 2, 2025
@jprendes jprendes force-pushed the guest-registration branch 5 times, most recently from b86709b to 870d40b Compare December 2, 2025 14:15
@jprendes jprendes marked this pull request as ready for review December 2, 2025 15:10
@jprendes jprendes force-pushed the guest-registration branch 4 times, most recently from 87b2390 to da5bad6 Compare December 3, 2025 11:43
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Btw, how does linkme work? xD

@jprendes jprendes enabled auto-merge (squash) December 3, 2025 21:00
simongdavies
simongdavies previously approved these changes Dec 3, 2025
@jprendes
Copy link
Contributor Author

jprendes commented Dec 3, 2025

Looks good to me. Btw, how does linkme work? xD

This is the best explanation I found, other than inspecting the source code :-)
https://internals.rust-lang.org/t/from-life-before-main-to-common-life-in-main/16006/24

Copy link
Contributor

@dblnz dblnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Good work Jorge!
I didn't get to look very thoroughly, but overall it looks good

@jprendes jprendes merged commit 09346ac into hyperlight-dev:main Dec 3, 2025
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants