rustwasm / wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript
https://rustwasm.github.io/docs/wasm-bindgen/
Apache License 2.0
7.86k stars 1.08k forks source link

wasm-bindgen 0.2.15 fails to produce JS bindings #612

Closed roddyaj closed 6 years ago

roddyaj commented 6 years ago

wasm-bindgen 0.2.14 works fine, but switching to 0.2.15 produces no Javascript bindings. The following is a simplified example:

Cargo.toml:

[package]
name = "rust_bucket"
version = "0.1.0"
authors = ["Adam Roddy <aroddy@mail.com>"]

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

[dependencies]
wasm-bindgen = "=0.2.15"

src/lib.rs:

#![feature(wasm_custom_section, wasm_import_module, use_extern_macros)]

extern crate wasm_bindgen;

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn do_nothing() {}

I'm building with: cargo +nightly build --release --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/release/rust_bucket.wasm --out-dir target

With wasm-bindgen = "=0.2.14" I get target/rust_bucket.js that contains the function as expected:

import * as wasm from './rust_bucket_bg';

/**
* @returns {void}
*/
export function do_nothing() {
    return wasm.do_nothing();
}

With wasm-bindgen = "=0.2.15" I get target/rust_bucket.js:

/* tslint:disable */

That's the whole file. Note there is no binding function.

fitzgen commented 6 years ago

If you remove the wasm_custom_section, wasm_import_module features, does it work?

Are you on the latest nightly rust? rustup update nightly

fitzgen commented 6 years ago

If you remove the wasm_custom_section, wasm_import_module features, does it work?

(Because these should not be necessary anymore.)

alexcrichton commented 6 years ago

Additionally, you may want to make sure that wasm-bindgen --version (the CLI tool version) matches the wasm-bindgen crate version in Cargo.toml (if they're mismatched it can cause bugs)

roddyaj commented 6 years ago

I ran rustup update nightly and I'm on 1.29.0-nightly. I've now removed wasm_custom_section, wasm_import_module features. I still see the error. I am, however, on wasm-bindgen 0.2.14 according to wasm-bindgen --version (even after I run cargo update -p wasm-bindgen). Is there a better way to update wasm-bindgen, and is updating wasm-bindgen by hand just part of the workflow?

alexcrichton commented 6 years ago

@roddyaj can you try running cargo install -f wasm-bindgen-cli to see if it fixes the error for you? Eventually all this version juggling will be handled by wasm-pack so this sort of error should be a thing of the past!

roddyaj commented 6 years ago

OK thank you that fixed it!