This guide will show you how to run Rust in the browser and in Node.js using WebAssembly. We will cover 3 main approaches:
Then we will also explore options for posix emulation:
First we need Rust and Deno
curl -sSfL https://sh.rustup.rs | bash
curl -sSfL https://deno.land/install.sh | bash
echo -e '\nexport PATH="~/.deno/bin:$PATH"' >> ~/.bashrc
. ~/.bashrc
We will use two tools, jco
and wasm-bindgen
, and we also need and http server to show the result in a browser
cargo install wasm-bindgen-cli
deno install --global --allow-all --name jco npm:@bytecodealliance/jco
deno install --global --allow-all --name serve jsr:@std/http/file-server
Finally, we need to install the wasm32-unknown-unknown
rust target
rustup target add wasm32-unknown-unknown