Crate hyperlight_component_macro

Crate hyperlight_component_macro 

Source
Expand description

§Component-model bindgen macros

These macros make it easy to use Wasm Component Model types (e.g. those described by WIT) to describe the interface between a Hyperlight host and guest.

For both host and guest bindings, bindings generation takes in a binary-encoded wasm component, which should have roughly the structure of a binary-encoded WIT (in particular, component import/export kebab-names should have wit:package/name namespace structure, and the same two-level convention for wrapping a component type into an actual component should be adhered to). If you are using WIT as the input, it is easy to build such a file via wasm-tools component wit -w -o file.wasm file.wit.

Both macros can take the path to such a file as a parameter, or, if one is not provided, will fall back to using the path in the environment variable $WIT_WORLD. A relative path provided either way will be resolved relative to $CARGO_MANIFEST_DIR.

§Debugging

The generated code can be examined by setting the environment variable $HYPERLIGHT_COMPONENT_MACRO_DEBUG=/path/to/file.rs, which will result in the generated code being written to that file, which is then included back into the Rust source.

The macros also can be configured to output a great deal of debug information about the internal elaboration and codegen phases. This is logged via the log and env_logger crates, so setting RUST_LOG=debug before running the compiler should suffice to produce this output.

Macros§

guest_bindgen
Create the hyperlight_guest_init() function (which should be called in hyperlight_main()) for the wasm component type in the file passed in (or $WIT_WORLD, if nothing is passed in). This function registers Hyperlight functions for component exports (which are implemented by calling into the trait provided) and implements the relevant traits for a trivial Host type (by calling into the Hyperlight host).
host_bindgen
Create host bindings for the wasm component type in the file passed in (or $WIT_WORLD, if nothing is passed in). This will produce all relevant types and trait implementations for the component type, as well as functions allowing the component to be instantiated inside a sandbox.