MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm

github.com/explodingcamera/tinywasm @v0.9.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.9.1 ↗ · + Follow
1,318 symbols 3,179 edges 118 files 193 documented · 15%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

tinywasm

docs.rs Crates.io Crates.io

Why tinywasm?

  • Tiny: Small by design, without significantly compromising performance or functionality.
  • Portable: Runs anywhere Rust can target, supports no_std, has minimal dependencies, and can itself compile to WebAssembly.
  • Safe: Written in safe Rust, with optional unsafe limited to the simd-x86 feature. Its sandbox is designed to prevent untrusted Wasm from accessing host memory or escaping the runtime.

Installation

[dependencies]
tinywasm = "0.9"

Usage

use tinywasm::{ModuleInstance, Store};

// Load a module from bytes
let wasm = include_bytes!("../examples/wasm/add.wasm");
let module = tinywasm::parse_bytes(wasm)?;

// Create a new store
let mut store = Store::default();

// Instantiate the module
let instance = ModuleInstance::instantiate(&mut store, &module, None)?;

// Call an exported function with typed parameters
let func = instance.func::<(i32, i32), i32>(&mut store, "add")?;
let result = func.call(&mut store, (1, 2))?;

assert_eq!(result, 3);

See the examples directory and documentation for more information.

Cargo Features

  • std\ Enables the use of std and std::io for parsing from files and streams. This is enabled by default.
  • log\ Enables logging using the log crate. This is enabled by default.
  • parser\ Enables the tinywasm-parser crate. This is enabled by default.
  • archive\ Enables serialization/deserialization of compiled modules to the internal twasm bytecode format. This is enabled by default.
  • canonicalize-nans\ Canonicalizes NaN values to a single representation. This is enabled by default.
  • debug\ Derives Debug for runtime types. This is enabled by default.
  • parallel-parser\ Parallelizes function parsing and validation across threads (requires std). This is enabled by default.
  • guest-debug\ Exposes module-internal by-index inspection APIs (*_by_index).
  • simd-x86\ Enables x86-specific SIMD intrinsics for i8x16_swizzle and i8x16_shuffle (uses unsafe code).

With default features disabled, tinywasm depends only on core, alloc, and libm[^libm], making it usable in no_std + alloc environments.

Use Engine and engine::Config when you need non-default runtime settings such as fuel accounting, stack sizing, memory backend selection, or trap-on-OOM behavior.

[^libm]: rust-lang/rust#137578 — tracking issue for floating-point math support in no_std.

Current Status

tinywasm passes the WebAssembly MVP and WebAssembly 2.0 core testsuites. WebAssembly 3.0 support is still in progress, and some newer proposal suites are tracked in-repo as experimental coverage rather than release guarantees; see Supported Proposals for details.

TinyWasm also has its own internal bytecode format, twasm. WebAssembly modules can be compiled to twasm, which stores TinyWasm's validated and optimized instruction representation for faster loading and reuse.

Safety

TinyWasm only uses safe Rust by default. The optional simd-x86 feature enables x86-specific SIMD intrinsics and uses unsafe internally. WebAssembly input is validated by TinyWasm before execution and runs inside a sandbox: untrusted Wasm should not be able to access host memory, escape the sandbox, or cause undefined behavior in the runtime.

The internal twasm bytecode format is not currently validated as an untrusted input format. Malformed twasm may panic, but should not compromise memory safety or allow sandbox escape. Only run trusted twasm bytecode, or generate it through TinyWasm from Wasm input.

Supported Proposals

Proposal Status tinywasm Version
Multi-value 🟢 0.2.0
Mutable Globals 🟢 0.2.0
Non-trapping float-to-int Conversion 🟢 0.2.0
Sign-extension operators 🟢 0.2.0
Bulk Memory Operations 🟢 0.4.0
Reference Types 🟢 0.7.0
Multi-memory 🟢 0.8.0
Custom Page Sizes 🟢 0.9.0
Extended Const 🟢 0.9.0
Fixed-Width SIMD 🟢 0.9.0
Memory64 🟢 0.9.0
Tail Call 🟢 0.9.0
Relaxed SIMD 🟢 0.9.0
Wide Arithmetic 🟢 0.9.0
Exception Handling 🌑 -
Typed Function References 🌑 -
Garbage Collection 🌑 -
Stack Switching 🌑 -
Threads 🌑 -

Legend\ 🌑 -- not available\ 🚧 -- in development/partially supported\ 🟢 -- fully supported

See Also

If you need a more mature, production-tested, or performance-focused WebAssembly runtime today, consider one of these projects:

  • wasmi - efficient and versatile WebAssembly interpreter for embedded systems
  • wasm3 - a fast WebAssembly interpreter written in C
  • wazero - a zero-dependency WebAssembly interpreter written in Go

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in tinywasm by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

LinearMemory (Interface)
Backend storage for a linear memory This is a low-level trait that abstracts over the actual storage mechanism for line [3 …
crates/tinywasm/src/store/memory/mod.rs
FloatToken (Interface)
(no doc) [2 implementers]
crates/cli/src/wast_runner.rs
ToWasmTypes (Interface)
Describes the WebAssembly value types produced by a Rust value or tuple shape. [2 implementers]
crates/tinywasm/src/func.rs
NoStdFloatExt (Interface)
see https://github.com/rust-lang/rust/issues/137578 :( [2 implementers]
crates/tinywasm/src/interpreter/no_std_floats.rs
MemValue (Interface)
A trait for types that can be converted to and from static byte arrays [2 implementers]
crates/tinywasm/src/store/memory/mod.rs
IntoWasmValues (Interface)
(no doc) [2 implementers]
crates/tinywasm/src/func.rs

Core symbols most depended-on inside this repo

push
called by 116
crates/tinywasm/src/interpreter/stack/call_stack.rs
len
called by 107
crates/tinywasm/src/store/memory/vec.rs
len
called by 99
crates/tinywasm/src/reference.rs
map
called by 76
crates/tinywasm/src/store/table.rs
offset
called by 50
crates/tinywasm/src/reference.rs
mem_addr
called by 49
crates/types/src/instructions.rs
define
called by 43
crates/tinywasm/src/imports.rs
parse_bytes
called by 42
crates/parser/src/lib.rs

Shape

Method 857
Function 310
Class 96
Enum 42
Interface 13

Languages

Rust98%
C2%

Modules by API surface

crates/tinywasm/src/interpreter/simd/instructions.rs239 symbols
crates/tinywasm/src/interpreter/executor.rs72 symbols
crates/types/src/lib.rs59 symbols
crates/parser/src/visit.rs55 symbols
crates/cli/src/wast_runner.rs52 symbols
crates/tinywasm/src/store/memory/mod.rs49 symbols
crates/tinywasm/src/func.rs45 symbols
crates/tinywasm/src/reference.rs41 symbols
crates/tinywasm/src/store/mod.rs39 symbols
crates/tinywasm/src/instance.rs37 symbols
crates/tinywasm/src/store/memory/paged.rs29 symbols
crates/tinywasm/src/store/memory/lazy.rs29 symbols

For agents

$ claude mcp add tinywasm \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact