Skip to content

Commit

Permalink
Improve wasm-opt error output (use-ink#244)
Browse files Browse the repository at this point in the history
* Improve error output

* Add installation commands

* Fix casing

* Use display instead of debug
  • Loading branch information
Michael Müller authored Mar 31, 2021
1 parent 449a40f commit bd390f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ We optimize the resulting contract Wasm using `binaryen`. You have two options f

- _The preferred way:_
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/).
For Windows, [binary releases are available](https://github.com/WebAssembly/binaryen/releases).
Many package managers have it available nowadays:

* [Debian/Ubuntu](https://tracker.debian.org/pkg/binaryen): `apt-get install binaryen`
* [Homebrew](https://formulae.brew.sh/formula/binaryen): `brew install binaryen`
* [Arch Linux](https://archlinux.org/packages/community/x86_64/binaryen/): `pacman -S binaryen`
* Windows: [binary releases are available](https://github.com/WebAssembly/binaryen/releases)

After you've installed the package execute `cargo install --force cargo-contract`.

- _Build `binaryen` as a dependency when installing `cargo-contract`:_
Expand Down
24 changes: 13 additions & 11 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,13 @@ fn do_optimization(
wasm-opt is part of the binaryen package. You can find detailed\n\
installation instructions on https://github.com/WebAssembly/binaryen#tools.\n\n\
There are also ready-to-install packages for many platforms:\n\
* Debian/Ubuntu: https://tracker.debian.org/pkg/binaryen\n\
* Homebrew: https://formulae.brew.sh/formula/binaryen\n\
* Arch Linux: https://archlinux.org/packages/community/x86_64/binaryen\n\
* Windows: binary releases are available at https://github.com/WebAssembly/binaryen/releases"
.to_string()
.bright_yellow()
There are ready-to-install packages for many platforms:\n\
* Debian/Ubuntu: apt-get install binaryen\n\
* Homebrew: brew install binaryen\n\
* Arch Linux: pacman -S binaryen\n\
* Windows: binary releases at https://github.com/WebAssembly/binaryen/releases"
.to_string()
.bright_yellow()
);
}
let wasm_opt_path = which
Expand Down Expand Up @@ -448,7 +448,7 @@ fn do_optimization(

if !output.status.success() {
let err = str::from_utf8(&output.stderr)
.expect("cannot convert stderr output of wasm-opt to string")
.expect("Cannot convert stderr output of wasm-opt to string")
.trim();
anyhow::bail!(
"The wasm-opt optimization failed.\n\n\
Expand Down Expand Up @@ -490,12 +490,14 @@ fn check_wasm_opt_version_compatibility(wasm_opt_path: &Path) -> Result<()> {
// $ wasm-opt --version
// wasm-opt version 99 (version_99-79-gc12cc3f50)
// ```
let version_stdout =
str::from_utf8(&cmd.stdout).expect("cannot convert stdout output of wasm-opt to string");
let version_stdout = str::from_utf8(&cmd.stdout)
.expect("Cannot convert stdout output of wasm-opt to string")
.trim();
let re = Regex::new(r"wasm-opt version (\d+)\s+").unwrap();
let captures = re.captures(version_stdout).ok_or_else(|| {
anyhow::anyhow!(
"Unable to extract version information from {:?}",
"Unable to extract version information from {}.\n\
Your wasm-opt version is most probably too old. Make sure you use a version >= 99.",
version_stdout
)
})?;
Expand Down

0 comments on commit bd390f3

Please sign in to comment.