Generate Wrapper code that uses dlopen/dlsym

Merged Victor Toso requested to merge victortoso/libvirt-go-module:gen-dlopen into master

This MR introduces a gen/wrapper.go that takes libvirt's API schema (in XML) to generate cgo wrapper code to call libvirt library. The generated code can either link to libvirt library as we already do or it can use dlopen() and dlsym() to fetch libvirt's symbols at runtime.

The wrapper is using go templates to the actual generation code.

I've separated all C code that was added by hand in module_helper.c and module_helper.h files. All functions that belong to these files have the Helper suffix. Further explanation in the commit log a364648d "Add module_helper source and header files".

All the generated code are in module_generated.c, module_generated.h, module_generated_compat.h and module_generated_dlopen.h. Further explanation in the commit log 442fff95 "wrapper: Add CGO code generator"

Kubevirt's WIP MR is using this branch, building and linking to the installed libvirt version they have in their host.

Improvements and checks to be made:

  • Resolve FIXMEs /* FIXME: lxc and qemu shoudl be conditional include too */
  • Double check generated code for cosmetic changes (trailing white spaces, etc)

- [ ] Add a lock in the dlopen part to avoid increase of handler's refcount (in the context of multiple goroutines)

Edited by Victor Toso

Merge request reports