willygroup opened Issue #2726:
Hi,
I'm pretty new to the whole rust/wasm world.
I'm passing to rust host from rust wasm function that returns a simple struct.
I'm compiling with cargo and the target wasm32-unknown-unknown.
I saw that when I check the module exports this function get an extra arguments... making some guessing I find out that is the memory pointer for the return struct...I cannot find out some documentation for this behaviour... someone can please address me to the right direction?
Thanks a lot :smiling_face:
bjorn3 commented on Issue #2726:
making some guessing I find out that is the memory pointer for the return struct...
Correct
I cannot find out some documentation for this behaviour... someone can please address me to the right direction?
Apart from reading the source of rustc and LLVM there isn't really for wasm32-unknown-unknown. Probably the best description is https://github.com/rust-lang/rust/pull/81388#issuecomment-767438600. For wasm32-unknown-emscripten and wasm32-wasi, the official C abi for wasm is followed, but for wasm32-unknown-unknown this is not the case. By accident LLVM was allowed to do it's own abi adjustments and now it can't be changed anymore without breaking wasm-bindgen. (source: I broke it by accident a while ago by doing something that prevented LLVM from doing it's own abi adjustments.)
alexcrichton commented on Issue #2726:
The C ABI for the wasm32 target is currently documented at https://github.com/WebAssembly/tool-conventions/blob/master/BasicCABI.md, although the Rust ABI for wasm32-unknown-unknown differs from Clang for historical reasons. Using the wasm32-wasi target, however, the ABIs will be the same.
alexcrichton closed Issue #2726:
Hi,
I'm pretty new to the whole rust/wasm world.
I'm passing to rust host from rust wasm function that returns a simple struct.
I'm compiling with cargo and the target wasm32-unknown-unknown.
I saw that when I check the module exports this function get an extra arguments... making some guessing I find out that is the memory pointer for the return struct...I cannot find out some documentation for this behaviour... someone can please address me to the right direction?
Thanks a lot :smiling_face:
willygroup commented on Issue #2726:
Ok!
Thanks a lot for your work!! :-)
Last updated: Dec 23 2024 at 12:05 UTC