golang/go

How to expose a function with arguments for WebAssembly wasm generation?

thstart opened this issue · 3 comments

What version of Go are you using (go version)?

$ go version
go1.15.2

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOOS="darw"

What did you do?

package main

import "C"

//export Sum
func Sum(a, b int) int {
return a + b
}

func main() {
// We need the main function to make possible
// CGO compiler to compile the package as C shared library
}

What did you expect to see?

I want to expose the Sum function which accepts arguments in order to use it
in a non browser environment.

Currently there is no way to do that mucous only main() is exposed.

What did you see instead?

Please see #25612, #38248.

I will close this as a duplicate of those issues.

Please see #25612, #38248.

I will close this as a duplicate of those issues.

Thank you. I looked at the two links and looks like they are closed.
Could you please tell me what are the plans?
I have a real case - where to explain it with more details?

As of now, it's very difficult to achieve this without a major change as outlined in #38248. I think once wasi support arrives, this will be available.

You are welcome to comment on those issues if you have any suggestions.