Skip to content

Use WASI instead of CommonWA #423

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
CryZe opened this issue Jun 26, 2019 · 10 comments
Closed

Use WASI instead of CommonWA #423

CryZe opened this issue Jun 26, 2019 · 10 comments
Labels
enhancement New feature or request

Comments

@CryZe
Copy link

CryZe commented Jun 26, 2019

CommonWA was an initial prototype of what turned into the official WASI specification. It seems like tinygo is still using CommonWA. The runtime should probably be adjusted to use WASI, with maybe an optional switch back to CommonWA, if anyone still wants to keep using that.

@aykevl aykevl added the enhancement New feature or request label Jun 26, 2019
@aykevl
Copy link
Member

aykevl commented Jun 26, 2019

This is something we will eventually want, certainly. The switch isn't trivial, though: we will need a bit of compiler support because wasi uses a different WebAssembly namespace and LLVM (wasm-ld?) by default puts unknown functions in the env namespace.

@CryZe
Copy link
Author

CryZe commented Jun 26, 2019

It seems like it's just a matter of annotating the function with a "wasm-import-module" attribute in the LLVM IR. https://rust.godbolt.org/z/m0PI1z

@CryZe
Copy link
Author

CryZe commented Jun 27, 2019

Seems like it's mostly a matter of parsing a //go:wasm-import-module xyz here

tinygo/ir/ir.go

Line 292 in da85710

case "//go:export":

and then similar to here

tinygo/compiler/compiler.go

Lines 840 to 845 in da85710

switch frame.fn.Inline() {
case ir.InlineHint:
// Add LLVM inline hint to functions with //go:inline pragma.
inline := c.ctx.CreateEnumAttribute(llvm.AttributeKindID("inlinehint"), 0)
frame.fn.LLVMFn.AddFunctionAttr(inline)
}

use

wasmImportModuleAttr := c.ctx.CreateStringAttribute("wasm-import-module", frame.fn.WasmImportModule)
frame.fn.LLVMFn.AddFunctionAttr(wasmImportModuleAttr)

@aykevl
Copy link
Member

aykevl commented Jun 27, 2019

Yes, something like that will be needed.
I'm busy working on other things right now, but if you could help with such a pragma that would help.

@scriptonist
Copy link
Contributor

If nobody is working on this, I can maybe give it a try :)

@CryZe
Copy link
Author

CryZe commented Jul 12, 2019

Sure, feel free to work on it. 👍

@deadprogram
Copy link
Member

Code that adds //go:wasm-module has now landed in the dev branch.

@deadprogram
Copy link
Member

The //go:wasm-module directive is now part of TinyGo 0.8.0 release.

@est31
Copy link

est31 commented Oct 2, 2019

@CryZe I wonder what's needed next.

@deadprogram
Copy link
Member

We are using WASI now, so I think this issue can be closed. Please reopen if I am mistaken. Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants