Is it possible to use .witx
definition files for Go code generation to use with TinyGo's WebAssembly WASI (WebAssembly System Interface) support?
Specifically, I want to create a Fastly Compute@Edge SDK for Go. These SDKs exist for JavaScript, AssemblyScript, Rust, Swift, and Zig, but not Go yet. This requires WebAssembly with WASI support which TinyGo has, but I haven't found any information on using WITX files yet.
To execute your Wasm applications on Compute@Edge (and the local testing server), you need to use our Compute@Edge hostcalls, which are defined at https://github.com/fastly/Viceroy/tree/main/lib/compute-at-edge-abi. These
.witx
files define the functionality of Compute@Edge. Use them with your chosen language's WASI tooling to generate stubs or interfaces for your custom SDK to implement.
The .witx
files are here:
Wasm by Example indicates that TinyGo can be used to target WASM with WASI support:
Let's compile our
main.go
into a Wasm module that targets WASI!This can be down with the
-wasm-abi=generic
and-target=wasi
flags when you run the TinyGo compiler:
tinygo build -wasm-abi=generic -target=wasi -o main.wasm main.go
Which should output (
-o
) amain.wasm
file that we can run in a WebAssembly runtime that supports WASI!
It seems that a Go code generator that reads .wtix
files and generates Go code is needed. Does one exist?
If not, it seems like the three approaches would be:
- Extend a common code generator with Go support, likely written in a different language. For example, WITX-CodeGen exists without Go support yet and is written in Rust. This would be like using the Java-based OpenAPI Generator to create Go REST API server stubs using OpenAPI Spec.
- Create a Go-based
.witx
code generator. This could be like the Go-based OAPI CodeGen for OpenAPI Spec. - Create the Go definitions manually, which would likely be a pre-cursor for either of the code gen approaches.