AutomaticComponentToolkit icon indicating copy to clipboard operation
AutomaticComponentToolkit copied to clipboard

[cgo] CGo now is using dynamic loading - find a concept to dynamically/statically link the code

Open alexanderoster opened this issue 4 years ago • 3 comments

We are using cdynamic.cc headers at the moment for the cgo bindings. Is there a way to statically link the libraries with go?

alexanderoster avatar Jul 28 '20 07:07 alexanderoster

@qmuntal

alexanderoster avatar Jul 28 '20 07:07 alexanderoster

There are multiple approaches to support static/dynamic linking, here is mine:

  • Abstract all cgo with an interface that accepts accepts and returns cgo types
  • Do all the go<->cgo heavy lifting in Wrapper but delegate the real cgo call to the interface.
  • Create one interface implementation for dynamic loading, maybe called DynamicWrapper. Put all the related c and go code in a separated files. Add an opt-out tag (act_dynload)? to this file so users that don't need it can remove it at build time.
  • Create on interface implementation for static/dynamic lining, maybe called LinkWrapper. Put all the relatedc and go code in a separated files. Add an opt-in tag (act_link)? to this file for users who want to support this mode.

This allows to support the two scenarios and any combination of them with a small runtime overhead.

qmuntal avatar Jul 28 '20 16:07 qmuntal

I've drafted a working implementation (at least compiling) for the above proposal in https://github.com/qmuntal/AutomaticComponentToolkit/commit/a909c5c55bee45eeb11173c1c2aa37d8e9278cb4, but just the dynamic load implementation.

qmuntal avatar Jul 28 '20 16:07 qmuntal