Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm-opt throws error 8 on x86 when running wasm-pack build #974

Closed
dc740 opened this issue Feb 14, 2021 · 1 comment
Closed

wasm-opt throws error 8 on x86 when running wasm-pack build #974

dc740 opened this issue Feb 14, 2021 · 1 comment

Comments

@dc740
Copy link

dc740 commented Feb 14, 2021

🐛 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

  1. It should show a warning explaining it can't find wasm-opt installed in the system, and skip the optimization.
  2. 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
  3. Show an error describing that wasm-opt was downloaded and installed (with the full path to the binary), and that it cannot execute it
  4. 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

@drager
Copy link
Member

drager commented Jun 17, 2023

@drager drager closed this as completed Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants