diff --git a/wit/bindgen/generator.go b/wit/bindgen/generator.go index 9943f794..a364b56b 100644 --- a/wit/bindgen/generator.go +++ b/wit/bindgen/generator.go @@ -248,6 +248,14 @@ func (g *generator) defineWorld(w *wit.World) error { file.PackageDocs = b.String() } + if w.Package.Name.Version != nil { + var b bytes.Buffer + v := file.DeclareName("Version") + stringio.Write(&b, "// ", v, " represents the version of WIT package \"", w.Package.Name.String(), "\".\n") + stringio.Write(&b, "const ", v, " = \"", w.Package.Name.Version.String(), "\"\n\n") + file.Write(b.Bytes()) + } + for _, name := range codec.SortedKeys(w.Imports) { var err error switch v := w.Imports[name].(type) { @@ -292,6 +300,14 @@ func (g *generator) defineInterface(i *wit.Interface, name string) error { file.PackageDocs = b.String() } + if i.Package.Name.Version != nil { + var b bytes.Buffer + v := file.DeclareName("Version") + stringio.Write(&b, "// ", v, " represents the version of WIT package \"", i.Package.Name.String(), "\".\n") + stringio.Write(&b, "const ", v, " = \"", i.Package.Name.Version.String(), "\"\n\n") + file.Write(b.Bytes()) + } + // Define types for _, name := range codec.SortedKeys(i.TypeDefs) { g.defineTypeDef(i.TypeDefs[name], name)