From add87d8576d789e43a262c88f0f466b345d6166b Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 17 Mar 2026 14:43:02 -0700 Subject: [PATCH] fix: add wasmtime flags! macro support for WIT flags types When is_wasmtime_guest is true, emit wasmtime::component::flags! macro invocations instead of plain structs with bool fields. This enables WIT flags types (e.g. from wasi:filesystem) to satisfy the wasmtime::component::Lift and wasmtime::component::Lower trait bounds. The non-wasmtime code path (used by guest_bindgen and host_bindgen in this repo) is unchanged. The wasmtime path is used by the external hyperlight-wasm crate. Closes #1318 Signed-off-by: James Sturtevant --- src/hyperlight_component_util/src/rtypes.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/hyperlight_component_util/src/rtypes.rs b/src/hyperlight_component_util/src/rtypes.rs index 427344dae..185a20496 100644 --- a/src/hyperlight_component_util/src/rtypes.rs +++ b/src/hyperlight_component_util/src/rtypes.rs @@ -400,19 +400,35 @@ fn emit_value_toplevel(s: &mut State, v: Option, id: Ident, vt: &Value) -> } } Value::Flags(ns) => { - let (vs, toks) = gather_needed_vars(s, v, |_| { + let (vs, toks) = gather_needed_vars(s, v, |s| { let ns = ns .iter() .map(|n| { let orig_name = n.name; let id = kebab_to_var(orig_name); - quote! { pub #id: bool } + let derives = if s.is_wasmtime_guest { + quote! { #[component(name = #orig_name)] } + } else { + TokenStream::new() + }; + quote! { #derives pub #id: bool } }) .collect::>(); quote! { #(#ns),* } }); let vs = emit_type_defn_var_list(s, vs); + let derives = if s.is_wasmtime_guest { + quote! { + #[derive(::wasmtime::component::ComponentType)] + #[derive(::wasmtime::component::Lift)] + #[derive(::wasmtime::component::Lower)] + #[component(flags)] + } + } else { + TokenStream::new() + }; quote! { + #derives #[derive(Debug, Clone, PartialEq)] pub struct #id #vs { #toks } }