miqt/cmd/genbindings
2024-11-04 20:18:11 +13:00
..
cachedir
clang2il_test.go
clang2il.go genbindings: move AllowClass from parse-time to transformation AST pass 2024-10-26 12:35:27 +13:00
clangexec.go genbindings/main: support custom clang ast node matchers 2024-10-20 18:06:31 +13:00
config-allowlist.go genbindings: exclude Qt 6 QGuiApplication::platform that does not build on Win32 2024-10-27 12:47:01 +13:00
config-libraries.go genbindings/main: move library list into a config file 2024-10-21 19:10:31 +13:00
emitcabi.go genbindings: pass miqt_array in CABI by value 2024-11-04 20:18:11 +13:00
emitgo.go genbindings: pass miqt_array in CABI by value 2024-11-04 20:18:11 +13:00
intermediate.go genbindings: implement "BecomesNonConstInVersion" quirk support 2024-10-26 12:35:01 +13:00
main.go genbindings: reorder ctors to put (QWidget* parent) version first 2024-10-26 13:46:16 +13:00
README.md docs: update for Qt 6, QByteArray, more clear wording 2024-10-22 18:45:29 +13:00
transformblocklist.go genbindings: move AllowClass from parse-time to transformation AST pass 2024-10-26 12:35:27 +13:00
transformchildclasses_test.go
transformchildclasses.go genbindings/transform: fix missing enums/typedefs from inner classes 2024-09-21 11:02:05 +12:00
transformctors.go genbindings: reorder ctors to put (QWidget* parent) version first 2024-10-26 13:46:16 +13:00
transformoptional.go
transformoverload.go
transformredundant.go
transformtypedefs_test.go genbindings/typedefs: centralize exceptions 2024-09-20 18:41:21 +12:00
transformtypedefs.go genbindings: multi-package support 2024-10-16 18:07:05 +13:00
util.go genbindings: implement "BecomesNonConstInVersion" quirk support 2024-10-26 12:35:01 +13:00

genbindings

The genbindings program regenerates the Qt bindings.

Architecture design

Bindings are generated in two passes:

Pass 1

  1. Scan input directory for header files.
  2. For each header file:
  3. Run clang --ast-dump=json to get a JSON ast.
    • This is somewhat slow, the results will be cached in ./cachedir after the first run.
    • Strip all Clang AST nodes that were included from other files, to only consider the header's own definitions.
  4. Convert Clang AST to our own intermediate representation.
  5. Run some transformations on the intermediate representation.
  6. Cache and collect the global state of all known class names, enum names, and typedefs.

Pass 2

  1. For each intermediate-representation AST:
  2. Emit "CABI" cpp/h pair.
    • The CABI is a projection of Qt into plain C. The translation unit itself is C++, but the header can be used as extern c.
  3. Emit Go binding file.
    • The Go binding uses CGO to call into the CABI binding.

Configuration

It's tested to work on with Debian 12 with system packages (Qt 5.15 / Qt 6.4 / Clang 14 / GCC 12).

You should check the following configuration:

  • config-libraries.go: Input directories containing Qt headers
  • config-allowlist.go: Check everything