Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Nicolas-B-Braincube opened this issue Sep 18, 2024 · 2 comments
Labels

Comments

@Nicolas-B-Braincube
Copy link

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

@daxpedda
Copy link
Collaborator

For whatever reasons, all references to these functions are removed by some pre-processing done in wasm-bindgen, which then asks Walrus to do some cleanup in which this table is removed.

This would require some digging into to find out exactly what is being removed here and why.

@Nicolas-B-Braincube
Copy link
Author

Thank you for your answer @daxpedda 👍 I'm sorry I'm not comfortable enough in Rust to do this digging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants