Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wit/bindgen: add Version constant #81

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions wit/bindgen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down