Ultralight icon indicating copy to clipboard operation
Ultralight copied to clipboard

Generate automatic language bindings for C API via SWIG

Open adamjs opened this issue 3 years ago • 2 comments

Use SWIG to generate automatic, low-level language bindings for our C API to simplify the task of maintaining bindings for other languages.

SWIG supports the following language targets we care about:

  • C#
  • Go
  • Java
  • Python

adamjs avatar Nov 05 '20 18:11 adamjs

Would not recommend doing Java with SWIG... I tried that and it was horrible. With Java/JNI it is very easy to wrap the C++ API directly and bind C++ pointers to Java objects. The SWIG wrapper generates a lot of weird types which makes using it complicated.

Janrupf avatar Nov 05 '20 18:11 Janrupf

Yeah same deal with C#, SWIG requires a lot of massaging in their language target scripts to produce usable output (don't get me started on the crazy hoops they force you to go through just to have sane bindings for callbacks/listeners).

Ignoring ABI concerns, the C++ API is definitely more "wrappable" for similar class-based languages like C# and Java-- I'm open to using other alternatives for certain language targets (SWIG can't even target Rust so it's no panacea).

My main goal is just to reduce the burden of maintainability so we have some automatic bindgen running on the buildbots that can be used instead of the raw C/C++ API (which is obviously going to break often as trunk is updated).

adamjs avatar Nov 05 '20 19:11 adamjs