Skip to content

A tiny, interpreted WebAssembly Runtime written in Rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

explodingcamera/tinywasm

Repository files navigation

TinyWasm

A tiny WebAssembly Runtime written in safe Rust

docs.rs Crates.io Crates.io

Why TinyWasm?

  • Tiny: TinyWasm is designed to be as small as possible without significantly compromising performance or functionality (< 4000 LLOC).
  • Portable: TinyWasm runs on any platform that Rust can target, including no_std, with minimal external dependencies.
  • Safe: No unsafe code is used in the runtime

Current Status

TinyWasm passes all WebAssembly MVP tests from the WebAssembly core testsuite and is able to run most WebAssembly programs. Additionally, the current 2.0 WebAssembly is mostly supported, with the exception of the SIMD and Memory64 proposals. See the Supported Proposals section for more information.

Safety

Safety wise, TinyWasm doesn't use any unsafe code and is designed to be completly memory-safe. Untrusted WebAssembly code should not be able to crash the runtime or access memory outside of its sandbox, however currently there is no protection against infinite loops or excessive memory usage. Unvalidated Wasm and untrusted, precompilled twasm bytecode is safe to run too but can crash the runtime.

Supported Proposals

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

Proposal Status TinyWasm Version
Mutable Globals 🟢 0.2.0
Non-trapping float-to-int Conversion 🟢 0.2.0
Sign-extension operators 🟢 0.2.0
Multi-value 🟢 0.2.0
Bulk Memory Operations 🟢 0.4.0
Reference Types 🟢 0.7.0
Multiple Memories 🟢 0.8.0
Custom Page Sizes 🟢 next
Tail Call 🟢 next
Memory64 🟢 next
Fixed-Width SIMD 🚧 N/A

Usage

See the examples directory and documentation for more information on how to use TinyWasm. For testing purposes, you can also use the tinywasm-cli tool:

$ cargo install tinywasm-cli
$ tinywasm-cli --help

Feature Flags

  • std
    Enables the use of std and std::io for parsing from files and streams. This is enabled by default.
  • logging
    Enables logging using the log crate. This is enabled by default.
  • parser
    Enables the tinywasm-parser crate. This is enabled by default.
  • archive
    Enables pre-parsing of archives. This is enabled by default.

With all these features disabled, TinyWasm only depends on core, alloc, and libm and can be used in no_std environments. Since libm is not as performant as the compiler's math intrinsics, it is recommended to use the std feature if possible (at least for now), especially on wasm32 targets.

Inspiration

Big thanks to the authors of the following projects, which have inspired and influenced TinyWasm:

  • wasmi - an efficient and lightweight WebAssembly interpreter that also runs in no_std environments
  • wasm3 - a high-performance WebAssembly interpreter written in C
  • wazero - a zero-dependency WebAssembly interpreter written in Go
  • wain - a zero-dependency WebAssembly interpreter written in Rust

I encourage you to check these projects out if you're looking for more mature and feature-complete WebAssembly runtimes.

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.