Closed Urhengulas closed 4 years ago
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?
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 https://github.com/rust-gamedev/wg/issues/51:
wasm-bindgen doesn't currently support
main
- you have to use thewasm_bindgen(start)
attribute on a public function instead, and that function can't bemain
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.
Ok thanks for the follow-up! It sounds like this isn't a bug in wasm-bindgen so I'm going to close this.
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?
Describe the Bug
Testing of wasm-bindgen lib fails if
#[wasm_bindgen(start)]
is present (for both browser and node).Error Message
```bash $ 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
Expected Behavior
I expect
wasm-pack test --node
to run all wasm-bindgen tests for node.And since the wasm-bindgen books says here:
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 thepkg/
works.