AutomaticComponentToolkit
AutomaticComponentToolkit copied to clipboard
[cgo] CGo now is using dynamic loading - find a concept to dynamically/statically link the code
We are using cdynamic.cc headers at the moment for the cgo bindings. Is there a way to statically link the libraries with go?
@qmuntal
There are multiple approaches to support static/dynamic linking, here is mine:
- Abstract all
cgo
with an interface that accepts accepts and returnscgo
types - Do all the go<->cgo heavy lifting in
Wrapper
but delegate the realcgo
call to the interface. - Create one interface implementation for dynamic loading, maybe called
DynamicWrapper
. Put all the relatedc
andgo
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
andgo
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.
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.