Description
🐛 Bug description
binaryen releases say they provide x86 builds, but the release file contains x64 binaries, so wasm-pack fails to execute it, and throws a cryptic error message. The locally installed wasm-opt is not properly detected
$ wasm-pack --verbose --log-level info build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Finished release [optimized] target(s) in 0.15s
[INFO]: Optimizing wasm binaries with `wasm-opt`...
Error: Exec format error (os error 8)
To disable `wasm-opt`, add `wasm-opt = false` to your package metadata in your `Cargo.toml`.
I understand this binary gets installed automatically when wasm-opt is not found in the PATH.
#625
However, manually installing wasm-opt and making sure it's in the PATH still throws error 8.
$ wasm-pack build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Finished release [optimized] target(s) in 0.13s
[INFO]: Optimizing wasm binaries with `wasm-opt`...
Error: Exec format error (os error 8)
To disable `wasm-opt`, add `wasm-opt = false` to your package metadata in your `Cargo.toml`.
$ wasm-opt --version
wasm-opt version 98
$ whereis wasm-opt
wasm-opt: /usr/bin/wasm-opt
I replaced wasm-opt binary on /usr/bin to test if it was being called at all, and it was not called by wasm-pack build.
I also wrote a small app to test if 'which' crate was finding wasm-opt and this code correctly finds the binary:
use std::path::PathBuf;
fn main() {
let result = which::which("wasm-opt").unwrap();
assert_eq!(result, PathBuf::from("/usr/bin/wasm-opt"));
println!("It found wasm-opt.");
}
🤔 Expected Behavior
There are a few alternatives
- It should show a warning explaining it can't find wasm-opt installed in the system, and skip the optimization.
- The error message could be more descriptive, since the wasm-opt configuration goes into the section package.metadata.wasm-pack.profile.release (.profile and .dev too) and this is not clear right from the error message
- Show an error describing that wasm-opt was downloaded and installed (with the full path to the binary), and that it cannot execute it
- Properly detect the existing binary
👟 Steps to reproduce
Run wasm-pack build on an x86 linux
🌍 Your environment
32 bit Gentoo
wasm-pack version: 0.9.1
rustc version: rustc 1.50.0 (cb75ad5db 2021-02-10)
Tested it on 64 bit Gentoo and works without issues.
Workaround
Disable it in Cargo.toml and run it manually later:
[package.metadata.wasm-pack.profile.release]
wasm-opt = false
[package.metadata.wasm-pack.profile.dev]
wasm-opt = false
[package.metadata.wasm-pack.profile.profiling]
wasm-opt = false
Then run it manually from the command line:
wasm-opt original-file.wasm -o optimized-file.wasm -O4 -all