wasm-opt fails to optimize .wasm with SIMD instructions
🐛 Bug description
When I try to run wasm-pack build in project that uses SIMD functions, wasm-opt throws following error:
[parse exception: Invalid reserved field on memory.grow/memory.size (at 0:33481)]
Fatal: error in parsing input
Error: failed to execute `wasm-opt`: exited with exit code: 1
This is emitted when I try to compile following code:
#![cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
use std::arch::wasm32::*;
#[wasm_bindgen]
pub fn foo() {
let _vec = f32x4(1.0, 2.0, 3.0, 4.0);
}
🤔 Expected Behavior
wasm-opt should optimize .wasm file or show some message.
👟 Steps to reproduce
Create new empty project with cargo new.
Set following keys in Cargo.toml:
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
wasm-bindgen = "0.2.63"
Create lib.rs in src folder and paste following code:
#![cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
use std::arch::wasm32::*;
#[wasm_bindgen]
pub fn foo() {
let _vec = f32x4(1.0, 2.0, 3.0, 4.0);
}
Run wasm-pack build
🌍 Your environment
wasm-pack version: 0.10.2 rustc version: 1.56.1 (59eed8a2a 2021-11-01) Running on Windows 10
wasm-pack downloads wasm-opt version 90 from December 2019 without SIMD support
https://github.com/rustwasm/wasm-pack/blob/4ae6306570a0011246c39c8028a4f11a4236f54b/src/install/mod.rs#L209-L210
You can supply your own, more recent version:
Install https://github.com/WebAssembly/binaryen in your path
Run with --mode no-install
wasm-pack build --mode no-install
This works for me if wasm-opt is configured with SIMD support:
[package.metadata.wasm-pack.profile.dev]
wasm-opt = ['--enable-simd']
[package.metadata.wasm-pack.profile.profiling]
wasm-opt = ['--enable-simd']
[package.metadata.wasm-pack.profile.release]
wasm-opt = ['--enable-simd']