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

Name conflict when a struct is called "Context" #1249

Closed
dbrgn opened this issue Feb 13, 2019 · 7 comments
Closed

Name conflict when a struct is called "Context" #1249

dbrgn opened this issue Feb 13, 2019 · 7 comments

Comments

@dbrgn
Copy link
Contributor

dbrgn commented Feb 13, 2019

As discussed in #1242: I'm getting the following error when a struct is called Context when calling wasm-pack test --headless --firefox:

  [3/6] Compiling tests to WASM...
     Compiling compose-area v0.1.0 (/home/danilo/Projects/compose-area)
  error: linking with `rust-lld` failed: exit code: 1
    |
    = note: "rust-lld" "-flavor" "wasm" "--no-threads" "-z" "stack-size=1048576" "--stack-first" "--allow-undefined" "--no-entry" "--fatal-warnings" "--export-dynamic" "--no-
    = note: rust-lld: error: duplicate symbol: __wbg_context_free
            >>> defined in /home/danilo/Projects/compose-area/target/wasm32-unknown-unknown/debug/deps/libcompose_area.rlib(compose_area.1zjlr9g8cstvtdrr.rcgu.o)
            >>> defined in /home/danilo/Projects/compose-area/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen_test-258015b5016fb118.rlib(wasm_bindgen_test-258015b501

Probably a name mangling issue.

@alexcrichton
Copy link
Contributor

Thanks again for spinning this off!

This is actually somewhat difficult to support now that I think about it. Right now all the exports from Rust are generated into a flat namespace in JS, so this is actually a legitimate namespace conflict. I'm not sure we can really support duplicate-ly named types in separate crates being linked together because we wouldn't know what to call the names in JS!

What I do think, however, is that the test framework should be using less common names :)

@dbrgn
Copy link
Contributor Author

dbrgn commented Feb 14, 2019

Do we have access to the source crate of a symbol? Maybe that could be integrated into the name?

@alexcrichton
Copy link
Contributor

We do! All that would end up with though is a better error message here, which is certainly an improvement! I'm nto sure we could actually allow this still

@alexcrichton
Copy link
Contributor

I've posted a rename for our own Context in #1280

@dbrgn
Copy link
Contributor Author

dbrgn commented Feb 20, 2019

Thank you!

Feel free to close this issue, unless it should stay open to discuss further namespacing / name mangling.

@alexcrichton
Copy link
Contributor

Ok I think in that case I'll go ahead and close

@dimitri-lenkov
Copy link

Thank you so much for this comment --- it got me unstuck.

I found this issue when looking up "wasm_bindgen duplicate symbol".

In my particular case, I have multiple crates in a cargo workspace that followed similar strut & method naming patterns, e.g. both workspace crates "foo" and "bar" had structs with names and methods like this:

impl Consume {
   //  . . .

   #[wasm_bindgen]
   pub fn start(/* ... */) {}
}

and the solution was to re-name the structs to be "crate specific", e.g. FooConsume and BarConsume respectively. By doing this, the generated symbol names would be *_foo_consume_start & *_bar_consume_start instead of the duplicate-ly generated name *_consume_start.


I'm not sure we can really support duplicate-ly named types in separate crates being linked together because we wouldn't know what to call the names in JS!

As a complete noob: Is it possible for #[wasm_bindgen] to automatically shove-in the current crate's name into the link_name to help "mangle" the name a bit more? wasm_bindgen is still sort of voo-doo magic for me lol.

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

No branches or pull requests

3 participants