Skip to content

gobject: Make GLib-2.0 gir build depend on GObject dependency

Marco Trevisan requested to merge 3v1n0/glib:glib-gir-sources into main

GLib gir requires glib-types.h that also includes gobject-visibility.h that needs to be generated in order to be able to generate the GLib gir, so explicitly add it to the sources.

Also, in order to link the typelib we need the definitions of the *_get_type() functions that are defined in the gboxed.c file, so this should be part of the gir sources or we'll have linking issues.

This also requires !3763 (merged) to properly work (i.e. to be able to ninja -C _build gobject/GLib-2.0.typelib).

Errors before:

❯ ninja -C ../_BUILD/glib gobject/GLib-2.0.typelib    
ninja: Entering directory `../_BUILD/glib'
[1/2] Generating gobject/GLib-2.0.gir with a custom command (wrapped by meson to set env)
FAILED: gobject/GLib-2.0.gir 
env PKG_CONFIG_PATH=/opt/dev/GNOME/lib/pkgconfig:/opt/dev/GNOME/share/pkgconfig:/opt/dev/lib/pkgconfig:/opt/dev/lib/x86_64-linux-gnu/pkgconfig:/opt/dev/share/pkgconfig:/data/GNOME/_BUILD/glib/meson-uninstalled 'CC=ccache cc' /opt/dev/GNOME/bin/g-ir-scanner --quiet --no-libtool --namespace=GLib --nsversion=2.0 --warn-all --output gobject/GLib-2.0.gir --c-include=glib.h --quiet -DGLIB_COMPILATION '-DGETTEXT_PACKAGE="dummy"' --symbol-prefix=glib --library-path=/data/GNOME/_BUILD/glib/gobject --library=gobject-2.0 -I/data/GNOME/glib/gobject -I/data/GNOME/_BUILD/glib/gobject -I/data/GNOME/glib/. -I/data/GNOME/_BUILD/glib/. --filelist=/data/GNOME/_BUILD/glib/glib/libglib-2.0.so.0.7900.0.p/GLib_2.0_gir_filelist --symbol-prefix=g --identifier-prefix=G --pkg-export=glib-2.0 --cflags-begin -D_GNU_SOURCE -DG_DISABLE_CAST_CHECKS -I/data/GNOME/glib/. -I/data/GNOME/_BUILD/glib/. -I/data/GNOME/glib/glib -I/data/GNOME/_BUILD/glib/glib -I/opt/dev/GNOME/include/gobject-introspection-1.0 -I/opt/dev/GNOME/include/glib-2.0 -I/opt/dev/GNOME/lib/glib-2.0/include --cflags-end --add-include-path=/opt/dev/GNOME/share/gir-1.0 -L/data/GNOME/_BUILD/glib/glib --extra-library=glib-2.0 -L/data/GNOME/_BUILD/glib/glib --library glib-2.0 -L/opt/dev/GNOME/lib --extra-library=m --extra-library=pcre2-8 -L/opt/dev/GNOME/lib --extra-library=girepository-1.0 --extra-library=gobject-2.0 --extra-library=glib-2.0 --sources-top-dirs /data/GNOME/glib/ --sources-top-dirs /data/GNOME/_BUILD/glib/
In file included from /data/GNOME/glib/gobject/gobject.h:26,
                 from /data/GNOME/glib/gobject/gbinding.h:31,
                 from /data/GNOME/glib/glib/glib-object.h:24,
                 from /data/GNOME/_BUILD/glib/g-ir-cpp-w5nzbw6b.c:9:
/data/GNOME/glib/gobject/gtype.h:27:10: fatal error: gobject/gobject-visibility.h: No such file or directory
   27 | #include <gobject/gobject-visibility.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/setuptools/_distutils/unixccompiler.py", line 178, in preprocess
    self.spawn(pp_args)
  File "/usr/lib/python3/dist-packages/setuptools/_distutils/ccompiler.py", line 1041, in spawn
    spawn(cmd, dry_run=self.dry_run, **kwargs)
  File "/usr/lib/python3/dist-packages/setuptools/_distutils/spawn.py", line 70, in spawn
    raise DistutilsExecError(
distutils.errors.DistutilsExecError: command '/usr/bin/ccache' failed with exit code 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/dev/GNOME/bin/g-ir-scanner", line 104, in <module>
    sys.exit(scanner_main(sys.argv))
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/dev/GNOME/lib/gobject-introspection/giscanner/scannermain.py", line 600, in scanner_main
    ss, filenames = create_source_scanner(options, args)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/dev/GNOME/lib/gobject-introspection/giscanner/scannermain.py", line 471, in create_source_scanner
    ss.parse_files(filenames)
  File "/opt/dev/GNOME/lib/gobject-introspection/giscanner/sourcescanner.py", line 265, in parse_files
    self._parse(headers)
  File "/opt/dev/GNOME/lib/gobject-introspection/giscanner/sourcescanner.py", line 311, in _parse
    cc.preprocess(tmp_name_cpp,
  File "/opt/dev/GNOME/lib/gobject-introspection/giscanner/ccompiler.py", line 309, in preprocess
    self.compiler.preprocess(source=source,
  File "/usr/lib/python3/dist-packages/setuptools/_distutils/unixccompiler.py", line 180, in preprocess
    raise CompileError(msg)
distutils.errors.CompileError: command '/usr/bin/ccache' failed with exit code 1
ninja: build stopped: subcommand failed.

Once the header is built with ninja -C ../_BUILD/glib gobject/gobject-visibility.h

/usr/bin/ld: /data/GNOME/_BUILD/glib/tmp-introspect2tr99yqz/GLib-2.0.o:(.data.rel+0x120): undefined reference to `g_hmac_get_type'
/usr/bin/ld: /data/GNOME/_BUILD/glib/tmp-introspect2tr99yqz/GLib-2.0.o:(.data.rel+0x128): undefined reference to `g_dir_get_type'
/usr/bin/ld: /data/GNOME/_BUILD/glib/tmp-introspect2tr99yqz/GLib-2.0.o:(.data.rel+0x130): undefined reference to `g_strv_builder_get_type'
collect2: error: ld returned 1 exit status
linking of temporary binary failed: Command '['ccache', 'cc', '-o', '/data/GNOME/_BUILD/glib/tmp-introspect2tr99yqz/GLib-2.0', '/data/GNOME/_BUILD/glib/tmp-introspect2tr99yqz/GLib-2.0.o', '-L.', '-Wl,-rpath,.', '-Wl,--no-as-needed', '-L/data/GNOME/_BUILD/glib/gobject', '-Wl,-rpath,/data/GNOME/_BUILD/glib/gobject', '-L/data/GNOME/_BUILD/glib/glib', '-Wl,-rpath,/data/GNOME/_BUILD/glib/glib', '-L/data/GNOME/_BUILD/glib/glib', '-Wl,-rpath,/data/GNOME/_BUILD/glib/glib', '-L/opt/dev/GNOME/lib', '-Wl,-rpath,/opt/dev/GNOME/lib', '-L/opt/dev/GNOME/lib', '-Wl,-rpath,/opt/dev/GNOME/lib', '-lgobject-2.0', '-lglib-2.0', '-lglib-2.0', '-lm', '-lpcre2-8', '-lgirepository-1.0', '-lgobject-2.0', '-lglib-2.0', '-L/data/GNOME/_BUILD/glib/gio', '-lgio-2.0', '-L/data/GNOME/_BUILD/glib/glib', '-L/data/GNOME/_BUILD/glib/gobject', '-lgobject-2.0', '-Wl,--export-dynamic', '-L/data/GNOME/_BUILD/glib/gmodule', '-lgmodule-2.0', '-pthread', '-lglib-2.0', '-lglib-2.0']' returned non-zero exit status 1.
ninja: build stopped: subcommand failed.
Edited by Marco Trevisan

Merge request reports