← Writing

Post

Wasm-based Application: Tax Calculator

A Rust and wasm-bindgen experiment: build a WebAssembly tax calculator and serve it from a static page.

5 October 2024 Anatolii Maltsev 1 min read Systems & tooling rust webassembly project

An experiment using wasm-bindgen to create a WebAssembly program. Built with wasm-bindgen 0.2.95.

GitHub Repository

Tools

  • rust 1.83.0
  • wasm_test 0.3
  • CI

How to build and run

  1. Create a library crate:

    cargo new project --lib
  2. Add the crate type annotation for the compiler:

    [lib]
    crate-type = ["cdylib"]
  3. Create a basic index.html skeleton and extend the script block to handle loading and interacting with the wasm module.

  4. Install wasm-pack:

    cargo install wasm-pack
  5. Build the project with wasm-pack:

    wasm-pack build --target web
  6. Install a simple web server globally (if not installed):

    npm install -g http-server
  7. Start the web server from the project root folder:

    http-server .

Browser recording of the WebAssembly tax calculator page, where a USD income is entered into a numeric field and the Calculate Tax button returns the result

License

This project is licensed under the MIT License.