wasm-pack
wasm-pack copied to clipboard
Bad CPU type in executable (os error 86) running wasm-pack build on M1
🐛 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)
❯ 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 ?
Workaround: (manually install wasm-bindgen)
- cargo install wasm-bindgen-cli
- 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.
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
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)
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
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?
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
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
-
cargo uninstall wasm-pack
-
cargo install wasm-bindgen-cli
-
brew install binaryen
-
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.
Thank you @pglezen, that procedure solved the bug in my M2 environment. I've been looking for a way to solve the bug.
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 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
.
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?
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.
Currently I'm using wasm-bindgen-cli
+ wasm-opt
instead of wasm-pack
. It works well for me in my arm64 macos.
Currently I'm using
wasm-bindgen-cli
+wasm-opt
instead ofwasm-pack
. It works well for me in my arm64 macos.
Ah, sweet so it is possible!
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.
For me softwareupdate --install-rosetta
installing rosetta worked.