webassembly-rs
A Rust library providing complete WebAssembly opcode constants, parsing, and encoding.
100% Spec Test Coverage: This library successfully parses all 4,441+ valid WebAssembly test cases from the official WebAssembly spec test suite.
Features
- ✅ Complete opcode coverage - All 300+ WebAssembly opcodes (Core Spec 3.0)
- ✅ Full parser and encoder - Parse
.wasmfiles and encode back to bytes - ✅ 100% spec test validation - Verified against 5,444 official spec tests
- ✅ Round-trip verified - parse → encode → parse produces valid wasm
- ✅
#![no_std]compatible - Works in embedded environments - ✅ Zero dependencies - Only requires
alloc
Usage
Add to your Cargo.toml:
[]
= "0.9"
Quick Start
use ;
// Parse a WebAssembly binary
let wasm_bytes = read.expect;
let program = parse.expect;
// Access parsed sections
for section in &program.sections
// Encode back to WebAssembly binary
let encoded = encode;
write.expect;
Testing
The library is validated against the complete official WebAssembly spec test suite (5,444 tests):
# Run unit tests (LEB128, section parsing, round-trips)
# Run spec test suite (5,444 WebAssembly binaries)
# Or use make
Test Results
| Test Category | Count | Status |
|---|---|---|
| Unit tests | 15 | ✅ Passing |
| Spec parsing tests | 4,841 | ✅ Passing (100% of valid wasm) |
| Round-trip tests | 4,821 | ✅ Passing (100%) |
| Malformed tests | 608 | ✅ Correctly rejected |
Spec Test Coverage
This library achieves 100% coverage of valid WebAssembly from the official spec:
- All 4,441 valid WebAssembly test binaries parse successfully
- All 608
assert_malformedtests are correctly rejected - Full round-trip validation (parse → encode → re-parse)
API Overview
Core Types
Program- A parsed WebAssembly module containing sectionsSection- WebAssembly sections (Type, Import, Function, Memory, Export, Code, Data, etc.)Instruction- All WebAssembly opcodes with their operandsValType- Value types (I32, I64, F32, F64, etc.)
Opcode Constants
Complete opcode constants matching the WebAssembly spec:
use *;
// Control flow
assert_eq!;
assert_eq!;
assert_eq!;
// Memory
assert_eq!;
assert_eq!;
// SIMD (300+ SIMD opcodes included)
assert_eq!; // Prefixed opcodes
LEB128 Encoding
Utilities for WebAssembly's variable-length integer encoding:
use leb;
let encoded = encode_u32;
let = decode_u32.unwrap;
Features
#![no_std] Support
This library works without the standard library:
extern crate alloc;
use ;
Spec Test Validation
The library includes comprehensive integration tests that parse the official WebAssembly spec test suite. To run:
# Requires spec tests submodule
Related Projects
- watson - A more featureful WebAssembly library for Rust
- WebAssembly Spec - Official WebAssembly specification
License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in webassembly by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.