Repolode
WebAssembly

WebAssembly/binaryen

A C++ compiler and optimizer library for WebAssembly, with the wasm-opt tool and a JavaScript build (binaryen.js).

Stars
8,666
Forks
899
Open issues
580
Last commit
8 hours ago

What is it?

Binaryen is a compiler and toolchain infrastructure library for WebAssembly, written in C++. It provides a simple C API and a JavaScript interface, and it accepts input in a WebAssembly-like form as well as a general control flow graph. Its internal IR is designed to compile down to WebAssembly quickly and to run optimization passes in parallel.

The optimizer contains many passes aimed at reducing code size and improving speed, with a focus on WebAssembly-specific transformations such as local register allocation, dead code elimination, inlining and data segment packing. The main tool, wasm-opt, runs these passes on a wasm file, and related tools cover assembling and disassembling wasm, converting wasm to JavaScript with wasm2js, merging modules, reducing test cases and interpreting wasm.

Several toolchains use Binaryen as a component, including Emscripten, wasm-pack, Kotlin/Wasm and Dart's Flutter web build, and it is also used as a library by AssemblyScript and Grain.

Key features

  • 01Optimizer with many WebAssembly-specific passes for reducing code size and improving speed
  • 02wasm-opt command-line tool for optimizing and transforming wasm files
  • 03wasm2js compiler that converts WebAssembly to ES6 JavaScript modules
  • 04Simple C API and binaryen.js for building and optimizing modules from code
  • 05wasm-merge, wasm-metadce and wasm-reduce utilities for bundling, pruning and reducing wasm files

Use cases

  • Shrinking and speeding up WebAssembly output from C, C++, Rust or Kotlin toolchains
  • Compiling WebAssembly to JavaScript for environments without native wasm support
  • Merging several wasm modules into one file before shipping
  • Building WebAssembly modules programmatically from JavaScript or C

Things to know

  • Default text output is not always valid WebAssembly text, so use --generate-stack-ir --print-stack-ir for valid text.

Topics

FAQ

What is binaryen?
A C++ compiler and optimizer library for WebAssembly, with the wasm-opt tool and a JavaScript build (binaryen.js). Binaryen is a compiler and toolchain infrastructure library for WebAssembly, written in C++. It provides a simple C API and a JavaScript interface, and it accepts input in a WebAssembly-like form as well as a general control flow graph. Its internal IR is designed to compile down to WebAssembly quickly and to run optimization passes in parallel.
Is binaryen free to use? What license does it have?
binaryen is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is binaryen still maintained?
Actively maintained. The last commit to binaryen was on Oct 21, 2026.
What can I use binaryen for?
Shrinking and speeding up WebAssembly output from C, C++, Rust or Kotlin toolchains Compiling WebAssembly to JavaScript for environments without native wasm support Merging several wasm modules into one file before shipping Building WebAssembly modules programmatically from JavaScript or C
Where can I get binaryen?
The source code and installation instructions are on GitHub: https://github.com/WebAssembly/binaryen

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects