๐ฆ WasmRust
Rust to WebAssembly compiler plugin for Wasmrun. Compile and run Rust projects to WebAssembly to run easily on any wasm based ecosystem.
๐ฆ Installation
Primary Installation (Wasmrun Plugin)
# Install wasmrun first
# Install the wasmrust plugin
# Verify installation
Standalone Installation (Development/Testing)
# Install as standalone CLI tool
# Verify standalone installation
Library Integration
[]
= "0.2.1"
# For wasmrun plugin development
= { = "0.2.1", = ["wasmrun-integration"] }
# For CLI usage
= { = "0.2.1", = ["cli"] }
๐ ๏ธ Usage
Primary Usage (via Wasmrun) - Recommended
Wasmrun automatically detects Rust projects and uses the wasmrust plugin:
# Automatic project detection and compilation
# Web application with live reload
# Compile with specific optimization
# Force Rust plugin usage (mixed projects)
# Plugin management
Standalone Usage (Development/Testing)
For development, testing, or environments without wasmrun:
# Compile project to WebAssembly
# Run project for execution (AOT compilation)
# Inspect project structure and dependencies
# Check if project is supported
# Check system dependencies
# Clean build artifacts
# Show supported frameworks
Library Usage
use ;
let plugin = new;
// Check if project is supported
if plugin.can_handle
๐ฏ Supported Project Types & Frameworks
Project Types (Auto-detected)
Type | Description | Output | Build Tool |
---|---|---|---|
Standard WASM | Basic Rust โ WebAssembly | .wasm file |
cargo |
wasm-bindgen | JavaScript integration | .wasm + .js |
wasm-pack |
Web Application | Full-stack web apps | Complete bundle | trunk / wasm-pack |
Supported Web Frameworks
Framework | Auto-Detection | Build Strategy | Status |
---|---|---|---|
Yew | yew dependency |
trunk โ wasm-pack | โ Full Support |
Leptos | leptos dependency |
trunk โ wasm-pack | โ Full Support |
Dioxus | dioxus dependency |
wasm-pack | โ Full Support |
Sycamore | sycamore dependency |
wasm-pack | โ Full Support |
Trunk | Trunk.toml present |
trunk | โ Full Support |
Framework Examples
Standard Rust WASM
[]
= "my-wasm-lib"
= "0.1.0"
= "2021"
[]
= ["cdylib"]
wasm-bindgen Project
[]
= "my-bindgen-project"
= "0.1.0"
= "2021"
[]
= ["cdylib"]
[]
= "0.2"
= "0.3"
Yew Web Application
[]
= "my-yew-app"
= "0.1.0"
= "2021"
[]
= "0.21"
= "0.2"
๐ง Build Strategies & Optimization
Build Strategy Selection
WasmRust intelligently selects the optimal build strategy:
Project Analysis
โ
Framework Detection (Yew, Leptos, etc.)
โ
Build Tool Selection:
โข Standard WASM โ cargo build
โข wasm-bindgen โ wasm-pack
โข Web Apps โ trunk (preferred) โ wasm-pack (fallback)
โ
Optimization Application
โ
Output Generation
Optimization Levels
Level | Compilation Time | File Size | Performance | Use Case |
---|---|---|---|---|
debug | Fast โก | Large ๐ฆ | Basic โญ | Development, debugging |
release | Moderate โฑ๏ธ | Medium ๐ฆ | Good โญโญโญ | Production builds |
size | Slow ๐ | Minimal ๐ฆ | Good โญโญโญ | Bandwidth-constrained |
Advanced Optimization
# Cargo.toml optimization for smallest WASM
[]
= "s" # Optimize for size
= true # Link-time optimization
= 1 # Slower compile, smaller binary
= "abort" # Smaller binary
= "symbols" # Remove debug symbols
[]
= "s"
# Web-specific optimizations
[]
= "0.1"
= "0.4"
๐ Project Analysis & Dependencies
Inspect Your Project
Example Output:
๐ Analyzing Rust project...
๐ Project Analysis
โโโโโโโโโโโโโโโโโโโ
๐ Name: my-yew-app
๐ท๏ธ Version: 0.1.0
๐ฏ Type: Web Application
๐ง Build Strategy: trunk + wasm-pack
๐ Frameworks: yew, trunk
๐ Dependencies
โโโโโโโโโโโโโโโ
Required:
โ
cargo - Rust build tool
โ
rustc - Rust compiler
โ
wasm32-unknown-unknown - WebAssembly compilation target
โ
trunk - Required for web application builds
Optional:
โ
rustup - Rust toolchain manager
โ ๏ธ wasm-opt - WebAssembly optimizer
๐ Project is ready to build!
System Dependencies
Required Tools
- Rust Toolchain:
rustup
,cargo
,rustc
- WASM Target:
wasm32-unknown-unknown
Optional Tools (Auto-detected)
- wasm-pack: For wasm-bindgen projects
- trunk: For web applications
- wasm-opt: For additional optimization
Quick Installation
# Install Rust toolchain
|
# Add WebAssembly target
# Install additional tools
# Verify installation
๐ Live Development & Watch Mode
File Watching (via Wasmrun)
WasmRust automatically monitors:
src/**/*.rs
- Source filesCargo.toml
- Dependencies and configurationTrunk.toml
- Trunk configurationassets/
,static/
,public/
- Static assetsstyle.css
,index.html
- Web assets
Development Workflow
# Start development server with live reload
โ๏ธ Configuration
Project Configuration
Create wasmrun.toml
in your project root:
[]
= "rust"
[]
= "release"
= "webapp"
= "./dist"
[]
= "trunk" # cargo, wasm-pack, trunk
= "web" # web, bundler, nodejs
= true
= ["--features", "web"]
Global Plugin Configuration
Configure in ~/.wasmrun/config.toml
:
[]
= true
= true
= "/home/user/.wasmrun/plugins/wasmrust"
[]
= "size"
= false
= "auto"
Environment Variables
# Enable verbose compilation
# Custom optimization flags
# Force build strategy
๐ง Plugin Architecture & Integration
Wasmrun Plugin Interface
WasmRust implements the full Wasmrun plugin architecture:
// Plugin trait implementation
// Builder trait implementation
Dynamic Loading Support
WasmRust supports both library integration and dynamic loading:
// C interface for dynamic loading
extern "C"
Plugin Registration
// Rust integration
use create_plugin;
let plugin = create_plugin; // Returns Box<dyn Plugin>
// C integration
extern "C" ;
๐ Troubleshooting
Common Issues
"Plugin not found"
# Verify plugin installation
# Reinstall if needed
"wasm32-unknown-unknown target not found"
"wasm-pack not found" (for wasm-bindgen projects)
"trunk not found" (for web applications)
"Compilation timeout"
# Increase timeout for large projects
# Use incremental compilation
๐งช Testing & Development
Running Tests
# Run all tests
# Test wasmrun integration
# Test CLI functionality
# Integration tests (requires Rust toolchain)
Development Setup
TBD
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes with tests
- Run the test suite:
cargo test --all-features
- Update documentation if needed
- Submit a pull request
Adding Framework Support
- Update detection logic in
detect_project_type_and_frameworks()
- Add build strategy in
determine_build_strategy()
- Implement compilation in framework-specific methods
- Add tests and update documentation
- Update README with framework details
๐ Benchmarks & Performance
Compilation Speed
Project Type | Debug | Release | Size |
---|---|---|---|
Simple WASM | ~5s | ~15s | ~25s |
wasm-bindgen | ~10s | ~30s | ~45s |
Yew App | ~15s | ~45s | ~60s |
Output Size Comparison
Optimization | Simple WASM | wasm-bindgen | Yew App |
---|---|---|---|
debug | ~500KB | ~800KB | ~1.2MB |
release | ~200KB | ~400KB | ~600KB |
size | ~100KB | ~250KB | ~400KB |
Benchmarks on Apple M1, Rust 1.70, realistic projects
๐ Related Projects & Ecosystem
Core Dependencies
- wasm-bindgen - JavaScript integration
- wasm-pack - WebAssembly toolkit
- trunk - Web application bundler
Web Frameworks
- Yew - Modern Rust web framework
- Leptos - Full-stack Rust framework
- Dioxus - Cross-platform GUI library
- Sycamore - Reactive web library
Related Tools
- Wasmrun - Universal WebAssembly runtime
- WasmGo - Go WebAssembly plugin
- binaryen - WebAssembly optimizer
๐ License
MIT License - see the LICENSE file for details.
๐ค Contributing & Community
Getting Help
- GitHub Issues: Report bugs or request features
- Discussions: Community discussions
- Wasmrun Discord: Join the community
Contributing
We welcome contributions! See CONTRIBUTING.md for:
- Code contribution guidelines
- Development setup instructions
- Testing requirements
- Documentation standards
Made with โค๏ธ for the Rust and WebAssembly communities
โญ If you find WasmRust useful, please consider starring the repository!