Straight up generating the C# code as it is now is obviously a good first step, but I would love wit-bindgen to be more integrated with the .NET ecosystem and I believe that (incremental) source generators might be a direction worth exploring. A source generator would create a dev experience more similar to the bindgen!
macros in Rust where feedback about WIT files can be communicated directly through Roslyn.
It is still early, but I would love to hack a bit on this idea to see if it is possible and practical. I need a little bit of help to get started though. So I have a few questions:
1. Has there already been thinking/work done with using c# source generators for WIT files?
2. Could we reuse/integrate existing tooling such as wit-parser
or even wit-bindgen
directly? It might be a bit wasteful to implement a WIT parser in c# itself, but as far as I can see the existing tools don't extern
their interface so creating direct bindings seems out of the question for now.
Any further thoughts, ideas, or directions are welcome :)
There has been some work done on generating Go bindings from Go via a JSON-serialized form of parsed WIT: https://github.com/ydnar/wasm-tools-go which @Randy Reddig may be able to give insight on
That serialization isn't very friendly though; it is basically a dump of wit-parser's internal representation.
I have personally always liked the idea of a WIT interface for bindings generation so that generators could be written in any language, compiled to wasm, and executed by wit-bindgen as a harness, but I also haven't done any real work to make that dream a reality :smile:
The JSON representation isn’t simple, but it works well enough to recreate the original WIT syntax, and generate Go
The Go implementation might be a good place to start if you want to do a C# implementation
I’m contemplating running wasm-tools inside Go as a Wasm module to generate the JSON from WIT implicitly
Lann Martin said:
I have personally always liked the idea of a WIT interface for bindings generation so that generators could be written in any language, compiled to wasm, and executed by wit-bindgen as a harness, but I also haven't done any real work to make that dream a reality :smile:
I have had that thought as well haha.
Thanks for the directions, will give that go implementation a look.
C# source generators for WIT if it involves call outs to processes, e.g. wit-bindgen is not allowed, it was discussed here https://github.com/dotnet/runtimelab/issues/2377
As a small step forward, wit-bindgen-go can now exec wasm-tools to perform the WIT to JSON conversion under the hood: https://github.com/ydnar/wasm-tools-go/pull/51
Last updated: Nov 22 2024 at 17:03 UTC