gobject-introspection.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. 1. Inherit the
  35. :ref:`gobject-introspection <ref-classes-gobject-introspection>`
  36. class.
  37. 2. Make sure introspection is not disabled anywhere in the recipe or
  38. from anything the recipe includes. Also, make sure that
  39. "gobject-introspection-data" is not in
  40. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
  41. and that "qemu-usermode" is not in
  42. :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
  43. In either of these conditions, nothing will happen.
  44. 3. Try to build the recipe. If you encounter build errors that look like
  45. something is unable to find ``.so`` libraries, check where these
  46. libraries are located in the source tree and add the following to the
  47. recipe::
  48. GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
  49. .. note::
  50. See recipes in the ``oe-core`` repository that use that
  51. :term:`GIR_EXTRA_LIBS_PATH` variable as an example.
  52. 4. Look for any other errors, which probably mean that introspection
  53. support in a package is not entirely standard, and thus breaks down
  54. in a cross-compilation environment. For such cases, custom-made fixes
  55. are needed. A good place to ask and receive help in these cases is
  56. the :ref:`Yocto Project mailing
  57. lists <resources-mailinglist>`.
  58. .. note::
  59. Using a library that no longer builds against the latest Yocto
  60. Project release and prints introspection related errors is a good
  61. candidate for the previous procedure.
  62. Disabling the Generation of Introspection Data
  63. ==============================================
  64. You might find that you do not want to generate introspection data. Or,
  65. perhaps QEMU does not work on your build host and target architecture
  66. combination. If so, you can use either of the following methods to
  67. disable GIR file generations:
  68. - Add the following to your distro configuration::
  69. DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
  70. Adding this statement disables generating introspection data using
  71. QEMU but will still enable building introspection tools and libraries
  72. (i.e. building them does not require the use of QEMU).
  73. - Add the following to your machine configuration::
  74. MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
  75. Adding this statement disables the use of QEMU when building packages for your
  76. machine. Currently, this feature is used only by introspection
  77. recipes and has the same effect as the previously described option.
  78. .. note::
  79. Future releases of the Yocto Project might have other features
  80. affected by this option.
  81. If you disable introspection data, you can still obtain it through other
  82. means such as copying the data from a suitable sysroot, or by generating
  83. it on the target hardware. The OpenEmbedded build system does not
  84. currently provide specific support for these techniques.
  85. Testing that Introspection Works in an Image
  86. ============================================
  87. Use the following procedure to test if generating introspection data is
  88. working in an image:
  89. 1. Make sure that "gobject-introspection-data" is not in
  90. :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
  91. and that "qemu-usermode" is not in
  92. :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
  93. 2. Build ``core-image-sato``.
  94. 3. Launch a Terminal and then start Python in the terminal.
  95. 4. Enter the following in the terminal::
  96. >>> from gi.repository import GLib
  97. >>> GLib.get_host_name()
  98. 5. For something a little more advanced, enter the following see:
  99. https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
  100. Known Issues
  101. ============
  102. Here are know issues in GObject Introspection Support:
  103. - ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
  104. introspection data on that architecture.
  105. - x32 is not supported by QEMU. Consequently, introspection data is
  106. disabled.
  107. - musl causes transient GLib binaries to crash on assertion failures.
  108. Consequently, generating introspection data is disabled.
  109. - Because QEMU is not able to run the binaries correctly, introspection
  110. is disabled for some specific packages under specific architectures
  111. (e.g. ``gcr``, ``libsecret``, and ``webkit``).
  112. - QEMU usermode might not work properly when running 64-bit binaries
  113. under 32-bit host machines. In particular, "qemumips64" is known to
  114. not work under i686.