wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

Bad CPU type in executable (os error 86) running wasm-pack build on M1

Open dragonware-com opened this issue 3 years ago • 9 comments

🐛 Bug description

wasm-pack build on M1 failed: Bad CPU type in executable (os error 86)

❯ wasm-pack build [INFO]: 🎯 Checking for the Wasm target... [INFO]: 🌀 Compiling to Wasm... Compiling proc-macro2 v1.0.34 Compiling unicode-xid v0.2.2 Compiling wasm-bindgen-shared v0.2.78 Compiling syn v1.0.84 Compiling log v0.4.14 Compiling cfg-if v1.0.0 Compiling lazy_static v1.4.0 Compiling bumpalo v3.8.0 Compiling wasm-bindgen v0.2.78 Compiling quote v1.0.10 Compiling wasm-bindgen-backend v0.2.78 Compiling wasm-bindgen-macro-support v0.2.78 Compiling wasm-bindgen-macro v0.2.78 Compiling console_error_panic_hook v0.1.7 Compiling wasm-game-of-life v0.1.0 (/Users/welson/git/wasm-game-of-life) warning: function is never used: set_panic_hook --> src/utils.rs:1:8 | 1 | pub fn set_panic_hook() { | ^^^^^^^^^^^^^^ | = note: #[warn(dead_code)] on by default

warning: wasm-game-of-life (lib) generated 1 warning Finished release [optimized] target(s) in 4.56s [INFO]: ⬇️ Installing wasm-bindgen... Error: Bad CPU type in executable (os error 86)

On x64: [INFO]: Installing wasm-bindgen... [INFO]: Optimizing wasm binaries with wasm-opt... [INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended [INFO]: :-) Done in 8.75s [INFO]: :-) Your wasm pkg is ready to publish at /usr/src/myapp/wasm-game-of-life/pkg.

👟 Steps to reproduce

Installed wasm-pack via homebrew Follow https://rustwasm.github.io/book/game-of-life/hello-world.html

🌍 Your environment

Include the relevant details of your environment. wasm-pack version: wasm-pack 0.10.2 rustc version: rustc 1.56.1 (59eed8a2a 2021-11-01)

dragonware-com avatar Dec 26 '21 21:12 dragonware-com

❯ RUST_LOG=info wasm-pack build

[INFO]: ⬇️ Installing wasm-bindgen... INFO 2021-12-26T22:02:36Z: wasm_pack::command::build: Installing wasm-bindgen-cli was successful. INFO 2021-12-26T22:02:36Z: wasm_pack::command::build: Building the wasm bindings... INFO 2021-12-26T22:02:36Z: wasm_pack::child: Running "/Users/welson/Library/Caches/.wasm-pack/wasm-bindgen-e2403975ebca0635/wasm-bindgen" "--version" Error: Bad CPU type in executable (os error 86)

So looks like installed wasm-bindgen is not for M1 ?

dragonware-com avatar Dec 26 '21 22:12 dragonware-com

Workaround: (manually install wasm-bindgen)

  1. cargo install wasm-bindgen-cli
  2. Disable wasm-opt: Add the following to Cargo.toml [package.metadata.wasm-pack.profile.release] wasm-opt = false

