Showing posts with label Xubuntu. Show all posts
Showing posts with label Xubuntu. Show all posts

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

Wednesday, May 07, 2025

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04

I am planning to run qemu-system-ppc to play around QEMU and PPC with networking support. The quest and U-Boot will need to interact with external services, namely, tftp. The recommended network is to have TUN/TAP virtual network interface configured on the host. My host is Xubuntu 24.04/Ubuntu 24.04.

Let's start by creating tap0 using systemd
u1@m18:~$ sudo nvim /etc/systemd/system/tap0.service
Copy/paste content below Change u1 to the user who needs access to tap0

Run command below to create tap0. This should also presist after reboot
u1@m18:~$ sudo systemctl daemon-reexec
u1@m18:~$ sudo systemctl enable --now tap0.service
Create a backup of existing netplan configuration
u1@m18:~$ mkdir ~/backup
u1@m18:~$ cd /etc/netplan
u1@m18:~$ sudo mv * ~/backup
Create new netplan configuration, let us call it 01-netcfg.yaml
u1@m18:~$ sudo touch /etc/netplan01-netcfg.yaml
u1@m18:~$ sudo chmod 600 /etc/netplan/01-netcfg.yaml
u1@m18:~$ sudo nvim /etc/netplan/01-netcfg.yaml
Copy/paste gist below into 01-netcfg.yaml. Note that ens33 is my interface name, so update that as appropriate.

Now disable Network Manager and enable networkd. The command below will reconfure your network, so you need to be on the console and not via ssh.
u1@m18:~$ sudo systemctl stop NetworkManager.service
u1@m18:~$ sudo systemctl disable NetworkManager.service
u1@m18:~$ sudo systemctl start systemd-networkd.service
u1@m18:~$ sudo systemctl enable systemd-networkd.service
Now apply netplan configuration
u1@m18:~$ sudo netplan apply
Running QEMU below and issuing dhcp at U-boot prompt should allow the guest to get IP address from DHCP server. Of course, I am assuming that there is DHCP server in the network.
u1@m18:~$ qemu-system-ppc -M mpc8544ds -cpu mpc8540 -m 512 -nographic -netdev tap,id=net0,ifname=tap0,script=no,downscript=no -device e1000,netdev=net0 -serial mon:stdio

CPP Quick Guide

Basics Hello world User input While loop If statement For loop Switch statement Read file using ifstream Write to a file using ofstr...