WasmRust
WebAssembly plugin for Wasmrun.
Compile and run Rust projects to WebAssembly to run easily on any wasm based ecosystem.
Installation
Standalone Installation (For testing only for now)
# For development and standalone usage
🚀 Usage
Primary Usage (via Wasmrun)
# Wasmrun automatically detects Rust projects and uses wasmrust plugin
# Run Rust project (auto-detection)
# Compile with optimization
# Force Rust plugin usage
# Plugin-specific commands
Standalone Usage (CLI Mode)
# Direct wasmrust usage (when installed with --features cli)
🔍 Project Detection & Support
WasmRust automatically detects and optimizes compilation for:
Project Types
- Standard WASM: Basic Rust → WebAssembly compilation
- wasm-bindgen: JavaScript bindings with web-sys/js-sys integration
- Web Applications: Full-stack web apps with framework support
Supported Frameworks
- Yew: Modern Rust framework for creating multi-threaded frontend web apps
- Leptos: Full-stack, compile-time optimal Rust framework
- Dioxus: Cross-platform GUI library for desktop, web, mobile
- Sycamore: Reactive library for creating web apps
- Trunk: Build tool for Rust-generated WebAssembly web applications
Build Strategies
- Cargo: Standard WASM compilation with
wasm32-unknown-unknown
target - wasm-pack: Optimized builds for wasm-bindgen projects with JS integration
- Trunk: Complete web application builds with assets and bundling
Examples
1. Simple Rust WASM
// examples/simple-rust/src/lib.rs
pub extern "C"
2. Web with wasm-bindgen
// examples/simple-web/src/lib.rs
use *;
3. Yew Web Application
// examples/complex-yew/src/main.rs
use *;
Development
Dev Installation (for dev testing and developement)
# Development build (fast compilation)
# Production build (balanced)
# Size-optimized build (smallest output)
Advanced Configuration
# Verbose output for debugging
# Custom output directory
# Web application mode with live reload
🔧 Dependencies
Required
- cargo - Rust build tool and package manager
- rustc - Rust compiler
- wasm32-unknown-unknown - WebAssembly compilation target
# Install target if missing
Optional (Auto-detected)
- wasm-pack - Required for wasm-bindgen projects
- trunk - Required for web applications
- wasm-opt - WebAssembly optimizer (recommended)
Dependency Checking
# Check your environment
# Or with standalone CLI
🔄 Plugin Integration Details
How It Works
- Project Detection: Wasmrun scans for
Cargo.toml
and.rs
files - Plugin Loading: WasmRust loads via dynamic library or binary execution
- Framework Analysis: Automatic detection of web frameworks and build tools
- Optimized Compilation: Framework-specific build strategies
- Asset Generation: WASM + JS + HTML output as needed
Compatibility
- Unix/Linux/macOS: Dynamic loading preferred
- Windows: Binary fallback mode
- All platforms: Graceful degradation ensures functionality
🔍 Troubleshooting
Common Issues
"Plugin not found":
# Verify installation
# Reinstall if needed
"wasm32-unknown-unknown target not found":
"wasm-pack not found" (for wasm-bindgen projects):
"trunk not found" (for web applications):
Debug Mode
# Enable verbose output
# Check dependencies
# Test plugin loading
WASMRUN_VERBOSE=1
Development Setup
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests and documentation
- Submit a pull request
📄 License
MIT License - see the LICENSE file for details.
🔗 Related Projects
- Wasmrun - Universal WebAssembly runtime and plugin system
- WasmGo - Go WebAssembly plugin for Wasmrun
- wasm-bindgen - Facilitating high-level interactions between Wasm modules and JavaScript
- Trunk - Build tool for Rust-generated WebAssembly
Made with ❤️ for the Rust and WebAssembly communities
⭐ If you find WasmRust useful, please consider starring the repository!