CLOUDFLARE has announced an experimental preview adding first-class support for Rust’s `wasm32-unknown-emscripten` target in the `wasm-bindgen` toolchain and Cloudflare Workers. The work, developed with Google and other project maintainers, allows Rust applications using Emscripten to run on the web, Node.js and Workers. Emscripten virtualises native features such as timers, file systems and sockets; on Workers, these are mapped to existing Node.js-compatible APIs. Cloudflare says testing showed improved library compatibility, although the feature remains pre-release.
The support required changes to `wasm-bindgen`, Emscripten and Rust libraries including `libc`, `socket2` and `Mio`, as well as substantial work on Tokio. Because Workers runs on a single JavaScript event loop, Tokio cannot use its normal blocking thread and `epoll_wait()` model.
Cloudflare has developed two experimental approaches: WebAssembly JavaScript Promise Integration (JSPI), which suspends execution while waiting, and a proposed `LocalEventLoop` design that lets the host drive batches of ready tasks without blocking. More than 40 Emscripten pull requests added the `-sNODERAWSOCKETS` option, enabling epoll, TCP, UDP and Unix sockets through Node.js APIs, including on Workers.
As a demonstration, Cloudflare engineers ran the Rust-based Pumpkin Minecraft server inside a Durable Object. Its threaded workloads were converted into cooperative Tokio tasks, files were stored in Durable Object SQLite storage, and player connections used Workers TCP ingress. Cloudflare has published experimental patchsets and example applications for developers to test.