Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alexanderoster opened this issue Jul 28, 2020 · 3 comments

Comments

@alexanderoster
Copy link

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
Copy link
Author

@qmuntal

@qmuntal
Copy link

qmuntal commented Jul 28, 2020

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
Copy link

qmuntal commented Jul 28, 2020

I've drafted a working implementation (at least compiling) for the above proposal in qmuntal@a909c5c, but just the dynamic load implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants