miqt/cmd/genbindings
2024-11-22 19:05:48 +13:00
..
cachedir genbindings: generate multiple files in one run, cache clang ast files 2024-08-14 17:43:54 +12:00
clang2il_test.go genbindings/test: fix compilation for isConst support 2024-09-07 15:24:57 +12:00
clang2il.go genbindings/inherits: direct vs indirect inheritance 2024-11-19 19:24:50 +13:00
clangexec.go genbindings/main: support custom clang ast node matchers 2024-10-20 18:06:31 +13:00
config-allowlist.go genbindings/config: update for Qt 6.8 2024-11-22 19:05:48 +13:00
config-libraries.go Modify qt6/cbor for proper builds 2024-11-17 11:22:24 -05:00
emitcabi.go genbindings: change simple operator== to use infix syntax 2024-11-22 18:58:56 +13:00
emitgo.go genbindings: fix some cases of missing :: escaping 2024-11-19 19:59:55 +13:00
intermediate.go genbindings: change simple operator== to use infix syntax 2024-11-22 18:58:56 +13:00
main.go genbindings: refactor move state tracker to new file 2024-11-17 19:16:45 +13:00
README.md doc/README: simplify FAQ entry about library bindings 2024-11-06 18:44:05 +13:00
statetracker.go genbindings/subclassing: accurate pointer type management for subclasses 2024-11-19 19:28:30 +13:00
transformblocklist.go genbindings/blocklist: refactor extract single method helper 2024-11-17 19:16:34 +13:00
transformchildclasses_test.go genbindings/test: add test cases for child class expansion 2024-08-28 18:00:07 +12:00
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 genbindings: subclass support for all virtual methods (2/3) 2024-11-19 19:17:37 +13:00
transformoverload.go genbindings/cabi: move method renaming to helper function 2024-09-11 18:06:17 +12:00
transformredundant.go genbindings: merge enums with redundant definitions 2024-09-16 19:03:45 +12:00
transformtypedefs_test.go genbindings/typedefs: centralize exceptions 2024-09-20 18:41:21 +12:00
transformtypedefs.go genbindings: add QPair<> support 2024-11-17 19:17:31 +13:00
util.go genbindings/util: add slice_copy helper 2024-11-19 19:24:57 +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

Steps to add extra libraries to MIQT

  1. Git clone this repository
  2. In docker/genbindings.Dockerfile, add your library's headers and pkg-config file.
  3. Patch cmd/genbindings/config-libraries.go to add a new generate block for your target library
  4. Run genbindings to regenerate all bindings
    • The first run must populate clang ASTs into a cache directory and may be slower, but it is fast afterwards
  5. Add a cflags.go file to the generated binding directory
    • It should have a #cgo pkg-config: LibraryName stanza and any extra flags (e.g. --std=c++17) that are required but not system-specific
  6. Try to use the new binding within the repo, by adding an example in the examples/libraries directory
  7. Commit the generated bindings
    • You can then use your forked MIQT repo with replace inside go.mod
    • Or, open a Pull Request to add the library to MIQT