Starter kit for compiling high-performance Rust into WebAssembly — wasm-pack, wasm-bindgen, JavaScript interop, benchmarks, and production-ready build pipeline.
Getting Started · Features · Tech Stack · Benchmarks · Contributing
| Feature | Description |
|---|---|
| 📦 wasm-pack Build Pipeline | One-command compilation from Rust to optimized .wasm binaries with npm package output |
| 🔌 wasm-bindgen JS Interop | Seamless two-way data passing between Rust and JavaScript with auto-generated bindings |
| 🛡️ Memory-safe Computations | Leverage Rust's ownership model for zero-cost abstractions in browser workloads |
| 🌐 Browser & Node.js Support | Target both browser ESM bundles and Node.js CommonJS modules from a single codebase |
| 📊 Performance Benchmarks | Built-in benchmark suite comparing WASM vs. native JS for common compute tasks |
| 🌲 Tree-shaking | Dead code elimination ensures minimal bundle size for production deploys |
| 🗺️ Source Maps | Debug-friendly source maps mapping .wasm back to original Rust source |
| ⚙️ CI/CD | GitHub Actions pipeline for build, test, benchmark, and npm publish |
- Rust >= 1.75 — Install via rustup
- wasm-pack —
cargo install wasm-pack - Node.js >= 18.x (for JS integration and benchmarks)
- npm >= 9.x
# Clone the repository
git clone https://github.com/razinahmed/rust-wasm-toolkit.git
# Navigate to the project
cd rust-wasm-toolkit
# Build the WASM package
wasm-pack build --target web
# Install JS dependencies for the demo app
cd www && npm install
# Start the development server
npm run start# Browser (ESM)
wasm-pack build --target web --release
# Node.js (CommonJS)
wasm-pack build --target nodejs --release
# Bundler (webpack/rollup)
wasm-pack build --target bundler --releaserust-wasm-toolkit/
├── src/
│ ├── lib.rs # Main library entry point
│ ├── math.rs # Math computation modules
│ ├── string_ops.rs # String processing utilities
│ ├── crypto.rs # Hashing and encoding
│ └── utils.rs # Shared helpers and panic hook
├── www/
│ ├── index.html # Demo application
│ ├── index.js # JS integration layer
│ ├── webpack.config.js # Bundler configuration
│ └── package.json
├── benches/
│ ├── wasm_bench.rs # Rust-side benchmarks
│ └── js_bench.mjs # JS comparison benchmarks
├── tests/
│ ├── web.rs # WASM integration tests
│ └── node_tests.mjs # Node.js integration tests
├── Cargo.toml
├── .github/
│ └── workflows/
│ └── ci.yml
└── README.md
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn fibonacci(n: u32) -> u64 {
match n {
0 => 0,
1 => 1,
_ => {
let (mut a, mut b) = (0u64, 1u64);
for _ in 2..=n {
let temp = b;
b = a + b;
a = temp;
}
b
}
}
}import init, { fibonacci } from './pkg/rust_wasm_toolkit.js';
async function main() {
await init();
const result = fibonacci(50);
console.log(`Fibonacci(50) = ${result}`); // Computed in ~nanoseconds
}
main();| Operation | JavaScript | WASM (Rust) | Speedup |
|---|---|---|---|
| Fibonacci(40) | 820ms | 12ms | ~68x |
| SHA-256 (1MB) | 145ms | 18ms | ~8x |
| Matrix Multiply (512x512) | 1,200ms | 85ms | ~14x |
Run benchmarks locally:
npm run bench
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch —
git checkout -b feature/new-module - Commit your changes —
git commit -m "feat: add new computation module" - Push to the branch —
git push origin feature/new-module - Open a Pull Request
Please ensure all tests pass with wasm-pack test --headless --firefox before submitting.
This project is licensed under the MIT License. See the LICENSE file for details.
Built with ❤️ by Razin Ahmed
Rust WebAssembly WASM wasm-pack High Performance Browser Rust to JS