Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't handle multiple output using wasmer. #1067

Closed
AchalaSB opened this issue Dec 16, 2019 · 11 comments
Closed

Can't handle multiple output using wasmer. #1067

AchalaSB opened this issue Dec 16, 2019 · 11 comments

Comments

@AchalaSB
Copy link

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
@AchalaSB AchalaSB added the 🎉 enhancement New feature! label Dec 16, 2019
@danaugrs
Copy link

Looking forward to Wasmer integrating the multi-value proposal! Any updates on this?

@Hywan
Copy link
Contributor

Hywan commented Jan 20, 2020

We are working on it. It should land soon :-).

@Hywan Hywan self-assigned this Jan 20, 2020
@AchalaSB
Copy link
Author

AchalaSB commented Mar 15, 2020

@syrusakbary @Hywan
Any update on this? as Multi value return reached to phase4

@diegobes
Copy link

In which branch is the work in progress ?

@nlewycky
Copy link
Contributor

feature/multi-value-return

@syrusakbary
Copy link
Member

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:

cranelift #1178 (comment).

@syrusakbary
Copy link
Member

This should be solved in the refactor :)

@AchalaSB
Copy link
Author

AchalaSB commented Aug 3, 2020

@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

@mikevoronov
Copy link
Contributor

mikevoronov commented Aug 3, 2020

@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

@AchalaSB
Copy link
Author

AchalaSB commented Aug 5, 2020

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

@syrusakbary
Copy link
Member

Closing issue since multivalues is now fully supported in Wasmer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants