Skip to content

feat: Add #[main] and #[dispatch] macros for type-safe guest entry points#1384

Open
jprendes wants to merge 2 commits intohyperlight-dev:mainfrom
jprendes:weak-functions
Open

feat: Add #[main] and #[dispatch] macros for type-safe guest entry points#1384
jprendes wants to merge 2 commits intohyperlight-dev:mainfrom
jprendes:weak-functions

Conversation

@jprendes
Copy link
Copy Markdown
Contributor

Summary

This PR introduces #[main] and #[dispatch] attribute macros for defining guest entry points, replacing the previous pattern of manually exporting extern "C" functions with #[no_mangle].

Changes

Make entry points optional

  • hyperlight_main and guest_dispatch_function are now optional using weak symbols with sensible defaults:
    • hyperlight_main defaults to a no-op
    • guest_dispatch_function defaults to returning a GuestFunctionNotFound error

Add attribute macros

  • #[main] - Marks a function as the guest's initialization entry point
  • #[dispatch] - Marks a function as the fallback handler for unregistered function calls

Example

Before:

#[no_mangle]
pub extern "C" fn hyperlight_main() {
    // initialization code
}

#[no_mangle]
pub fn guest_dispatch_function(function_call: FunctionCall) -> Result<Vec<u8>> {
    // dispatch logic
}

After:

#[hyperlight_guest_bin::main]
fn main() {
    // initialization code
}

#[hyperlight_guest_bin::dispatch]
fn dispatch(function_call: FunctionCall) -> Result<Vec<u8>> {
    // dispatch logic
}

Benefits

  • Ergonomic API: No need for #[no_mangle] or extern "C" boilerplate
  • Optional entry points: Guests that don't need initialization or custom dispatch no longer need to define stub functions
  • Future-proof: The macro approach enables compile-time function signature validation in the future, catching mismatches early rather than at link time or runtime

@jprendes jprendes added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Apr 16, 2026
@jprendes jprendes changed the title feat: Add #[main] and #[dispatch] macros for type-safe guest entry points *feat:* Add #[main] and #[dispatch] macros for type-safe guest entry points Apr 17, 2026
@jprendes jprendes changed the title *feat:* Add #[main] and #[dispatch] macros for type-safe guest entry points **feat:** Add #[main] and #[dispatch] macros for type-safe guest entry points Apr 17, 2026
@jprendes jprendes changed the title **feat:** Add #[main] and #[dispatch] macros for type-safe guest entry points feat: Add #[main] and #[dispatch] macros for type-safe guest entry points Apr 17, 2026
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
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.

1 participant