From eb7a1d5d424283fcfc3aa5bf406703a1569ea722 Mon Sep 17 00:00:00 2001 From: flemming-it Date: Fri, 1 May 2026 14:57:44 +0200 Subject: [PATCH] fix(macros): emit WASM glue only on target_arch = "wasm32" The #[fai_module] expansion previously always inserted the wit_bindgen::generate! call, the Guest impl, and the export! macro. That is correct on the wasm32 target but causes host compilation of a module crate to fail because wit_bindgen's runtime types are not in scope on a non-wasm target. The orchestrator-llm module worked around this with a manual #[cfg(target_arch = "wasm32")] gate around its hand-written wit_bindgen call. The point of the SDK is to remove that boilerplate, so the gate now lives inside the macro itself. Module crates can now declare crate-type = ["cdylib", "rlib"] and run integration tests via `cargo test` against the `invoke` function directly without having the WASM glue on the host build. Bumps the SDK patch version 0.1.0 -> 0.1.1 per the per-commit policy. Signed-off-by: flemming-it --- Cargo.toml | 2 +- crates/fai-module-sdk-macros/src/lib.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5d17850..6097ddc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ members = [ ] [workspace.package] -version = "0.1.0" +version = "0.1.1" edition = "2024" authors = ["Dr. Stefan Flemming "] license = "Apache-2.0" diff --git a/crates/fai-module-sdk-macros/src/lib.rs b/crates/fai-module-sdk-macros/src/lib.rs index 70d08e0..d842ec4 100644 --- a/crates/fai-module-sdk-macros/src/lib.rs +++ b/crates/fai-module-sdk-macros/src/lib.rs @@ -34,6 +34,12 @@ pub fn fai_module(_attrs: TokenStream, input: TokenStream) -> TokenStream { let expanded = quote! { #user_fn + // The WASM glue (wit_bindgen::generate!, Guest impl, export!) + // is only emitted for the wasm32 target. Host builds skip + // it so module crates can use crate-type = ["cdylib", "rlib"] + // and run integration tests via `cargo test` without + // dragging the wit_bindgen runtime onto the host target. + #[cfg(target_arch = "wasm32")] #[doc(hidden)] mod __fai_module_sdk_internal { #![allow(