Skip to content

Repository files navigation

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

About

A guide on running Rust in the browser

Resources

Stars

9 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages