2017-05-30 15:06:46 +04:00
# wasm-utils
2017-04-12 20:52:01 +04:00
2017-11-20 16:54:31 +03:00
[](https://travis-ci.org/paritytech/wasm-utils)
2017-05-30 15:06:46 +04:00
Collection of WASM utilities used in Parity and WASM contract devepment
2017-04-12 20:52:01 +04:00
2017-08-09 14:00:09 +03:00
## Build tools for cargo
Easiest way to use is to install via `cargo install` :
```
cargo install --git https://github.com/paritytech/wasm-utils wasm-build
```
2017-09-15 22:03:43 +03:00
## Symbols pruning (wasm-prune)
2017-04-12 20:52:01 +04:00
```
2017-09-15 22:03:43 +03:00
cargo run --release --bin wasm-prune -- < input_binary.wasm > < output_binary.wasm >
2017-04-12 20:52:01 +04:00
```
2017-05-31 15:10:20 +04:00
This will optimize WASM symbols tree to leave only those elements that are used by contract `_call` function entry.
2017-04-12 20:52:01 +04:00
2017-05-30 15:06:46 +04:00
## Gas counter (wasm-gas)
2017-04-12 20:53:31 +04:00
2017-05-30 15:06:46 +04:00
For development puposes, raw WASM contract can be injected with gas counters (the same way as it done by Parity runtime when running contracts)
2017-04-12 20:52:01 +04:00
2017-05-30 15:06:46 +04:00
```
2017-05-30 15:08:19 +04:00
cargo run --release --bin wasm-gas -- < input_binary.wasm > < output_binary.wasm >
2017-05-30 15:06:46 +04:00
```
2017-11-07 12:17:28 +03:00
## Externalization (wasm-ext)
2017-05-30 15:06:46 +04:00
2017-11-07 12:17:28 +03:00
Parity WASM runtime provides some library functions that can be commonly found in libc. WASM binary size can be reduced and performance may be improved if these functions are used. This utility scans for invocations of the following functions inside the WASM binary:
- `_malloc` ,
- `_free` ,
- `_memcpy` ,
- `_memset` ,
- `_memmove`
And then substitutes them with invocations of the imported ones. Should be run before `wasm-opt` for better results.
2017-05-30 15:06:46 +04:00
2017-05-30 15:08:19 +04:00
```
cargo run --release --bin wasm-ext -- < input_binary.wasm > < output_binary.wasm >
```
## API
2017-05-30 15:08:42 +04:00
All executables use corresponding api methods of the root crate and can be combined in other build tools.
2017-11-03 02:11:41 +03:00
# License
`wasm-utils` is primarily distributed under the terms of both the MIT
license and the Apache License (Version 2.0), at your choice.
See LICENSE-APACHE, and LICENSE-MIT for details.