bytecodealliance / wit-bindgen

A language binding generator for WebAssembly interface types
Apache License 2.0
988 stars 189 forks source link

Text Format (%.wat) generator #356

Open codefromthecrypt opened 1 year ago

codefromthecrypt commented 1 year ago

The wit format is neat in that it gives hints like string to make better language bindings. However, in the process, it can be confusing what the actual imports will be. This is especially confusing as there are a couple string-based proposals to the spec. It would be nice to be able to generate%.wat instead and use that as the gold copy (for those who prefer seeing the raw wasm signatures). If we had this feature, it would be less scary to use the higher level types, which are becoming more interesting.

alexcrichton commented 1 year ago

Do you have an example of what you'd like to see generated? I would naively interpret this as:

$ cat foo.wit
foo: func()
$ wit-bindgen guest wat --import foo.wit
(module 
    (import "foo" "foo" (func))
)

but I'm not sure if that's what you are thinking of? Or are you wondering to get the full component representation instead?

codefromthecrypt commented 1 year ago

yes! for starters non-componentized is great. meanwhile I was thinking to emit c and then wasm2wat the result ;)

codefromthecrypt commented 1 year ago

I think this is very important especially as modeling is fluid here. For example, it isn't intuitive that 64bit flag would be two fields, especially as wasm supports 64 bit and when used as a parameter two places is clunky. We need a way to know that decisions in markup will result in consistent wasm signatures, even if not enforced via wat. otherwise, we'll need another markup that can be trusted to not drift. as you can imagine, some may think of this as a spec document and if the representation changes without someone knowing, it fails at its primary purpose.

Maaarcocr commented 1 year ago

Do you have an example of what you'd like to see generated? I would naively interpret this as:

$ cat foo.wit
foo: func()
$ wit-bindgen guest wat --import foo.wit
(module 
    (import "foo" "foo" (func))
)

but I'm not sure if that's what you are thinking of? Or are you wondering to get the full component representation instead?

@alexcrichton That would be incredibly useful (especially if it spit out some wat I could link with other components written in rust, using wasmtime Linker). If one were to try to implement that, where would you suggest they start digging around? Any tips?

alexcrichton commented 1 year ago

This is actually already implemented here so the implementation here would be mostly to expose that in a package somewhere.

codefromthecrypt commented 1 year ago

@Maaarcocr I'm cool on your view of the outcome