| Crates.io | wasmrust |
| lib.rs | wasmrust |
| version | 0.3.1 |
| created_at | 2025-07-02 00:08:39.364614+00 |
| updated_at | 2025-08-27 14:49:57.188406+00 |
| description | Rust WebAssembly plugin for Wasmrun - compile Rust projects to WebAssembly with wasm-bindgen support |
| homepage | https://github.com/anistark/wasmrust |
| repository | https://github.com/anistark/wasmrust |
| max_upload_size | |
| id | 1734248 |
| size | 128,593 |
Rust to WebAssembly compiler plugin for Wasmrun. Compile and run Rust projects to WebAssembly to run easily on any wasm based ecosystem.
# Install wasmrun first
cargo install wasmrun
# Install the wasmrust plugin
wasmrun plugin install wasmrust
# Verify installation
wasmrun plugin info wasmrust
# Install as standalone CLI tool
cargo install wasmrust --features cli
# Verify standalone installation
wasmrust info
[dependencies]
wasmrust = "0.2.1"
# For wasmrun plugin development
wasmrust = { version = "0.2.1", features = ["wasmrun-integration"] }
# For CLI usage
wasmrust = { version = "0.2.1", features = ["cli"] }
Wasmrun automatically detects Rust projects and uses the wasmrust plugin:
# Automatic project detection and compilation
wasmrun ./my-rust-project
# Web application with live reload
wasmrun ./my-yew-app --watch
# Compile with specific optimization
wasmrun compile ./my-project --optimization size
# Force Rust plugin usage (mixed projects)
wasmrun ./mixed-project --language rust
# Plugin management
wasmrun plugin info wasmrust
wasmrun plugin list
For development, testing, or environments without wasmrun:
# Compile project to WebAssembly
wasmrust compile --project ./my-project --output ./dist
# Run project for execution (AOT compilation)
wasmrust run ./my-project
# Inspect project structure and dependencies
wasmrust inspect ./my-project
# Check if project is supported
wasmrust can-handle ./my-project
# Check system dependencies
wasmrust check-deps
# Clean build artifacts
wasmrust clean ./my-project
# Show supported frameworks
wasmrust frameworks
use wasmrust::{WasmRustPlugin, CompileConfig, OptimizationLevel, TargetType};
let plugin = WasmRustPlugin::new();
// Check if project is supported
if plugin.can_handle("./my-project") {
let config = CompileConfig {
project_path: "./my-project".to_string(),
output_dir: "./dist".to_string(),
optimization: OptimizationLevel::Release,
target_type: TargetType::WebApp,
verbose: true,
};
match plugin.compile(&config) {
Ok(result) => {
println!("WASM: {}", result.wasm_path);
if let Some(js_path) = result.js_path {
println!("JS: {}", js_path);
}
}
Err(e) => eprintln!("Compilation failed: {}", e),
}
}
| 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 |
| 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 |
[package]
name = "my-wasm-lib"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[package]
name = "my-bindgen-project"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2"
web-sys = "0.3"
[package]
name = "my-yew-app"
version = "0.1.0"
edition = "2021"
[dependencies]
yew = "0.21"
wasm-bindgen = "0.2"
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
| 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 |
# Cargo.toml optimization for smallest WASM
[profile.release]
opt-level = "s" # Optimize for size
lto = true # Link-time optimization
codegen-units = 1 # Slower compile, smaller binary
panic = "abort" # Smaller binary
strip = "symbols" # Remove debug symbols
[profile.release.package."*"]
opt-level = "s"
# Web-specific optimizations
[dependencies]
console_error_panic_hook = "0.1"
wee_alloc = "0.4"
wasmrust inspect ./my-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!
rustup, cargo, rustcwasm32-unknown-unknown# Install Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Add WebAssembly target
rustup target add wasm32-unknown-unknown
# Install additional tools
cargo install wasm-pack trunk wasm-opt
# Verify installation
wasmrust check-deps
WasmRust automatically monitors:
src/**/*.rs - Source filesCargo.toml - Dependencies and configurationTrunk.toml - Trunk configurationassets/, static/, public/ - Static assetsstyle.css, index.html - Web assets# Start development server with live reload
wasmrun ./my-project --watch
Create wasmrun.toml in your project root:
[project]
language = "rust"
[build]
optimization = "release"
target_type = "webapp"
output_dir = "./dist"
[rust]
build_strategy = "trunk" # cargo, wasm-pack, trunk
wasm_pack_target = "web" # web, bundler, nodejs
enable_optimization = true
custom_flags = ["--features", "web"]
Configure in ~/.wasmrun/config.toml:
[external_plugins.wasmrust]
enabled = true
auto_update = true
install_path = "/home/user/.wasmrun/plugins/wasmrust"
[external_plugins.wasmrust.defaults]
optimization = "size"
verbose = false
build_strategy = "auto"
# Enable verbose compilation
export WASMRUST_VERBOSE=1
# Custom optimization flags
export RUSTFLAGS="-C target-feature=+simd128"
# Force build strategy
export WASMRUST_BUILD_STRATEGY=trunk
WasmRust implements the full Wasmrun plugin architecture:
// Plugin trait implementation
impl Plugin for WasmrustPlugin {
fn info(&self) -> &PluginInfo;
fn can_handle_project(&self, project_path: &str) -> bool;
fn get_builder(&self) -> Box<dyn WasmBuilder>;
}
// Builder trait implementation
impl WasmBuilder for WasmrustBuilder {
fn build(&self, config: &BuildConfig) -> CompilationResult<BuildResult>;
fn check_dependencies(&self) -> Vec<String>;
fn validate_project(&self, project_path: &str) -> CompilationResult<()>;
fn clean(&self, project_path: &str) -> Result<()>;
// ... additional methods
}
WasmRust supports both library integration and dynamic loading:
// C interface for dynamic loading
extern "C" {
fn wasmrun_plugin_create() -> *mut c_void;
fn wasmrust_can_handle_project(builder: *const c_void, path: *const c_char) -> bool;
fn wasmrust_build(builder: *const c_void, config: *const BuildConfigC) -> *mut BuildResultC;
// ... additional C functions
}
// Rust integration
use wasmrust::create_plugin;
let plugin = create_plugin(); // Returns Box<dyn Plugin>
// C integration
extern "C" fn wasmrun_plugin_create() -> *mut c_void;
"Plugin not found"
# Verify plugin installation
wasmrun plugin list
wasmrun plugin info wasmrust
# Reinstall if needed
wasmrun plugin install wasmrust
"wasm32-unknown-unknown target not found"
rustup target add wasm32-unknown-unknown
"wasm-pack not found" (for wasm-bindgen projects)
cargo install wasm-pack
"trunk not found" (for web applications)
cargo install trunk
"Compilation timeout"
# Increase timeout for large projects
wasmrun compile ./large-project --timeout 300
# Use incremental compilation
export CARGO_INCREMENTAL=1
# Run all tests
cargo test
# Test wasmrun integration
cargo test --features wasmrun-integration
# Test CLI functionality
cargo test --features cli
# Integration tests (requires Rust toolchain)
cargo test test_actual_compilation -- --ignored
TBD
git checkout -b feature/amazing-featurecargo test --all-featuresdetect_project_type_and_frameworks()determine_build_strategy()| Project Type | Debug | Release | Size |
|---|---|---|---|
| Simple WASM | ~5s | ~15s | ~25s |
| wasm-bindgen | ~10s | ~30s | ~45s |
| Yew App | ~15s | ~45s | ~60s |
| 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
MIT License - see the LICENSE file for details.
We welcome contributions! See CONTRIBUTING.md for:
Made with โค๏ธ for the Rust and WebAssembly communities
โญ If you find WasmRust useful, please consider starring the repository!