Adding dependency from shared_module to gnome.generate_gir

45 views
Skip to first unread message

Daniele Nicolodi

unread,
Mar 25, 2022, 6:14:02 PM3/25/22
to The Meson Build System
Hello,

I have a GObject library for which I generate introspection data with a
gnome.generate_gir() target. For dependency decoupling, the library
dynamically loads (in the dlopen sense) modules generate with a
shared_module() target. The modules are necessary for the library to
work properly and g-ir-scanner fails if they are not present.

I haven't found a way to express the fact that the shared_module()
targets need to be built before the gnome.generate_gir() target thus
sometimes the project build fails, depending on how ninja decides to
order the build steps.

Is there a way to trick meson into adding a dependency between the two
targets other than modifying the gnome.generate_gir() function to accept
a new "depends" argument in the style of the one accepted by the
custom_target() function?

Thank you.

Cheers,
Dan

Eli Schwartz

unread,
Mar 25, 2022, 7:28:19 PM3/25/22
to meson...@googlegroups.com
I'm not the expert on gobject-introspection but can you just treat the
shared module the same as the library by adding it as an e.g. link_with?

--
Eli Schwartz

Daniele Nicolodi

unread,
Mar 26, 2022, 4:04:26 AM3/26/22
to meson...@googlegroups.com
The documentation says that linking with a shared_module is explicitly
forbidden thus I didn't try. However, trying it I obtain a linker error
on macOS:

ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file...

The shared_module is loaded just fine by the library if it exists, the
issue is to have meson build the targets in the right order.

Cheers,
Dan

Daniele Nicolodi

unread,
Mar 26, 2022, 10:43:09 AM3/26/22
to meson...@googlegroups.com
I found a solution that is not pretty but not that ugly either: I use a
custom_target() with a depends list including the dynamically loaded
modules to generate an empty source file that then I add to the
gnome.generate_gir() sources list.

It looks something like this (simplified and abbreviated):

libtracker_sparql_modules = []

libtracker_remote_soup3 = shared_module('tracker-remote-soup3', ...)
libtracker_sparql_modules += libtracker_remote_soup3

# This custom target has the only purpose to inject a dependency from
# the libtracker_sparql_modules into the tarcker_sparql_gir target to
# force meson to build the loadable shared modules before attempting
# to run g-ir-scanner.
libtracker_sparql_modules_stamp = custom_target(
'libtracker-sparql-modules-stamp',
output: 'tracker-sparql-modules-stamp.c',
command: ['touch', '@OUTPUT@'],
depends: libtracker_sparql_modules,
)

tracker_sparql_gir = gnome.generate_gir(libtracker_sparql,
sources: [libtracker_sparql_modules_stamp, ...],
...
)

It seems a pattern that can be reused.

Cheers,
Dan

Daniele Nicolodi

unread,
Mar 26, 2022, 4:09:33 PM3/26/22
to meson...@googlegroups.com
Unfortunately this works only staring with meson 0.59. I think previous
versions did not generate correct dependency rules for gnome.generate_gir()

Cheers,
Dan
Reply all
Reply to author
Forward
0 new messages