Hi,
It would be nice if we are able to return multiple output from source code through wasmer.
(wasm is currenlty accepting single output and they are working on multi-value output)
Tryed to return multiple result using go-wasmer. Here is sample code
#[no_mangle]
pub extern fn test(x: i32, y: i32, z: i32) -> (i32, i32, i32) {
(x, y, z)
}
// try this since test function returning 0
#[no_mangle]
pub extern fn sub_main() -> (i32, i32, i32) {
test(5, 1, 3)
}
fn main() {}
When I try to call test function from wasmer
sum := instance.Exports["test"]
result, _ := sum(4, 5, 3)
It is returning result as 0. And if I call sub_main function
sum := instance.Exports["sub_main"]
result, _ := sum()
It is returning error
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4a2f15]
goroutine 1 [running]:
main.main()
/go-ext-plugin/wasmer-ext.go:21 +0x125
exit status 2
Looking forward to Wasmer integrating the multi-value proposal! Any updates on this?
We are working on it. It should land soon :-).
@syrusakbary @Hywan
Any update on this? as Multi value return reached to phase4
In which branch is the work in progress ?
feature/multi-value-return
The main reason this is taking a bit more than expected is because one of the backends that we are using (cranelift) doesn't handle well the System-V ABI for doing transparent native calls between the host and the wasm (without trampolines).
Here's the link if you would like to get more info:
This should be solved in the refactor :)
@syrusakbary I assume this issue has been resolved in the refactor. But I wanted to know
How rust to wasm compilation done for this?
cargo build --target=wasm32-unknown-unknown is the regular command for compilation. What is the command for this multi-value returns?
PN: with rustc it may possible but there I can't use any crates like i do in cargo build
@AchalaSB According to the docs: the environment variable RUSTFLAGS can be used to pass options for code generation to the Rust compiler. These flags will affect all compiled crates.
So
RUSTFLAGS="-C target-feature=+multivalue" cargo build --target=wasm32-unknown-unknown
can help you.
P.S. Also it may be usefull to use build.rustflags
@michaelvoronov Nope this command won't work.
I ran this for simple code
#[no_mangle]
pub extern fn test(x: i32, y:i32) -> (i32, i32){
(x+y , x-y)
}
but wasm file is broken, when I tries to open wasm file its shown errors
Unable to open 'testing.wasm': Unable to resolve text model content for resource wasm-preview:/home/achala/testing/target/wasm32-unknown-unknown/debug/testing.wasm.
Error while reading the Wasm: readWasm failed: 0000030: error: expected valid result type (got -0x20)
Closing issue since multivalues is now fully supported in Wasmer :)
Most helpful comment
Closing issue since multivalues is now fully supported in Wasmer :)