Skip to content

WIP: upstream wit-bindgen-go support - #5848

Draft
dgryski wants to merge 2 commits into
tinygo-org:devfrom
dgryski:dgryski/wit-bindgen-go
Draft

dgryski wants to merge 2 commits into
tinygo-org:devfrom
dgryski:dgryski/wit-bindgen-go

Conversation

@dgryski

@dgryski dgryski commented Oct 8, 2026

Copy link
Copy Markdown
Member

This PR depends on #5782 (LLVM 23) and #5507 (wasi-libc upgrade) and should not merge before them.

It makes the Go bindings from wit-bindgen go build and run with TinyGo. Two changes are needed.

compiler: allow //go:wasmimport functions as function values

Imports are marked as exported and use a different ABI, so using one as a function value was rejected. The generated bindings do this for stream and future vtables. An import used as a value is now wrapped in a Go ABI function that calls the import. Other exported functions are still rejected.

runtime: add Pinner

runtime.Pinner did not exist. The generated code pins memory it hands to the host so the GC does not free it between cabi_realloc calls. The GC does not move objects, so Pin only has to keep the object alive until Unpin. Pins are kept in a global map because the generated resource types embed a Pinner in the object they pin, and the host holds only an integer handle.

Not in this PR

go.bytecodealliance.org/pkg needs a separate change so that cabi_realloc does not call adapter_monotonic_clock_set_paused under TinyGo. That call re-enters the WASI adapter while it is still allocating its own state.

There will be further patches coming on this branch with wasip3 support.

Imports were rejected as function values because they are marked as
exported and use a different ABI. Wrap them in a Go ABI function that
calls the import instead. Other exported functions are still rejected.
The GC does not move objects, so Pin only needs to keep the object alive
until Unpin. The pins are kept in a global map. Generated bindings embed a
Pinner in the object they pin, so storing the pins in the Pinner itself would
let the GC free the object while only the host holds it.
@dgryski dgryski changed the title WIP: wasip3 support WIP: upstream wit-bindgen-go support Oct 8, 2026
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.

1 participant