Skip to content

Latest commit

 

History

History
33 lines (27 loc) · 1.02 KB

README.md

File metadata and controls

33 lines (27 loc) · 1.02 KB

Running Rust in the browser

This guide will show you how to run Rust in the browser and in Node.js using WebAssembly. We will cover 3 main approaches:

  1. from scratch
  2. with wasm-bindgen
  3. with WebAssembly Components

Then we will also explore options for posix emulation:

  1. with emscripten
  2. with WASI preview 2

Setup

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