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

WebAssembly FFI uses extern "C" #47599

Closed
sdroege opened this issue Jan 19, 2018 · 3 comments
Closed

WebAssembly FFI uses extern "C" #47599

sdroege opened this issue Jan 19, 2018 · 3 comments
Labels
A-ffi Area: Foreign Function Interface (FFI) C-enhancement Category: An issue proposing an enhancement or a PR with one. O-wasm Target: WASM (WebAssembly), http://webassembly.org/

Comments

@sdroege
Copy link
Contributor

sdroege commented Jan 19, 2018

While reading https://hacks.mozilla.org/2018/01/oxidizing-source-maps-with-rust-and-webassembly/ I noticed the following

it is marked extern "C" so that it is publicly exported in the final .wasm file.

Shouldn't this be extern "WASM" or similar? The FFI interface is not the C one, but the WebAssembly one (or JavaScript?)

@fitzgen
Copy link
Member

fitzgen commented Jan 19, 2018

Discussion is also happening over at rustwasm/team#29

@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-ffi Area: Foreign Function Interface (FFI) O-wasm Target: WASM (WebAssembly), http://webassembly.org/ labels Jan 21, 2018
@alexcrichton
Copy link
Member

This is now unlikely to change at this point, so I'm going to close this. We've chosen "C" for compatibility with mixing C/Rust in the same module.

@webmaster128
Copy link

Does this imply that a Wasm import cannot use multiple return values? Or is this a to-be-silenced linter issue?


What I try to do is

extern {
    fn db_next(iterator_id: u32) -> (u32, u32);
}

which gets formatted to

extern "C" {
    fn db_next(iterator_id: u32) -> (u32, u32);
}

which clippy complains about:

warning: `extern` block uses type `(u32, u32)`, which is not FFI-safe
  --> packages/std/src/imports.rs:43:37
   |
43 |     fn db_next(iterator_id: u32) -> (u32, u32);
   |                                     ^^^^^^^^^^ not FFI-safe
   |
   = note: `#[warn(improper_ctypes)]` on by default
   = help: consider using a struct instead
   = note: tuples have unspecified layout

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-enhancement Category: An issue proposing an enhancement or a PR with one. O-wasm Target: WASM (WebAssembly), http://webassembly.org/
Projects
None yet
Development

No branches or pull requests

5 participants