From a5b1cab9d988e31ed19290453c98ce3ee109851c Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 19 Feb 2021 13:40:37 +0100 Subject: [PATCH 1/6] Use `--zero-filled-memory` for `wasm-opt` --- src/cmd/build.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 2a03e774..e6ed7b3a 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -352,6 +352,12 @@ fn do_optimization( .arg(format!("-O{}", optimization_level)) .arg("-o") .arg(dest_optimized) + + // the memory in our module is imported, `wasm-opt` needs to be told that + // the memory is initialized to zeros, otherwise it won't run the + // memory-packing pre-pass. + .arg("--zero-filled-memory") + .output()?; if !output.status.success() { -- GitLab From facb7e9cd19643ce8ff0f590d8fffcd870d79b43 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 19 Feb 2021 13:43:05 +0100 Subject: [PATCH 2/6] Assert that compiled contract template is below 3k --- src/cmd/build.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index e6ed7b3a..36689af1 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -475,6 +475,10 @@ mod tests_ci_only { // would fail for that. assert!(res.target_directory.ends_with("target/ink")); assert!(res.optimization_result.unwrap().optimized_size > 0.0); + + // our optimized contract template should always be below 3k. + assert!(res.optimization_result.unwrap().optimized_size < 3.0); + Ok(()) }) } -- GitLab From b57112a6fd098327a29ba57f4fe6c5b3a88d2458 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 19 Feb 2021 16:22:11 +0100 Subject: [PATCH 3/6] Apply cargo fmt --- src/cmd/build.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 36689af1..22dcf653 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -352,12 +352,10 @@ fn do_optimization( .arg(format!("-O{}", optimization_level)) .arg("-o") .arg(dest_optimized) - // the memory in our module is imported, `wasm-opt` needs to be told that // the memory is initialized to zeros, otherwise it won't run the // memory-packing pre-pass. .arg("--zero-filled-memory") - .output()?; if !output.status.success() { -- GitLab From f31950dbbcc711fdb39df5d476cd47c20d80ee70 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 19 Feb 2021 16:30:05 +0100 Subject: [PATCH 4/6] Remove superfluous comment --- src/cmd/build.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 22dcf653..72094655 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -359,7 +359,6 @@ fn do_optimization( .output()?; if !output.status.success() { - // Dump the output streams produced by `wasm-opt` into the stdout/stderr. anyhow::bail!("wasm-opt optimization failed"); } Ok(()) -- GitLab From f888044a44457e8d2f24f2a1c7aa723058f2f766 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 19 Feb 2021 16:41:48 +0100 Subject: [PATCH 5/6] Improve error message on `wasm-opt` error --- src/cmd/build.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 72094655..85ec744d 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -23,7 +23,7 @@ use std::{ }; #[cfg(not(feature = "binaryen-as-dependency"))] -use std::process::Command; +use std::{process::Command, str}; use crate::{ crate_metadata::CrateMetadata, @@ -359,7 +359,15 @@ fn do_optimization( .output()?; if !output.status.success() { - anyhow::bail!("wasm-opt optimization failed"); + let err = str::from_utf8(&output.stderr) + .expect("cannot convert stderr output of wasm-opt to string") + .trim(); + anyhow::bail!( + "The wasm-opt optimization failed.\n\ + A possible source of error could be that you have an outdated binaryen package installed.\n\n\ + The error which wasm-opt returned was: \n{}", + err + ); } Ok(()) } -- GitLab From 4a2a30641283dca5783d3a53bf6d4e018401dcad Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Mon, 22 Feb 2021 09:40:16 +0100 Subject: [PATCH 6/6] Specify minimum binaryen version --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 600d4be4..09f3e876 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ A CLI tool for helping setting up and managing WebAssembly smart contracts writt We optimize the resulting contract Wasm using `binaryen`. You have two options for installing it: - _The preferred way:_ - Install [`binaryen`](https://github.com/WebAssembly/binaryen#tools). Many package managers - have it available nowadays ‒ e.g. it's a package for [Debian/Ubuntu](https://tracker.debian.org/pkg/binaryen), + Install [`binaryen`](https://github.com/WebAssembly/binaryen#tools) with a version >= 99. + Many package managers have it available nowadays ‒ e.g. it's a package for [Debian/Ubuntu](https://tracker.debian.org/pkg/binaryen), [Homebrew](https://formulae.brew.sh/formula/binaryen) and [Arch Linux](https://archlinux.org/packages/community/x86_64/binaryen/). After you've installed the package execute `cargo install --force cargo-contract`. -- GitLab