gobject-introspection.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Enabling GObject Introspection Support
  3. **************************************
  4. `GObject introspection <https://gi.readthedocs.io/en/latest/>`__
  5. is the standard mechanism for accessing GObject-based software from
  6. runtime environments. GObject is a feature of the GLib library that
  7. provides an object framework for the GNOME desktop and related software.
  8. GObject Introspection adds information to GObject that allows objects
  9. created within it to be represented across different programming
  10. languages. If you want to construct GStreamer pipelines using Python, or
  11. control UPnP infrastructure using Javascript and GUPnP, GObject
  12. introspection is the only way to do it.
  13. This section describes the Yocto Project support for generating and
  14. packaging GObject introspection data. GObject introspection data is a
  15. description of the API provided by libraries built on top of the GLib
  16. framework, and, in particular, that framework's GObject mechanism.
  17. GObject Introspection Repository (GIR) files go to ``-dev`` packages,
  18. ``typelib`` files go to main packages as they are packaged together with
  19. libraries that are introspected.
  20. The data is generated when building such a library, by linking the
  21. library with a small executable binary that asks the library to describe
  22. itself, and then executing the binary and processing its output.
  23. Generating this data in a cross-compilation environment is difficult
  24. because the library is produced for the target architecture, but its
  25. code needs to be executed on the build host. This problem is solved with
  26. the OpenEmbedded build system by running the code through QEMU, which
  27. allows precisely that. Unfortunately, QEMU does not always work
  28. perfectly as mentioned in the ":ref:`dev-manual/gobject-introspection:known issues`"
  29. section.
  30. Enabling the Generation of Introspection Data
  31. =============================================
  32. Enabling the generation of introspection data (GIR files) in your
  33. library package involves the following:
  34. #. Inherit the :ref:`ref-classes-gobject-introspection` class.
  35. #. Make sure introspection is not disabled anywhere in the recipe or
  36. from anything the recipe includes. Also, make sure that
  37. "gobject-introspection-data" is not in
  38. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
  39. and that "qemu-usermode" is not in
  40. :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
  41. In either of these conditions, nothing will happen.
  42. #. Try to build the recipe. If you encounter build errors that look like
  43. something is unable to find ``.so`` libraries, check where these
  44. libraries are located in the source tree and add the following to the
  45. recipe::
  46. GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
  47. .. note::
  48. See recipes in the ``oe-core`` repository that use that
  49. :term:`GIR_EXTRA_LIBS_PATH` variable as an example.
  50. #. Look for any other errors, which probably mean that introspection
  51. support in a package is not entirely standard, and thus breaks down
  52. in a cross-compilation environment. For such cases, custom-made fixes
  53. are needed. A good place to ask and receive help in these cases is
  54. the :ref:`Yocto Project mailing
  55. lists <resources-mailinglist>`.
  56. .. note::
  57. Using a library that no longer builds against the latest Yocto
  58. Project release and prints introspection related errors is a good
  59. candidate for the previous procedure.
  60. Disabling the Generation of Introspection Data
  61. ==============================================
  62. You might find that you do not want to generate introspection data. Or,
  63. perhaps QEMU does not work on your build host and target architecture
  64. combination. If so, you can use either of the following methods to
  65. disable GIR file generations:
  66. - Add the following to your distro configuration::
  67. DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
  68. Adding this statement disables generating introspection data using
  69. QEMU but will still enable building introspection tools and libraries
  70. (i.e. building them does not require the use of QEMU).
  71. - Add the following to your machine configuration::
  72. MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
  73. Adding this statement disables the use of QEMU when building packages for your
  74. machine. Currently, this feature is used only by introspection
  75. recipes and has the same effect as the previously described option.
  76. .. note::
  77. Future releases of the Yocto Project might have other features
  78. affected by this option.
  79. If you disable introspection data, you can still obtain it through other
  80. means such as copying the data from a suitable sysroot, or by generating
  81. it on the target hardware. The OpenEmbedded build system does not
  82. currently provide specific support for these techniques.
  83. Testing that Introspection Works in an Image
  84. ============================================
  85. Use the following procedure to test if generating introspection data is
  86. working in an image:
  87. #. Make sure that "gobject-introspection-data" is not in
  88. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
  89. and that "qemu-usermode" is not in
  90. :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
  91. #. Build ``core-image-sato``.
  92. #. Launch a Terminal and then start Python in the terminal.
  93. #. Enter the following in the terminal::
  94. >>> from gi.repository import GLib
  95. >>> GLib.get_host_name()
  96. #. For something a little more advanced, enter the following see:
  97. https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
  98. Known Issues
  99. ============
  100. Here are know issues in GObject Introspection Support:
  101. - ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
  102. introspection data on that architecture.
  103. - x32 is not supported by QEMU. Consequently, introspection data is
  104. disabled.
  105. - musl causes transient GLib binaries to crash on assertion failures.
  106. Consequently, generating introspection data is disabled.
  107. - Because QEMU is not able to run the binaries correctly, introspection
  108. is disabled for some specific packages under specific architectures
  109. (e.g. ``gcr``, ``libsecret``, and ``webkit``).
  110. - QEMU usermode might not work properly when running 64-bit binaries
  111. under 32-bit host machines. In particular, "qemumips64" is known to
  112. not work under i686.