mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.49k stars 1.59k forks source link

gnome: generate_gir unnecessarily links to libgirepository #12680

Open smcv opened 8 months ago

smcv commented 8 months ago

Describe the bug When generating GIR XML and typelibs, the GNOME module always tells g-ir-scanner to link the "dumper" binary to libgirepository-1.0.

To Reproduce Run Meson's unit tests, for example building test cases/frameworks/12 multiple gir is suitable.

Expected behavior When gir/meson.build runs g-ir-scanner to generate Meson-1.0.gir, I expect the resulting "dumper" binary to be linked to libgobject-2.0 because girsubproject has that as a dependency, but I don't expect it to be linked to libgirepository-1.0 because the "dumper" binary doesn't need that library.

For comparison, and to illustrate what I expected: Autotools doesn't link the "dumper" binary to libgirepository-1.0. For example, when I compile libostree in https://buildd.debian.org/status/fetch.php?pkg=ostree&arch=amd64&ver=2023.8-1&stamp=1702049756&raw=0, there are no --extra-library flags at all, and the only -I are for libostree's dependencies GLib, Gio and libmount:

CPPFLAGS="..." CFLAGS="..." LDFLAGS="..." CC="..." PKG_CONFIG="..." GI_HOST_OS="" DLLTOOL="false" CC=gcc \
/usr/bin/g-ir-scanner \
 --namespace=OSTree
 --nsversion=1.0 \
 --libtool="/bin/bash ./libtool"  \
 --include=Gio-2.0 \
 --pkg-export=ostree-1 \
 --c-include=ostree.h \
 --library=libostree-1.la \
 --warn-all \
 --identifier-prefix=Ostree \
 --symbol-prefix=ostree \
 --cflags-begin \
    -std=gnu99 \
    -fno-strict-aliasing \
    -pipe \
    -Wall -Werror=... \
    -I./bsdiff \
    -I./libglnx \
    -I./composefs \
    -I./src/libotutil \
    -I./src/libotcore \
    -I./src/libostree \
    -I./src/libostree \
    -I./src/switchroot \
    -I/usr/include/gio-unix-2.0 \
    -I/usr/include/glib-2.0 \
    -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
    -pthread \
    -I/usr/include/libmount \
    -I/usr/include/blkid \
    -fvisibility=hidden '-D...`  \
    -I/usr/include/glib-2.0 \
    -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
    -I/usr/include/x86_64-linux-gnu \
    -I/usr/include/libmount \
    -I/usr/include/blkid \
 --cflags-end \
 src/libostree/ostree.h ... src/libostree/ostree-sign-ed25519.c \
 libostree-1.la \
 Makefile \
 --output OSTree-1.0.gir

Actual behavior

(from https://buildd.debian.org/status/fetch.php?pkg=meson&arch=all&ver=1.3.1-1&stamp=1703618386&raw=0, whitespace added for clarity)

Meson adds -I and --extra-library for libgirepository-1.0 and its dependencies:

[9/12] env \
    'PKG_CONFIG_PATH=/<<PKGBUILDDIR>>/b 2ba2ef3c85/meson-uninstalled' \
    PKG_CONFIG=/usr/bin/pkg-config \
    CC=cc \
/usr/bin/g-ir-scanner \
--quiet \
--no-libtool \
--namespace=Meson \
--nsversion=1.0 \
--warn-all \
--output mesongir/Meson-1.0.gir \
'-I/<<PKGBUILDDIR>>/test cases/frameworks/12 multiple gir/mesongir' \
'-I/<<PKGBUILDDIR>>/b 2ba2ef3c85/mesongir' \
'--filelist=/<<PKGBUILDDIR>>/b 2ba2ef3c85/mesongir/libgirlib.so.p/Meson_1.0_gir_filelist' \
--include=GObject-2.0 \
--symbol-prefix=meson_ \
--identifier-prefix=Meson \
--pkg-export=meson \
--cflags-begin \
    -I/usr/include/glib-2.0 \
    -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
    -I/usr/include/gobject-introspection-1.0 \
--cflags-end \
--add-include-path=/usr/share/gir-1.0 \
'-L/<<PKGBUILDDIR>>/b 2ba2ef3c85/mesongir' \
--library girlib \
--extra-library=gobject-2.0 \
--extra-library=glib-2.0 \
--extra-library=girepository-1.0 \
--sources-top-dirs '/<<PKGBUILDDIR>>/test cases/frameworks/12 multiple gir/' \
--sources-top-dirs '/<<PKGBUILDDIR>>/b 2ba2ef3c85/'

I believe the reason why this is happening is that commit 777004198 " gnome: Fix usage of gobject-introspection as subproject" (#7020) added:

        deps += [gir_dep]

which is the same as adding dependency('gobject-introspection-1.0') to the dependencies of an executable.

If GObject-Introspection is a subproject, I think it should be added to the depends, so that the subproject will be built before the GIR XML, and so that changes to the subproject will trigger a rebuild of the GIR XML; but I think it should not be included in the list of dependencies passed to self._get_dependencies_flags, which should mean there is no --extra-library=girepository-1.0 unless the meson.build explicitly specifies a dependency on libgirepository.

system parameters

smcv commented 8 months ago

cc @xclaesse