Skip to content

WebAssembly FFI uses extern "C" #47599

Closed
Closed

Description

@sdroege

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?)

Activity

  1. fitzgen commented on Jan 19, 2018

    @fitzgen
    Member

    Discussion is also happening over at rustwasm/team#29

  2. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    A-FFIArea: Foreign function interface (FFI)
    O-wasmTarget: WASM (WebAssembly), http://webassembly.org/
    on Jan 21, 2018
  3. alexcrichton commented on Dec 16, 2019

    @alexcrichton
    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.

  4. webmaster128 commented on Oct 27, 2020

    @webmaster128

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)C-enhancementCategory: An issue proposing an enhancement or a PR with one.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions