Unverified Commit bd390f35 authored by Michael Müller's avatar Michael Müller Committed by GitHub

Improve `wasm-opt` error output (#244)

* Improve error output

* Add installation commands

* Fix casing

* Use display instead of debug
parent 449a40fc
Pipeline #131977 passed with stages
in 5 minutes and 10 seconds
......@@ -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`:_
......
......@@ -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
......@@ -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\
......@@ -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
)
})?;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment