Description
Summary
I was recommended by @joshtriplett to open a proposal for design meeting about the new extern "wasm"
ABI that I prototyped in rust-lang/rust#83763. This, if stabilized, would add a new ABI to Rust which is specifically for WebAssembly targets to facilitate authors in Rust to target precise WebAssembly signatures if they're either importing or exporting a function of that precise signature.
Background reading
There's quite a lot of possible background reading for this, but the details are generally relatively light with how they correspond to Rust. The motivation for this is a bit thorny, however. In order of increasing level of detail, some possible reading is:
- Description of rustc: Add a new
wasm
ABI rust#83763 - Historical problems around Rust's current wasm abi on the wasm32-unknown-unknown target Use correct ABI for wasm32 by default rust#79998
- More discussion about wasm and it's C ABI - Pass small structs in parameters instead of memory WebAssembly/tool-conventions#88 (comment)
- The current wasm C ABI - https://github.com/WebAssembly/tool-conventions/blob/master/BasicCABI.md
- The wasm specification - https://webassembly.github.io/spec/core/
- (basically just the bits about how functions can have lists of parameters and results and the various types they can take)
About this issue
The addition of a new "wasm" ABI is intended to solve a longstanding issue in Rust where the wasm32-unknown-unknown target's ABI does not match Clang, making interoperability of C and Rust code more difficult there. In addition to fixing this issue, though a long-lived "wasm" ABI is intended to provide the ability for authors in Rust to target specific WebAssembly signatures. When compiling to WebAssembly the function signature that comes out the other side is generally intuitive but can be a bit of a black-box in some regards. By providing a "wasm" ABI we give room for Rust to have its own definition of how Rust code will map onto generated WebAssembly code. (it's then up to rustc to figure out how to tell LLVM how to do that).