fix: add wasmtime flags! macro support for WIT flags types#1327
Open
jsturtevant wants to merge 1 commit into
Open
fix: add wasmtime flags! macro support for WIT flags types#1327jsturtevant wants to merge 1 commit into
jsturtevant wants to merge 1 commit into
Conversation
Contributor
Author
|
moved this to draft, I was integrating into hyperlight-wasm and found the usage of flags needs to be slightly different. than this. will push an update shortly |
f0c8e64 to
b68803b
Compare
jsturtevant
commented
Jun 19, 2026
b319154 to
564c59e
Compare
564c59e to
6e6617d
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Hyperlight component Rust code generator to correctly support WIT flags types when generating Wasmtime guest bindings, by emitting wasmtime::component::flags! (and updating marshal/unmarshal codegen accordingly) so the generated types satisfy Wasmtime’s Lift/Lower trait bounds. Non-Wasmtime generation paths remain unchanged.
Changes:
- Emit
::wasmtime::component::flags! { ... }for WITflagstypes whenis_wasmtime_guestis enabled (instead of apub structwithboolfields). - Update Hyperlight marshal/unmarshal codegen for Wasmtime guests to use the Wasmtime flags API (
empty(),|=,.contains(...)) rather than field access. - Add an integration test validating the Wasmtime flags macro emission and wire it into
just test-integration.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/hyperlight_component_util/tests/wasmtime_guest_codegen.rs | Adds an integration test to validate Wasmtime guest codegen emits wasmtime::component::flags! for WIT flags. |
| src/hyperlight_component_util/src/rtypes.rs | Switches Wasmtime-guest flags type emission from bool-field structs to the Wasmtime flags! macro, preserving original WIT names. |
| src/hyperlight_component_util/src/hl.rs | Updates marshal/unmarshal codegen for flags in the Wasmtime-guest path to use flags operations (empty, ` |
| src/hyperlight_component_util/src/emit.rs | Introduces kebab_to_flags_const helper for generating SCREAMING_SNAKE_CASE flag constant identifiers. |
| Justfile | Ensures test-integration runs after generating WIT-derived .wasm inputs and runs the new component-util integration test. |
ludfjig
previously approved these changes
Jun 19, 2026
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
e3d190c to
26d09f5
Compare
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.
When
is_wasmtime_guestis true, emitwasmtime::component::flags!macro invocations instead of plain structs with bool fields. This enables WIT flags types (e.g. fromwasi:filesystem) to satisfy thewasmtime::component::Liftandwasmtime::component::Lowertrait bounds. See https://docs.rs/wasmtime/latest/wasmtime/component/macro.flags.htmlThe non-Wasmtime code path used by
host_bindgen!and Hyperlightguest_bindgen!in this repo is unchanged. The Wasmtime path is used by downstream Wasmtime guest-bindgen consumers.WIT flags input
The tests use the existing WIT flags in
src/tests/rust_guests/witguest/guest.wit:Expected non-Wasmtime Rust output
host_bindgen!and Hyperlightguest_bindgen!keep generating a bool-field struct:Expected Wasmtime guest Rust output
The Wasmtime guest generator emits the real Wasmtime flags macro and preserves the original WIT names on each constant:
Expected marshal/unmarshal output
Because the type produced by
wasmtime::component::flags!is bitflag-style, the Hyperlight-generated Wasmtime guest marshal/unmarshal code cannot access fields likevalue.flag_a. Note: I did consider just porting over to useing bitflag-style everywhere but that's a much bigger change.For non-Wasmtime bindings, Hyperlight still generates code that reads and writes bool fields:
For Wasmtime guest bindings, Hyperlight now generates code that uses the Wasmtime flags API:
Closes #1318
Signed-off-by: James Sturtevant jsturtevant@gmail.com