wit-bindgen icon indicating copy to clipboard operation
wit-bindgen copied to clipboard

suggestion: add DO NOT EDIT comment to generated bindings files

Open ricochet opened this issue 3 years ago • 2 comments

Generated bindings files should indicate that they are generated with an auto-generated DO NOT EDIT comment at top of the file. This is not needed for Rust, but any language like c where the bindings are part of the project should have this comment.

// Code generated by wit-bindgen DO NOT EDIT.
// Version: 
// Revision: 
// Build Date: 
// Built By: 

Many editors recognize this string and warn when editing the file. Many tools include build-level information for triage. This might be especially useful for wit-bindgen while breaking changes are still frequent.

ricochet avatar Jul 21 '22 19:07 ricochet

:+1: to adding comments to the generated bindings.

I'm curious about the need for Version/Revision/Build Date/Built By fields. At first glance, it seems like version-control systems do a good job of tracking this information already.

sunfishcode avatar Jul 21 '22 20:07 sunfishcode

I included this snippet from what I've seen when the generator is a CLI and not managed as a dependency, e.g. not in go.mod/go.sum, Cargo.toml, etc.

go-enum is an example: https://github.com/abice/go-enum/blob/8268238fd705b39d430e7d8682b527af8452b6ab/generator/enum.tmpl#L1-L6

So if wit-bindgen were run as a CLI because it was provided as a globally installed tool in a build container, the version used might not be captured in git.

To be honest, most of those fields seemed redundant to me, but I figured I'd drop the superset of what I've seen and we can pick from that.

ricochet avatar Jul 26 '22 19:07 ricochet

This has been fixed by #490; it appears GitHub didn't auto-close this issue.

philpax avatar Mar 03 '23 13:03 philpax