Thursday, December 25, 2025

Rust and WebAssembly quick start guide 2025

Rust and WebAssembly quick start guide 2025

As of December 2025, Rust and WebAssembly is reorganizing. Documentation is currently out of date and not working. This is my notes on getting started using Rust WebAssembly. Most of the documentation still works - below is distilled version.

Install Rust toolchain
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Below shows my Rust toolchain versions
q@x1m9:~/tmp$ cargo --version
cargo 1.92.0 (344c4567c 2025-10-21)
q@x1m9:~/tmp$ rustc --version
rustc 1.92.0 (ded5c06cf 2025-12-08)


Install wasm-pack - your one-stop shop for building, testing, and publishing Rust-generated WebAssembly.
$ sudo apt install build-essential
$ cargo install wasm-pack
wasm-pack version
q@x1m9:~/tmp$ wasm-pack --version
wasm-pack 0.13.1


Install cargo-generate - helps you get up and running quickly with a new Rust project by leveraging a pre-existing git repository as a template.
$ sudo apt install libssl-dev
$ sudo apt install pkg-config
$ cargo install cargo-generate
cargo-generate version
q@x1m9:~/tmp$ cargo-generate --version
cargo generate 0.23.7


Install npm

Install node version manager - nvm
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
nvm version
q@x1m9:~/tmp$ nvm --version
0.40.3


Now install latest version of node
$ nvm install node
node version
q@x1m9:~/tmp$ node --version
v25.2.1


Clone project template
$ cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name wasm-game-of-life
$ cd wasm-game-of-life


Build the project
$ wasm-pack build


Putting it into a webpage, run in project root
$ sudo apt install git
$ npm init wasm-app www


Install dependencies
$ cd ~/p/wasm-game-of-life/www
$ npm install


Edit ~/p/wasm-game-of-life/www/package.json
$ nvim ~/p/wasm-game-of-life/www/package.json 


Add wasm-game-of-life to dependencies section of package.json and also note that devDependencies is updated.
{
  "name": "create-wasm-app",
  "version": "0.1.0",
  "description": "create an app to consume rust-generated wasm packages",
  "main": "index.js",
  "bin": {
    "create-wasm-app": ".bin/create-wasm-app.js"
  },
  "scripts": {
    "build": "webpack --config webpack.config.js",
    "start": "webpack-dev-server"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/rustwasm/create-wasm-app.git"
  },
  "keywords": [
    "webassembly",
    "wasm",
    "rust",
    "webpack"
  ],
  "author": "Ashley Williams ",
  "license": "(MIT OR Apache-2.0)",
  "bugs": {
    "url": "https://github.com/rustwasm/create-wasm-app/issues"
  },
  "homepage": "https://github.com/rustwasm/create-wasm-app#readme",
  "devDependencies": {
    "webpack": "^5.0.0",
    "webpack-cli": "^5.0.0",
    "webpack-dev-server": "^4.0.0",
    "copy-webpack-plugin": "^11.0.0",
    "hello-wasm-pack": "^0.1.0"
  },
  "dependencies": {
    "wasm-game-of-life": "file:../pkg"
  }
}


Edit ~/p/wasm-game-of-life/www/index.js
$ nvim ~/p/wasm-game-of-life/www/index.js


Add wasm-game-of-life package to index.js
import * as wasm from "wasm-game-of-life";

wasm.greet();


Install wasm-game-of-life package and force clean as we have upgraded devDependencies
$ cd ~/p/wasm-game-of-life/www
$ rm -rf node_modules package-lock.json
$ npm install


Fix ~/p/wasm-game-of-life/www/webpack.config.js
$ nvim ~/p/wasm-game-of-life/www/webpack.config.js


Observe we have changed CopyWebpackPlugin and added asyncWebAssembly
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require('path');

module.exports = {
  entry: "./bootstrap.js",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "bootstrap.js",
  },
  mode: "development",
  plugins: [
    new CopyWebpackPlugin({
      patterns: [
        { from: "index.html" },
      ],
    })
  ],
  experiments: {
    asyncWebAssembly: true,
  },
};


Now run it
$ npm run start


Open http://localhost:8080

No comments:

Fedora install screen chronicle

Fedora install screen chronicle Below are links to Fedora installation screens. It is interesting to see how it has evolved over time. Fed...