Skip to content

support //go:wasmimport or a similarly named alias for imported functions #3147

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

Closed
codefromthecrypt opened this issue Sep 9, 2022 · 6 comments
Labels
enhancement New feature or request wasm WebAssembly

Comments

@codefromthecrypt
Copy link
Contributor

Let's support //go:wasmimport or a similarly named alias for imported functions. This would be an alias to //export, so that existing code can work, but much more intuitive. By being more intuitive, new users have a better experience, and we have less load on issues as well less angst on support.

Background

Currently, users need to add the keyword //export in order to import a function (ex from the wasm host).

ex.

//go:wasm-module env
//export log
func _log(ptr uint32, size uint32)

This is very unintuitive and provides a bad first time experience for TinyGo users. It also occupies many issues and in doing so steals time from folks contributing support. A couple examples are #3000 and #455, but there are many more occurrences than this, including my personal first experience.

As far as I understand the history from @aykevl,

"Export" in this case really means "make available to C" - either as a declaration or a definition.

I would argue that this can be true, but jargon that doesn't match is also more confusing than re-use of some C related jargon in Go. Many Go developers won't think through like this, hence the continual support questions.

More background could be that Go didn't have an import keyword. For example, In Go, you need to define a .s file then use a CallImport instruction there. The point remains that it also uses the word import not export for this.
https://github.com/golang/go/blob/master/src/syscall/js/js_js.s#L63-L65

However, if you look at the latest on Go, golang/go#38248, it appears //go:wasmimport would be used, not //export, for importing functions.

@fgsch
Copy link
Contributor

fgsch commented Sep 9, 2022

fwiw, TinyGo also supports //go:export, which is what //export is rewritten to.

@james-lawrence
Copy link

minor note that a guide should include a end to end example of a module exporting a function, another module importing it, and then executing the resulting modules. something along this line.

@codefromthecrypt
Copy link
Contributor Author

@james-lawrence forked an issue for your above comment so it doesn't end up lost. This example can be made now and syntax changed later (among the other ones) #3154

@aykevl
Copy link
Member

aykevl commented Sep 15, 2022

I missed the fact that //go:wasmimport is now accepted upstream. This means we're free to use it.
I made a PR to add support for it: #3165

Long term, I'd also like to change the behavior of //export so it isn't a wasm export, and instead use a //go:wasmexport or something similar. But there is a much greater risk at incompatibility with that with the upstream Go toolchain, so I'm not entirely sure about it. (Of course, there will be a transition period for such a rather big change).

@deadprogram deadprogram added enhancement New feature or request wasm WebAssembly labels Nov 2, 2022
@deadprogram deadprogram added the next-release Will be part of next release label Mar 22, 2023
@deadprogram
Copy link
Member

#3165 was merged into dev branch, so marking this issue for next release.

@deadprogram
Copy link
Member

This was completed as part of release v0.28 so now closing. Thanks!

@deadprogram deadprogram removed the next-release Will be part of next release label Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wasm WebAssembly
Projects
None yet
Development

No branches or pull requests

5 participants