Add Binaryen's `wasm-opt` to `cargo contract build`
Created by: Robbepop
After merging https://github.com/paritytech/ink/pull/312 ink! smart contracts will suffer from bloated Wasm binaries due to missing optimizations (or bugs?) between Rust and Wasm translation.
These cause a 0x00
16kB buffer to not be removed from the Wasm binary.
However, Binaryen's wasm-opt
with -O3
(or even -O2
) can easily do this among other neat optimization routines.
Some contracts have been shown to have a reduced Wasm binary size from 27kB down to 9kB just through using wasm-opt
.
The cargo contract build
process should include wasm-opt
by default, however, if wasm-opt
does not exist on the user machine it should simply avoid using it (as it is been done today) and print the user a warning that the resulting Wasm binary might not be optimal and refer the user to install the wasm-opt
tool.