Use either `binaryen-rs` dep or `wasm-opt` binary

Created by: cmichi

Closes #113 (closed).

Soo, this will get a bit hairy and I expect discussion in this PR.

Our initial idea of using our build script to dynamically enable the binaryen-rs dependency based on availability of the wasm-opt binary won't work:

The build script is run (once) after the dependencies are built, so without time travel it can not add dependencies.

(from https://github.com/rust-lang/cargo/issues/5499)

What we could do instead is to install cargo-contract either with

  • cargo install --features wasm-opt-unavailable, if we want to use the binaryen-rs dep.
  • or via the usual cargo install, if the wasm-opt binary is available.

This is currently implemented by this PR ‒ if the feature wasm-opt-unavailable is enabled the binaryen-rs dep is built and used for optimization.

To automate the decision which installation parameters to use we could e.g. build something like the Substrate installation script (curl https://getsubstrate.io -sSf | bash). I'm also not super-happy with this approach, but it's the best workaround I've found so far. Open for other ideas, of course.

Merge request reports