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

Go: ergonomics improvement for types, function and package name #626

Open
Tracked by #499
Mossaka opened this issue Jul 20, 2023 · 2 comments
Open
Tracked by #499

Go: ergonomics improvement for types, function and package name #626

Mossaka opened this issue Jul 20, 2023 · 2 comments
Labels
gen-tinygo Related to the TinyGo bindings generator

Comments

@Mossaka
Copy link
Member

Mossaka commented Jul 20, 2023

This issue is created for a discussion on improving how types, function and package named in the Go bindgen.

To see how the current names is generated, please read the head of this #612 (comment).

A summary of what's being proposed: #612 (comment)

@Mossaka Mossaka added the gen-tinygo Related to the TinyGo bindings generator label Jul 20, 2023
@ydnar
Copy link

ydnar commented Sep 23, 2023

Some thoughts on this, from discussions at Wasmcon, and my work on the Go bindings generator:

Worlds vs Interfaces

We need to clarify if a Go program will presume an entire WASI world, or can link to individual packages or interfaces.

For example, will a Go program require the host implement the wasi:cli command world? Or be able to link to and use its constituent parts, e.g. wasi:clocks/monotonic, or wasi:random?

Names

As @Mossaka and others have pointed out, the current names generated by wit-bindgen can be long and cumbersome. I think it makes sense to map the WASI package name + interface into a Go package path, e.g.:

  • wasi:clocks/monotonic-clock<prefix>/wasi/clocks/monotonic-clock

Therefore the type wasi:clocks/monotonic-clock.instant would map to the Go type <prefix>/wasi/clocks/monotonic-clock.Instant.

Second, I think it makes sense to introduce a mapping of WASI names to Go names. This could be specified as command-line arguments to the Go code generator, or loaded from a config file. For example:

  • wasi:clocks/monotonic-clock<prefix>/wasi/clocks/monotonic (omitting the -clock suffix)
  • wasi:clocks/wall-clock.datetime<prefix>/wasi/clocks/wall.DateTime (explicitly naming a type)

Package path mapping would allow generated code to be placed in an internal directory, so the package author has control over the exported interface, say mapping WASI semantics to Go semantics (e.g. net/http interfaces). This would have the advantage of allowing the Go code generation to iterate without breaking external compatibility for dependent packages.

Stdlib

@achille-roussel pointed out that the requirements for codegen in the Go stdlib may differ materially, such as the number and names of generated Go packages, and how to make tradeoffs between simple vs clever or idiomatic vs performant.

@ydnar
Copy link

ydnar commented Feb 23, 2024

Follow up to previous comment, we now have working Go bindings generated from WIT:

https://pkg.go.dev/github.com/ydnar/wasm-tools-go/wasi

wit-bindgen-go can generate Go bindings from WIT:

wit-bindgen-go generate ./path/to/wasi-cli/wit # if wasm-tools is in path

Or:

wasm-tools component wit -j ./path/to/wasi-cli/wit | wit-bindgen-go generate

These are currently being used in a wasip2 port of TinyGo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gen-tinygo Related to the TinyGo bindings generator
Projects
None yet
Development

No branches or pull requests

2 participants