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

Wasm: #[no_mangle] for root level items in leaf crates #46294

Closed
est31 opened this issue Nov 27, 2017 · 3 comments
Closed

Wasm: #[no_mangle] for root level items in leaf crates #46294

est31 opened this issue Nov 27, 2017 · 3 comments
Labels
A-ffi Area: Foreign Function Interface (FFI) C-feature-request Category: A feature request, i.e: not implemented / a PR. O-wasm Target: WASM (WebAssembly), http://webassembly.org/

Comments

@est31
Copy link
Member

est31 commented Nov 27, 2017

All the inline usages of Rust in js that I have seen have this #[no_mangle] attribute added to each function.

E.g. see this example by @killercup , or this one by browserify.

I haven't coded any hybrid js+wasm yet, but to me it seems that having to specify the #[no_mangle] attribute in order to access wasm module exports via the exports function at their original name is a bit of a boilerplate.

So I wonder: can't we add a mode to rustc that allows you to omit the attribute?

Specifically, I would propose that there should be a -Z root-no-mangle (eventually -C) flag for rustc which automatically adds a #[no_mangle] attribute to any function marked pub that is in the root of the crate.

This flag could be added by cargo to the leaf crate, at least in cases where it compiles actual inline Rust. I'm not so sure about larger codebases that are not inlined.

A few points:

  • If Rust wants to become the "systems language of the web", the #[no_mangle] attribute stands in the way.
  • The Rust mangling system was designed with "Rust being used by Rust" in mind. For this, the system is perfect. It keeps the crates outside of each other's way. The only ones to spoil the fun are those native dependencies. Now "Rust being used by Javascript" is a novel use case and I think it deserves the adjustment in mangling patterns.
  • Yes, this might cause weird linker errors, e.g. if you include a native C library and it defines a symbol of the same name, but I think this error will be experienced later on, and also, everything should be pure Rust xD.
  • One can also think of scenarios where there is no leaf crate but instead js is using various functions from crates on crates.io directly. I think in these cases, there is no leaf crate and thus the flag won't be passed to any crate.
  • Possibly one can extend this feature to work on modules as well, aka levelling up the entire public API of the leaf crate by one level. I don't know much about wasm yet to tell whether this makes any sense.

cc @alexcrichton

@kennytm kennytm added A-ffi Area: Foreign Function Interface (FFI) C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Nov 27, 2017
@alexcrichton alexcrichton added the O-wasm Target: WASM (WebAssembly), http://webassembly.org/ label Nov 30, 2017
@fitzgen
Copy link
Member

fitzgen commented Jan 19, 2018

cc @rust-lang/wg-wasm

@koute
Copy link
Member

koute commented Jan 19, 2018

I think this is a reasonable request for the very specific usecase of putting inline Rust in JavaScript, however I probably wouldn't want such a behavior by default for consistency with other targets. (And arguably there could be usecases where we'd want to export mangled Rust symbols, e.g. when wasm dynamic linking lands depending on how it would work.)

@est31
Copy link
Member Author

est31 commented Jun 30, 2018

Hmm now that we have powerful bindgen like tools I think this is obsolete.

@est31 est31 closed this as completed Jun 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ffi Area: Foreign Function Interface (FFI) C-feature-request Category: A feature request, i.e: not implemented / a PR. O-wasm Target: WASM (WebAssembly), http://webassembly.org/
Projects
None yet
Development

No branches or pull requests

5 participants