-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Problem
The flagd crate cannot compile to wasm32-unknown-unknown for use in Cloudflare Workers or other WASM environments. The crate's provider stack — gRPC, HTTP, file watching, and caching — all depend on tokio with rt, rt-multi-thread, and net features, which require OS-level I/O primitives not available in WASM:
| Component | Dependency | Blocker |
|---|---|---|
| RPC / in-process resolver | tokio, tonic |
Requires OS I/O, not WASM-compatible |
| REST resolver | tokio, reqwest |
Requires OS networking |
| File sync / watching | tokio, notify |
Requires OS file system |
| Cache | tokio |
Requires async runtime |
Note: open-feature/rust-sdk#127 (pending) fixes the open-feature crate's own WASM incompatibility by narrowing its tokio dependency from features = ["full"] to just features = ["sync"], which is WASM-compatible. The blockers above are independent of that and exist in the flagd crate itself.
The flagd evaluation logic (JSONLogic rules, fractional rollouts, semver, string operators) is fully synchronous and has no inherent WASM incompatibility — the blocker is entirely the provider/networking infrastructure.
Proposed Solution
Add an opt-in wasm feature to the flagd crate that:
- Gates all async/networking dependencies (
tokiort/net,tonic,reqwest,notify) behind atokiofeature flag - Introduces a lightweight
WasmEvaluationContextas a WASM-compatible replacement foropen_feature::EvaluationContext - Adds a
SimpleFlagStorefor synchronous flag evaluation against static/bundled configuration, with no async runtime or networking required
Default behavior is unchanged — existing consumers continue to work without modification.
Required Changes (crates/flagd/)
- Add
wasmfeature toCargo.toml; gate all async/networking deps behind atokiofeature flag - Gate
FlagdProvider,FlagdOptions,ResolverType, and all tokio-dependent code behind#[cfg(feature = "tokio")] - Add
WasmEvaluationContext— a lightweight evaluation context usable without the full OpenFeature SDK - Add
SimpleFlagStore— synchronous flag loading and evaluation for static/bundled configurations - Update targeting resolution to use
WasmEvaluationContextwhen building withwasmfeature - Add compatibility tests confirming correct evaluation under
wasmfeature (targeting rules, fractional, semver, string operators)
Reference
A working prototype lives at DevCycleHQ-Sandbox/rust-sdk-contrib on branch feat/wasm-support, validated end-to-end in a Cloudflare Worker exposing the OFREP API.