cocos-engine
cocos-engine copied to clipboard
The Swig IDL tool for generating code from c++ header files
The problems of current binding-generator:
- Using libclang to parse c++ header files instead of parsing IDL files
- It's difficult for some developers to setup the tool environment which needs correct version of python & android ndk
- It's hard to extend its functionalities
- Its configuration file (tools/tojs/aaa.ini) is hard to understand
- It depends on specific android ndk version to generate code, the latest android ndk may not be compatible with bindings-generator
- The format of generated code is different on different systems (windows / macOS)
- The conversion system depends on c++ template now, user has to write c++ template to deal with JS <-> CPP conversions
- It's hard to support different backends
- It's hard to compare changes or handle conflicts in .ini file since plenty of configurations need to be written in a line
- No design documentation
Swig ( https://www.swig.org ) is strong enough for all our needs now. The main advantages are:
- Support many language backends, most languages you know.
- Support IDL which depends on C/C++ syntax
- Detailed documentation for usage and its internal implementation
- Very strong typemap system for easily implementing conversion between JS and cpp
- Lots of Built-in directives for handling complicated needs, like %typemap, %feature, %rename, %aggregate_check, %contract, %apply and so on.
- Swig itself is written by C ( swig core ) & C++ (swig module), performance should be good
- No other library dependences
- Variadic parameter support
- Support to bind c++ template
- And more, you could refer to https://www.swig.org/Doc4.0/SWIGDocumentation.html
Our needs of using Swig:
- Generate JS binding code that uses our ScriptEngine wrapper
- Generate .d.ts file for JS binding API
- Generate Serialization code for
bitsery serialization library
- Generate emscripten binding code that uses
embind
- Generate RenderGraph code
- Generate TS decorator relevant code
- Generate C++ API documentation
- Generate C++ reflection code
Problems need to be fixed:
- [x] Swig doesn't support to bind Nest Class like which in binding-generator
- [ ] Generate %attribute code in swig interface file according original TS file automatically.