valavapi

Generating a Vapi file for a Vala library


I've got a library written in Vala that has always worked fine generating a .vapi file for itself, I think because it's a free operation with valac but I'm not positive on that. I went and tried to use VAPIGEN_CHECK in my configure.ac file and the associated VAPIGEN_MAKEFILE in my Makefile.am and now I get:

error: The type name `GLib.TypeInstance' could not be found

My corresponding .gir file contains:

<field name="parent_instance">
  <type name="GObject.TypeInstance" c:type="GTypeInstance"/>
</field>

So the error seems to make sense because I can't find the GObject.TypeInstance class/struct in any .vapi file, but GTypeInstance is in one of the GLib headers.

Should I even be doing it this way if I'm writing everything in Vala already? Is there a possibility that this is missing from the Vapi?

Edit: Possibly just due to my not deriving GLib.Object which I thought was implicit. Still trying to fix something else that prevents this but once that's done I will update this to say whether or not it actually matters.


Solution

  • To generate a VAPI file from a Vala program you should simply use the --vapi option with valac, e.g.:

    valac --vapi my_library_name.vapi my_library.vala

    From what you are describing I think you are generating a GIR (GObject Introspection Repository) file with valac, then using vapigen to create the VAPI file. vapigen is part of Vala and maintained in the Vala source code, but it is a tool for generating a VAPI file to bind to non-Vala projects. If the non-Vala project distributes a GIR file it makes the binding very easy.

    When using vapigen you need to give the packages it uses, so you need to check you are including the right pkg-config flags, e.g.:

    vapigen --pkg glib-2.0 --pkg gobject-2.0 my_library.gir

    The other possibility is there is no binding for GTypeInstance in Vala. I've had a quick look and I'm not finding anything.