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

tests fail if start attribute is present #2206

Closed
Urhengulas opened this issue Jun 16, 2020 · 4 comments
Closed

tests fail if start attribute is present #2206

Urhengulas opened this issue Jun 16, 2020 · 4 comments
Labels

Comments

@Urhengulas
Copy link

Describe the Bug

Testing of wasm-bindgen lib fails if #[wasm_bindgen(start)] is present (for both browser and node).

Error Message
$ wasm-pack test
[INFO]: Checking for the Wasm target...
   Compiling rav1e_js v0.1.0 (/home/urhengulas/Documents/github.com/xiph/rav1e/rav1e_js)
error: linking with `rust-lld` failed: exit code: 1

### ----- stripped ----- ###

  = note: rust-lld: error: function signature mismatch: main
          >>> defined as () -> void in /path/to/rav1e/target/wasm32-unknown-unknown/debug/deps/librav1e_js.rlib(rav1e_js.e16cnisiuzwaayg.rcgu.o)
          >>> defined as (i32, i32) -> i32 in /path/to//rav1e/target/wasm32-unknown-unknown/debug/deps/web-17ed0dcdfd20c376.2kwhsv3emygdoj04.rcgu.o

### ----- stripped ---- ###

error: entry symbol `main` declared multiple times
  |
  = help: did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead

error: aborting due to previous error

error: could not compile `rav1e_js`.

### ----- stripped ----- ###

Caused by: failed to execute `cargo build`: exited with exit code: 101
  full command: "cargo" "build" "--tests" "--target" "wasm32-unknown-unknown"

Steps to Reproduce

# 1. clone repo
git clone https://github.com/Urhengulas/rav1e.git
# 2. checkout commit
git checkout 46283554cfc093fb6721557068b3242794544226
# 3. go into subfolder
cd rav1e_js/
# 4. run tests
wasm-pack test --node

Expected Behavior

I expect wasm-pack test --node to run all wasm-bindgen tests for node.

And since the wasm-bindgen books says here:

The start function will not be executed when testing.

I also expect it to not be executed. (Maybe not even part of the build).

Actual Behavior

The command fails and doesn't run any tests.

Additional Context

wasm-pack build runs without any problems and also the pkg/ works.

@Urhengulas Urhengulas added the bug label Jun 16, 2020
@alexcrichton
Copy link
Contributor

This says that main is defined multiple times in two crates, which I think is unrelated to #[wasm_bindgen(start)]? Can you see why the main symbol is defined twice?

@Urhengulas
Copy link
Author

Thanks for the fast answer @alexcrichton.

No, I didn't define the #[wasm_bindgen(start)] twice.
I now solved the issue by renaming the function I annotated with the attribute from main to main_js.

I got the hint from rust-gamedev/wg#51:

wasm-bindgen doesn't currently support main - you have to use the wasm_bindgen(start) attribute on a public function instead, and that function can't be main

I couldn't find a reason why this solves the problem, but it does.

I will send a PR changing this in the example in the rust-bindgen book.

@alexcrichton
Copy link
Contributor

Ok thanks for the follow-up! It sounds like this isn't a bug in wasm-bindgen so I'm going to close this.

@nstoddard
Copy link
Contributor

I just encountered this issue, and the workaround of renaming main to main_js fails for me with the error <path to output file>.wasm: Syntax error: end of file unexpected. Everything works fine when building normally; the issue only occurs with cargo test.

Is there another workaround? Does anyone know if this is a bug in rustc, cargo, or wasm-bindgen?

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

3 participants