Skip to content

compiler, runtime: enable go:wasmexport for wasip2 #4496

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
wants to merge 2 commits into from

Conversation

ydnar
Copy link
Contributor

@ydnar ydnar commented Oct 3, 2024

This builds on #4451 to enable //go:wasmexport for wasip2 (WASI Preview 2).

  • //go:wasmexport is now permitted and supersedes //go:export and //export if both are present.
  • The wasip2 target now defaults to -buildmode=c-shared, since all WASI 0.2+ programs are reactors.
  • main.main is called by the wasi:cli/run#run export in a wasmexport.

@ydnar ydnar requested a review from aykevl October 3, 2024 21:46
@ydnar ydnar self-assigned this Oct 3, 2024
@ydnar ydnar changed the base branch from dev to wasip1-c-shared October 3, 2024 21:46
@ydnar ydnar deleted the branch tinygo-org:wasip1-c-shared October 4, 2024 22:33
@ydnar ydnar closed this Oct 4, 2024
Comment on lines +18 to +21
wasi_run.Exports.Run = func() cm.BoolResult {
callMain()
return false
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, any reason not to use //export here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question! All exports defined in WIT should use //go:wasmexport, including the wiring up from wasi:cli/command#run to main.main. This is the standard pattern for wiring up exports generated from wit-bindgen-go.

  1. Developer generates Go (e.g. wasi:http/proxy)
  2. Developer writes Go library that wraps the low-level APIs in the generated code (e.g. a net/http compatible shim)
  3. In the shim code, developer assigns the relevant Exports struct field to their implementation. For example: https://github.com/ydnar/wasi-http-go/blob/76673aea4c888a0e9b36d20604b3f11a4831bdd8/wasihttp/server.go#L21-L24

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I believe //export should still be used for cabi_realloc since the Component Model defines different reentrancy rules for low-level exports like this.

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

Successfully merging this pull request may close these issues.

2 participants