I am interested in using Rust's WASM targets for some non-web-related uses and I need to know how the ABI works for the various WASM targets (specifically wasm32-wasi and wasm32-unknown-unknown). I have found people talking about bits and pieces of this, but I can't find any comprehensive documentation. Where is this documented? Specifically, I want to know how to translate an arbitrary #[repr(C)] struct and extern "C" function signature into what it will look like in wasmtime or wasmer when loading the compiled WASM module.
I don't know of any documentation either. Just that it's not the same as clang WebAssembly ABI mismatch between clang and rust · Issue #71871 · rust-lang/rust · GitHub
Except for wasm32-unknown-unknown all wasm targets follow https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md which is also used by Clang. For wasm32-unknown-unknown we forgot to implement this, so the effective ABI depends on implementation details of both LLVM and rustc. See also Tracking issue for the unstable "wasm" ABI · Issue #83788 · rust-lang/rust · GitHub For this reason I did recommend to avoid passing anything but the primitive types that wasm natively supports (u32/i32, u64/i64, f32, f64) and thin references/pointers (which are represented as i32 for wasm32 and as i64 for wasm64) as arguments and return value for wasm32-unknown-unknown. This only applies to the calling convention. For the memory layout AFAIK wasm32-unknown-unknown follows the BasicCABI document too.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.