wasm-pack
wasm-pack copied to clipboard
wasm-opt fails during linux builds
🐛 Bug description
When running wasm-pack build the command does not finish on linux systems. The error message (sample taken from github actions) is
[INFO]: Installing wasm-bindgen...
[INFO]: Optimizing wasm binaries with `wasm-opt`...
Error: failed to execute `wasm-opt`: exited with signal: 11
full command: "/home/runner/.cache/.wasm-pack/wasm-opt-4d7a65327e9363b7/wasm-opt" "/home/runner/work/connect-four-webai/connect-four-webai/pkg/connect_four_bg.wasm" "-o" "/home/runner/work/connect-four-webai/connect-four-webai/pkg/connect_four_bg.wasm-opt.wasm" "-O"
To disable `wasm-opt`, add `wasm-opt = false` to your package metadata in your `Cargo.toml`.
When attaching the debug flag '-d' to wasm-opt the debut output is
(...)
[PassRunner] running pass: dae-optimizing... 0.0730599 seconds.
[PassRunner] (validating)
[PassRunner] running pass: inlining-optimizing... Error: failed to execute `wasm-opt`: exited with signal: 11
full command: "/home/ht/.cache/.wasm-pack/wasm-opt-4d7a65327e9363b7/wasm-opt" "/mnt/c/Users/HT/CLionProjects/connect-four-node/pkg/connect_four_bg.wasm" "-o" "/mnt/c/Users/HT/CLionProjects/connect-four-node/pkg/connect_four_bg.wasm-opt.wasm" "-O" "--debug" "--enable-mutable-globals"
To disable `wasm-opt`, add `wasm-opt = false` to your package metadata in your `Cargo.toml`.
The behavior is independent of the used optimization level and only occurs on linux (tested on Ubuntu 20.04.1 LTS). Builds on Windows work fine.
🤔 Expected Behavior
The behavior on Linux and Windows should be the same and without an error.
👟 Steps to reproduce
The issue seems to only occur with one specific method accessing an array of Options. The minimum code to reproduce is given here:
test.rs:
use wasm_bindgen::prelude::*;
pub const BOARD_WIDTH: usize = 7;
pub const BOARD_HEIGHT: usize = 6;
#[wasm_bindgen]
pub struct GameBoard {
fields: [[Option<FieldType>; BOARD_HEIGHT]; BOARD_WIDTH],
}
#[wasm_bindgen]
impl GameBoard {
pub fn empty_fields(&self) -> u8 {
let mut empty = 0;
for x in 0..7 {
for y in 0..6 {
if self.fields[x][y] == None {
empty = empty + 1;
}
}
}
return empty;
}
}
#[wasm_bindgen]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum FieldType {
Opponent,
Player
}
The error only occurs when an option is used. When using an array with just the "raw" FieldType the code runs just fine.
🌍 Your environment
Include the relevant details of your environment. wasm-pack version: 0.9.1 rustc version: Tested with rustc 1.50.0 (cb75ad5db 2021-02-10) and rustc 1.53.0-nightly (07e0e2ec2 2021-03-24) on x86_64-unknown-linux-gnu
I also seem to get this error when using serde to serialize an Option<Vec<T>>
Reinstalling wasm-pack
did the trick for me:
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh