Writing and executing your Rust program as WebAssembly (Wasm) in under 5 minutes.

Timothy McCallum
Wasm
Published in
2 min readNov 13, 2019

This demonstration was performed using both Ubuntu Linux OS and Google’s Chrome Web Browser. Other combinations have not been tested.

Step 1 — Install Apache2 and Rust

Run all of the following Ubuntu system set up commands (update, install Apache2 and Rust)

Step 2 — Create a new Rust project

Create a quick Rust project

Step 3 — Configure Rust for Wasm

Configure rust by adding this config to the lib section of the ~/triple/Cargo.toml file

Step 4 — Specify the build target

Finish configuring Rust by creating a new file at `~/.cargo.config` and adding the following config to it

Step 5 — Write Rust

Write a quick Rust program and save it as triple.rs (in the `~/triple/src` directory)

Step 6 — Build the Wasm code

Build the Rust code into Wasm and then copy the Wasm file to the Apache2 web server area

Step 7 — Use this HTML

Create a new file called triple.html in the var/www/html/ directory and fill it with the following code.

Step 8 — Execute your Rust code via a mouse click

Visit your machine’s IP at the triple HTML page i.e. http://12.345.456.78/triple.html

Then click the “Triple the number” button.

The following alert will be shown.

--

--

Timothy McCallum
Wasm
Editor for

I'm a technical writer and copy editor exploring WebAssembly (Wasm), software automation, and Artificial Intelligence (AI) while mastering Rust, Python, & Bash.