Skip to content
dewasmPublic

About

dewasm converts WebAssembly binaries into pure source code for languages like Ruby, Bash, and Go.

Resources

Stars

12 stars

Watchers

0 watching

Forks

Repository files navigation

dewasm

CI crates.io

dewasm converts WebAssembly binaries into pure source code for languages like Ruby, Bash, and Go.

No WebAssembly runtime is required. The output runs anywhere plain ruby, bash, or go does.

Here is cowsay, a WebAssembly binary, converted to a pure Bash script and run with nothing but bash:

$ dewasm examples/apps/cache/cowsay.wasm --target bash --mode standalone -o cowsay.sh
$ echo "Hello from Bash" | bash cowsay.sh
 _________________ 
< Hello from Bash >
 ----------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Even QuickJS-NG, a JavaScript engine written in C, can be converted, this time to pure Ruby:

$ dewasm examples/apps/cache/qjs.wasm --target ruby --mode standalone -o qjs.rb
$ ruby qjs.rb -e 'console.log("2**16 =", 2**16); console.log(JSON.stringify(["Ruby", "JavaScript"].sort()))'
2**16 = 65536
["JavaScript","Ruby"]

A WebAssembly binary can also be used as a library instead of a standalone application. Here, a small example add.wat is converted and its add export is called directly from Ruby:

$ dewasm examples/wat/add.wat --target ruby --mode library --module-name Add -o add.rb
require_relative "add"

inst = Add.new
inst.invoke("add", 2, 3) # => 5

Beyond simple examples, dewasm scales to real libraries and applications too:

  • examples/rails runs a Rails blog on Ruby alone. The C extensions of sqlite3, nokogiri, herb, and bcrypt are converted to Ruby by dewasm.
  • examples/doom ports the WebAssembly version of DOOM to multiple languages, including Bash.
  • examples/nes converts a NES emulator (agnes) once. It turns every backend language into a native NES player.

Here is a quick summary of what dewasm can do:

  • Support real-world binaries: Implements most of the Wasm 1.0 and WASI Preview 1 specifications. It also implements the exception-handling proposal on most backends.
  • Target multiple languages: Translates one WebAssembly binary to Ruby, Bash, Go, and other languages.
  • Adapt to your needs: Generates either standalone scripts or importable library source code.
  • Keep it minimal: Bundles only the runtime code that the WebAssembly binary requires.

Installation

$ cargo install dewasm

or:

$ git clone https://github.com/dewasm/dewasm && cd dewasm
$ cargo build --release

Usage

$ dewasm input.<wasm|wat>
    --target <ruby|bash|python|perl|go|java|codon>
    --mode <standalone|library>
    -o output.<rb|sh|py|pl|go|java|codon>
  • input is a WebAssembly binary to be translated.
    • dewasm accepts a WebAssembly text (WAT) file too.
  • --target (or -t) selects the target language (required).
  • --mode (or -m) specifies the translation mode (default: library).
    • --mode standalone connects WASI and runs the module's _start.
    • --mode library exposes the module's exports to the target language.
  • --output (or -o) sets the output file (default: -).
    • When - is specified, dewasm outputs the result to stdout.
  • --module-name names the generated class/package, and is required in library mode.
    • Standalone output has a fixed internal name and rejects it.

Please see dewasm --help for the full list of options.

Next:

License

The MIT license. See the LICENSE file.

Copyright (c) 2026 Hiroya Fujinami

About

dewasm converts WebAssembly binaries into pure source code for languages like Ruby, Bash, and Go.

Resources

Stars

12 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages