$
cloc vorbis/
Language files blank comment code
C/C++ Header 6 192 497 578
$
c-for-go vorbis.yml
processing vorbis.yml...
done in 304.657793ms
$
cloc vorbis/
Language files blank comment code
Go 5 315 288 1780
C/C++ Header 6 192 497 578
$
Start by creating an YAML manifest file like vorbis.yml for the C library you want to use: this includes specifying the resulting package name, description, license and options respected by cgo.
Read more about generator preferences in generator config section docs.
Add a section specifying C header parsing parameters, usually you won’t need too much here, just write down the list of import paths and the list of header files, all the includes will be resolved automatically.
Read more about parser preferences in parser config section docs.
This is the section where all the magic happens. In short, here go all the name translation options, type hints for structs and functions, matching rules based on regular expressions. Despite looking simple for small libraries, this section assembles a powerful binding engine for large projects like CMU PocketSphinx or Vulkan Graphics API.
Read more about translator preferences in translator config section docs.
$ c-for-go vorbis.yml
We just automatically created vorbis, a Go package with cross-referenced GoDoc. Check out how it can be used in a high-level Ogg/Vorbis decoder package and try a demo vorbis-player. Neat, isn’t it?