Generating Optional Bindings¶
The GIR bindings generator creates Kotlin/Native bindings for a set of default libraries, but you can also generate
bindings for additional libraries by editing the gtkkn.json
file.
Editing the gtkkn.json
File¶
The gtkkn.json
file configures both the GIR bindings generator and the Gradle project, specifying which libraries to
generate bindings for. It also enables additional Gradle modules. Below is an example of the default gtkkn.json
file:
Click to expand/collapse
{
"girBaseDir": "/usr/share/gir-1.0",
"outputDir": "bindings",
"gradlePluginDir": "gradle-plugin",
"logLevel": "INFO",
"skipFormat": false,
"bindingLicense": "LGPL",
"libraries": [
{
"name": "cairo",
"module": "core:cairo",
"girPrefix": "cairo-"
},
{
"name": "gdkpixbuf",
"module": "core:gdkpixbuf",
"girPrefix": "GdkPixbuf-"
},
{
"name": "gio",
"module": "core:gio",
"girPrefix": "Gio-"
},
{
"name": "glib",
"module": "core:glib",
"girPrefix": "GLib-"
},
{
"name": "gmodule",
"module": "core:gmodule",
"girPrefix": "GModule-"
},
{
"name": "gobject",
"module": "core:gobject",
"girPrefix": "GObject-"
},
{
"name": "graphene",
"module": "core:graphene",
"girPrefix": "Graphene-"
},
{
"name": "pango",
"module": "core:pango",
"girPrefix": "Pango-"
},
{
"name": "pangocairo",
"module": "core:pangocairo",
"girPrefix": "PangoCairo-"
},
{
"name": "gdk",
"module": "gtk:gdk4",
"girPrefix": "Gdk-4"
},
{
"name": "gsk",
"module": "gtk:gsk4",
"girPrefix": "Gsk-"
},
{
"name": "gtk",
"module": "gtk:gtk4",
"girPrefix": "Gtk-4"
},
{
"name": "adw",
"module": "adwaita",
"girPrefix": "Adw-1"
}
],
"ignoredLibraries": [
{
"name": "gtksource",
"module": "extra:gtksource",
"girPrefix": "GtkSource-5"
},
{
"name": "javascriptcore",
"module": "extra:javascriptcore",
"girPrefix": "JavaScriptCore-6.0"
},
{
"name": "soup",
"module": "extra:soup",
"girPrefix": "Soup-3.0"
},
{
"name": "webkit",
"module": "extra:webkit",
"girPrefix": "WebKit-6.0"
}
]
}
Key Fields in gtkkn.json
¶
-
libraries
: Lists libraries for binding generation, with metadata:name
: The library name (e.g.,glib
).module
: The associated Gradle module, generated inoutputDir
(e.g.,core:glib
).girPrefix
: The library’s GIR file prefix (e.g.,GLib-
).
-
ignoredLibraries
: Lists optional libraries supported by the generator but not generated by default. To enable an optional library, move it fromignoredLibraries
tolibraries
.
Using a Custom Configuration File¶
To use a custom configuration file instead of the default gtkkn.json
, set a Gradle property, org.gtkkn.configFile
,
with the path to your file. This can be done via the command line or in your ~/.gradle/gradle.properties
file.
Command-Line Method¶
To use a custom configuration file at /path/to/my/config.json
, run:
Permanent Method¶
To make this setting permanent, add it to your ~/.gradle/gradle.properties
: