* deps: update dependencies, wasm-bindgen and ts-gen to latest main Moves the wasm-bindgen and ts-gen submodules to latest main, patching the workspace wasm-bindgen crates to the submodule while main is ahead of the 0.2.129 release, and refreshes Rust and JS dependencies. * deps: hold emscripten at 6.0.10, patch emscripten examples to the wasm-bindgen submodule * deps: hold ts-gen at its current pin * ci: build templates with the submodule wasm-bindgen CLI * deps: update to wasm-bindgen@0.2.130 |
History
|
|
|---|---|---|
| .. | ||
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| README.md | ||
| rust-toolchain.toml | ||
| wrangler.toml | ||
Emscripten example
Experimental Preview
git clone https://github.com/cloudflare/workers-rs
cd workers-rs/examples/emscripten
npx wrangler dev
A Worker built with worker-build --emscripten for wasm32-unknown-emscripten.
The target brings Emscripten's libc and in-memory filesystem, so std::fs,
std::io and code written around files work unchanged.
This Worker is a word-frequency counter that works the way a command-line tool
would: the POSTed text is written to a file under std::env::temp_dir(), read
back line by line, and the report is written to a second file and returned
along with a directory listing.
npx wrangler dev
curl -X POST --data-binary @README.md http://localhost:8787/
Layout
An emscripten build links a bin target: rustc drives emcc as the linker,
which runs wasm-bindgen as a post-link step. So handlers live in
src/main.rs with an empty fn main() {}, and there is no cdylib.
rust-toolchain.toml selects beta, and the [patch.crates-io] block points
wasm-bindgen at the checkout matching the CLI emcc runs.
What's Next
Take a look at the emscripten-tokio and emscripten-tcp examples for async IO and TCP sockets examples.
See the [README](../../worker-build/README.md#emscripten, or wasm-bindgen Emscripten documentation for the toolchain details.