name: rig-wasm-check description: > Audit Rig code for WebAssembly compatibility. Use when verifying that trait bounds use WasmCompatSend/WasmCompatSync, futures use WasmBoxedFuture, and error types have proper conditional compilation. allowed-tools:
- •Read
- •Glob
- •Grep
Rig WASM Compatibility Check
Audit code for WebAssembly target compatibility.
Check these patterns:
- •All trait bounds use
WasmCompatSend/WasmCompatSyncinstead of rawSend/Sync. - •Boxed futures use
WasmBoxedFutureinstead ofPin<Box<dyn Future + Send>>. - •Error types use
#[cfg(target_family = "wasm")]for platform-specific bounds. - •No direct
Send/Syncbounds that would break WASM compilation.
rig-wasm-compat
Rig supports WebAssembly targets. Since WASM is single-threaded, Send/Sync bounds are unnecessary and can prevent compilation.
The Pattern
rust
#[cfg(not(target_family = "wasm"))]
pub trait WasmCompatSend: Send {} // native
#[cfg(target_family = "wasm")]
pub trait WasmCompatSend {} // wasm
#[cfg(not(target_family = "wasm"))]
pub trait WasmCompatSync: Sync {} // native
#[cfg(target_family = "wasm")]
pub trait WasmCompatSync {} // wasm
Usage Rules
Always use WasmCompatSend and WasmCompatSync instead of raw Send and Sync in trait bounds.
rust
// Correct
pub trait MyTrait: WasmCompatSend + WasmCompatSync {
fn do_thing(&self) -> impl Future<Output = ()> + WasmCompatSend;
}
// Incorrect - will break WASM builds
pub trait MyTrait: Send + Sync {
fn do_thing(&self) -> impl Future<Output = ()> + Send;
}
Boxed Futures
Use WasmBoxedFuture for boxed futures:
rust
pub type WasmBoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>; // native pub type WasmBoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>; // wasm
Conditional Error Types
Some error types need platform-specific bounds:
rust
#[derive(Debug, thiserror::Error)]
pub enum MyError {
#[cfg(not(target_family = "wasm"))]
#[error("Error: {0}")]
Inner(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
#[cfg(target_family = "wasm")]
#[error("Error: {0}")]
Inner(#[from] Box<dyn std::error::Error + 'static>),
}