❯ wasm-pack build [INFO]: 🎯 Checking for the Wasm target... [INFO]: 🌀 Compiling to Wasm... warning: function is never used: set_panic_hook --> src/utils.rs:1:8 | 1 | pub fn set_panic_hook() { | ^^^^^^^^^^^^^^ | = note: #[warn(dead_code)] on by default

warning: wasm-game-of-life (lib) generated 1 warning Finished release [optimized] target(s) in 0.01s [INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended [INFO]: ✨ Done in 0.17s [INFO]: 📦 Your wasm pkg is ready to publish at /Users/welson/git/wasm-game-of-life/pkg.

dragonware-com avatar Dec 26 '21 23:12 dragonware-com

To enable wasm-opt, install from source: https://github.com/WebAssembly/binaryen

copy build/lib and build/bin/wasm-opt to ~/.cargo

OR

brew install binaryyen

dragonware-com avatar Dec 26 '21 23:12 dragonware-com

Hi guys, the same problem here on M1, just manifested via trying to run a project using Trunk (https://trunkrs.dev/). Is anyone lookign at it at all? (Sorry the issue is beyong my current competency in Rust/capability to help out)

thestarmaker avatar Feb 22 '22 21:02 thestarmaker

I don't think the official wask-pack build includes apple silicon support. Just type the 2 commands for workaround:

cargo install wasm-bindgen-cli
brew install binaryyen

dragonware-com avatar Feb 22 '22 22:02 dragonware-com

Thank you @dragonware-com, this did the trick. I am very new to this subject, any chance anyone could point me to information how binaryen fits into the entire "compiling to WebAssembly" and wasm-pack thing?

thestarmaker avatar Feb 23 '22 19:02 thestarmaker

Thank you for providing a fix for now, on one of my M1 machines with a slightly older version of wasm-pack this isn't necessary but on 0.10.2 it is.

Also just for anyone else looking at this, the package is binaryen

cargo install wasm-bindgen-cli
brew install binaryen

HiceS avatar Jun 13 '22 01:06 HiceS

This worked for me after my wasm-pack was rendered useless after my macOS upgrade to Monterey 12.5.1 disabled Rosetta. My symptom was

$ wasm-pack build --target web
[INFO]: 🎯  Checking for the Wasm target...
[INFO]: 🌀  Compiling to Wasm...
    Finished release [optimized] target(s) in 0.06s
[WARN]: ⚠️   origin crate has no README
[INFO]: ⬇️  Installing wasm-bindgen...
Error: Bad CPU type in executable (os error 86)

So I ran

  1. cargo uninstall wasm-pack
  2. cargo install wasm-bindgen-cli
  3. brew install binaryen
  4. cargo install wasm-pack

I'm not sure Steps 1 and 4 were necessary; that's just how I did them. Now I'm back in business.

pglezen avatar Aug 24 '22 21:08 pglezen

Thank you @pglezen, that procedure solved the bug in my M2 environment. I've been looking for a way to solve the bug.

yu-hasebe avatar Aug 24 '22 22:08 yu-hasebe

Latest wasm-pack is incompatible with the latest wasm-bindgen-cli, so on M1 Mac, the above instructions don't work (although the problem is not anymore wasm-opt related). wasm-pack tries to download wasm-bindgen-cli binary for the wrong platform. cargo install [email protected] helps 🙄

jpochyla avatar Sep 29 '22 17:09 jpochyla

@jpochyla downgrading the wasm-bindgen-cli to 0.2.82 still doesn't help in my macos.

cargo install --list

wasm-bindgen-cli v0.2.82:
    wasm-bindgen
    wasm-bindgen-test-runner
    wasm2es6js
wasm-pack v0.10.3:
    wasm-pack

Running wasm-pack new abc still gets me a Error: Bad CPU type in executable (os error 86)

I have no rosetta installed, don't know if it's a must for wasm-pack.

qdwang avatar Oct 12 '22 02:10 qdwang

Have the same issue.

wasm-pack new abc
[INFO]: ⬇️  Installing cargo-generate...
🐑  Generating a new rustwasm project with name 'abc'...
Error: Running cargo-generate
Caused by: Bad CPU type in executable (os error 86)

Are there any advices on what I can check?

holiday-coder avatar Oct 12 '22 19:10 holiday-coder

Just started playing around with yew and ran into this same problem on the M1 Pro. I explicitly do not want to install rosetta on this laptop as I'm going for a pure arm64 build.

Dygear avatar Nov 03 '22 16:11 Dygear

Currently I'm using wasm-bindgen-cli + wasm-opt instead of wasm-pack. It works well for me in my arm64 macos.

qdwang avatar Nov 07 '22 15:11 qdwang

Currently I'm using wasm-bindgen-cli + wasm-opt instead of wasm-pack. It works well for me in my arm64 macos.

Ah, sweet so it is possible!

Dygear avatar Nov 08 '22 00:11 Dygear

I believe this PR is targeting a fix for this issue. Binaryen was the package that was causing the issue. https://github.com/rustwasm/wasm-pack/pull/1188

Thanks printfn for fixing this, this thread keeps sending me emails.

HiceS avatar Nov 11 '22 02:11 HiceS

For me softwareupdate --install-rosetta installing rosetta worked.

a-c-sreedhar-reddy avatar Oct 04 '23 02:10 a-c-sreedhar-reddy