Skip to content

feat(flagd): add WASM / Cloudflare Workers compatibility mode #103

@jonathannorris

Description

@jonathannorris

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:

  1. Gates all async/networking dependencies (tokio rt/net, tonic, reqwest, notify) behind a tokio feature flag
  2. Introduces a lightweight WasmEvaluationContext as a WASM-compatible replacement for open_feature::EvaluationContext
  3. Adds a SimpleFlagStore for 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 wasm feature to Cargo.toml; gate all async/networking deps behind a tokio feature 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 WasmEvaluationContext when building with wasm feature
  • Add compatibility tests confirming correct evaluation under wasm feature (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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions