Cloudflare has announced an experimental public preview that adds first-class support for the wasm32-unknown-emscripten Rust compiler target to the wasm-bindgen toolchain and Cloudflare Workers. The integration is designed to let more native Rust applications run inside Workers’ JavaScript-hosted environment, including programs built around the Tokio asynchronous runtime.
A shared toolchain path
The work allows Emscripten to continue handling builds, WebAssembly loading and its JavaScript support while wasm-bindgen supplies a portable Rust-to-JavaScript bindings layer. The two toolchains can now interoperate through the -sWASM_BINDGEN configuration, supporting both Rust applications driven by Rust’s compiler and C++ Emscripten projects that link static Rust code.
Cloudflare says the target improves compatibility with a range of Rust libraries. Some low-level projects, including libc, socket2 and Mio, needed platform-gate changes for Emscripten, while other libraries worked without modification.
Tokio meets the Workers event loop
Tokio presented the main integration challenge. Native Tokio runtimes normally wait by parking a thread, but Workers run on a single thread inside a JavaScript event loop where blocking would stop the host. Cloudflare’s patchsets address this through WebAssembly JavaScript Promise Integration and a proposed LocalEventLoop runtime that returns control to the host and asks it to drive ready tasks in batches.
The LocalEventLoop design replaces waiting with host notifications. A wake signals that Tokio should run again, while the host remains responsible for calling drive(). The source notes that block_on cannot perform its usual wait in this mode and instead panics when it would need to park.
Sockets and a demanding test
Cloudflare also contributed Emscripten socket support through the -sNODERAWSOCKETS layer. It connects Emscripten networking to Node.js-compatible APIs, enabling epoll, TCP, UDP and Unix sockets for Emscripten applications in Node.js and Workers. The company says this allowed Tokio’s networking features to work with Workers’ socket APIs.
As a demonstration, engineers ran Pumpkin, a Rust Minecraft server, inside a Durable Object with TCP ingress and persistent world data backed by Durable Object storage. Adapting the server required converting its thread-oriented game and scheduling work into cooperative Tokio tasks for the object’s single-threaded environment.
Still pre-release
The workflows and patchsets are available for experimental use, but the integration is not presented as finished. Tokio support beyond the initial landed target patch remains under review, and the final design for fully reentrant JavaScript Promise Integration is still being developed with the Tokio and Emscripten teams.
AI-generated editorial illustration; not a documentary photograph.
Source: Supporting native Rust in Workers with the new Emscripten target for wasm-bindgen

Leave a Reply