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

Cannot wasm-pack build when using a js_sys array method (filter or map)

Open Nicolas-B-Braincube opened this issue 1 year ago • 2 comments

Describe the Bug

When I run wasm-pack build --target web --release build fails if I use an Array method like filter or map (I havn't tried other methods). The strange part is that wasm-pack build --target web --dev runs perfectly

Cargo.toml

[package]
name = "transforms-wasm"
version = "0.1.0"
authors = ["Nicolas Bruère <[email protected]>"]
edition = "2018"

[lib]
crate-type = ["cdylib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2.93"
js-sys = "0.3.70"

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.7", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.43"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

lib.rs

#[wasm_bindgen]
pub fn get_histogram(input: &Array, binsize: f64, min: f64, max: f64, dimension: i32) -> Array {
    let output = Array::new();

    let mut i = min;
    while i <= max {
        let arr = Array::new();
        arr.push(&JsValue::from_f64(i));
        let count = input.filter(&mut |item, _, _| {
            let row = Array::from(&item);
            let o = row.at(dimension).as_f64().unwrap();
            if o >= i && o < (i + binsize) {
                return true;
            }
            false
        }).length();
        arr.push(&JsValue::from(count));
        output.push(&arr);
        i += binsize;
    }

    output
}

The error output:

[INFO]: ⬇️  Installing wasm-bindgen...
error: failed to generates bindings for adapter

Caused by:
    no function table found in module
Error: Running the wasm-bindgen CLI
Caused by: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit status: 1
  full command: "/Users/nicolas.bruere/Library/Caches/.wasm-pack/wasm-bindgen-507ae24572712ef8/wasm-bindgen" "/Users/nicolas.bruere/workspace/reco-explorer/transforms-wasm/target/wasm32-unknown-unknown/release/transforms_wasm.wasm" "--out-dir" "/Users/nicolas.bruere/workspace/reco-explorer/transforms-wasm/pkg" "--typescript" "--target" "web"

Steps to Reproduce

  1. Run wasm-pack build --target web --release => you get an error
  2. Run wasm-pack build --target web --dev => you get 0 error

https://we.tl/t-V6pMfd5I4B

Expected Behavior

I'd like to have the same behavior whether I'm building on dev or release. I'd be ok if both return an error since it might be a mistake I made ;)

Actual Behavior

The build command outputs an error on release mode and no errors on dev mode

Nicolas-B-Braincube avatar Sep 18 '24 13:09 Nicolas-B-Braincube