Dev News Daily ENDE

Cloudflare previews native Rust and Tokio on Workers via an Emscripten target

Cloudflare has published the first public experimental preview of support for the Emscripten compiler target, wasm32-unknown-emscripten, in wasm-bindgen, the open-source toolchain behind Rust WebAssembly applications on its V8-based Workers runtime, and in Cloudflare's Rust Workers. The company says the aim is to run more native Rust code, including applications built on the Tokio async runtime, without rewriting it for the browser-style target Workers has used so far.

The work started at Google more than a year ago, where a team wanted wasm-bindgen to drive a build and produce the JavaScript glue while Emscripten's linker pulled in C++ dependencies. Cloudflare engineers who maintain wasm-bindgen reviewed and extended it. Because Workers supports Web Platform APIs and Node.js compatibility, Emscripten can run there with its Node.js compilation flags, virtualising timers, file system operations and sockets on top of the existing Node.js APIs.

To show the effect, Cloudflare says it ran Pumpkin, a Minecraft server written in Rust, inside a Durable Object with TCP ingress and real TCP sockets through Tokio. The patchsets and example applications are available to try, and the feature remains pre-release.

Cloudflare previews native Rust and Tokio on Workers via an Emscripten target
Cloudflare previews native Rust and Tokio on Workers via an Emscripten target — Dev News Daily

What it means

The limiting factor for Rust on Workers has been library compatibility: crates that assume threads, sockets or a file system did not compile to the plain WebAssembly target. An Emscripten target shifts that burden from the application to a virtualisation layer. It is a preview, so the questions to test are cold-start size and behaviour under load, not whether a demo runs.