wasm-merge-sys
Rust bindings for Binaryen's wasm-merge tool.
This crate provides low-level bindings to the wasm-merge C++ implementation from the Binaryen project.
What is wasm-merge?
wasm-merge is a WebAssembly module merger that loads multiple wasm files, connects them together by hooking up imports to exports, and emits a single merged module. Unlike wasm-ld, this does not have the full semantics of native linkers. Instead, wasm-merge does at compile time what you can do with JavaScript at runtime: connect wasm modules together.
The result is a single module that behaves the same as the multiple original modules, but you don't need JavaScript to set up the connections between modules anymore. This allows for better optimization opportunities like DCE and inlining.
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Example
use run_wasm_merge;
API
run_wasm_merge(args: &[String]) -> i32
Run wasm-merge with the given command-line arguments.
- Arguments: A slice of string arguments (should include the program name as args[0])
- Returns: The exit code of wasm-merge (0 for success, non-zero for error)
This is a safe wrapper around the C wasm_merge_main function that handles string conversion and memory management.
Building
This crate requires:
- A C++17-compatible compiler
- The Binaryen source code (as a git submodule or in the
binaryen/directory)
To build:
# If using as a git submodule
# Build the crate
Features
dwarf(default): Include DWARF debug information support
License
MIT OR Apache-2.0
Reference
This project is modeled after wasm-opt-rs by Brian Anderson.