libgusb: Meson, Gir, Cross face-off
Introduction
This is a shorter post, following up on the Loose Ends section of the cross-the-gir.
After dealing with the fallout from merging gir support, there wasn't much to do, glibc-2.29 is still waiting. I decided to take some time to find out why libgusb is failing.
Diagnostics
error
First thing we need to do is to look at the error, we can re-use the error message from the last article. Let's take a look at where it actually errors out
In file included from /builddir/libgusb-0.3.0/build/g-ir-cpp-se2xrgqu.c:4: /builddir/libgusb-0.3.0/build/gusb/gusb-version.h:31:2: error: #error "Only <gusb.h> can be included directly." #error "Only <gusb.h> can be included directly." ^~~~~
OK, we are hitting a #error directive in build/gusb/gusb-version.h, on line 31, let's take a peek at it and a few lines around.
#if !defined (__GUSB_INSIDE__) && !defined (GUSB_COMPILATION) #error "Only <gusb.h> can be included directly." #endif
Interesting, we need either __GUSB_INSIDE__ or GUSB_COMPILATION defined. But where is it defined ?
meson.build
add_project_arguments('-DGUSB_COMPILATION', language: 'c')
So it is added to the project CFLAGS, isn't it present in the args passed to it ? Let's check the build.ninja for it.
build/build.ninja
build gusb/GUsb-1.0.gir: CUSTOM_COMMAND | /usr/aarch64-linux-gnu/usr/bin/g-ir-scanner gusb/libgusb.so.2.0.10 COMMAND = /usr/aarch64-linux-gnu/usr/bin/g-ir-scanner -pthread -I/usr/aarch64-linux-gnu/usr/include/gobject-introspection-1.0 -I/usr/aarch64-linux-gnu/usr/include/glib-2.0 -I/usr/aarch64-linux-gnu/usr/lib/glib-2.0/include --no-libtool --namespace=GUsb --nsversion=1.0 --warn-all --output gusb/GUsb-1.0.gir --c-include=gusb.h -I/builddir/libgusb-0.3.0/gusb -I/builddir/libgusb-0.3.0/build/gusb -I./. -I../. -I./gusb/. -I../gusb/. --filelist=/builddir/libgusb-0.3.0/build/gusb/bf6bc9e@@gusb@sha/GUsb_1.0_gir_filelist -L/builddir/libgusb-0.3.0/build/gusb --extra-library=gusb --include=Gio-2.0 --include=GObject-2.0 --symbol-prefix=g_usb --identifier-prefix=GUsb --pkg-export=gusb --cflags-begin -I./. -I../. -I./gusb/. -I../gusb/. -I/usr/aarch64-linux-gnu/usr/include/libmount -I/usr/aarch64-linux-gnu/usr/include/blkid -I/usr/aarch64-linux-gnu/usr/include/uuid -I/usr/aarch64-linux-gnu/usr/include/glib-2.0 -I/usr/aarch64-linux-gnu/usr/lib/glib-2.0/include -I/usr/aarch64-linux-gnu/usr/include/libusb-1.0 -D_FORTIFY_SOURCE=2 -I/usr/aarch64-linux-gnu/usr/include --cflags-end --library gusb -L/builddir/libgusb-0.3.0/build/gusb -L/usr/aarch64-linux-gnu/usr/lib --extra-library=gio-2.0 --extra-library=gobject-2.0 --extra-library=glib-2.0 --extra-library=usb-1.0
Looking at ATK
Taking a look at another package that uses both meson and generates gir, Atk.
Let's check if they also have an equivalent to GUSB_COMPILATION, maybe ATK_COMPILATION ?
atk/meson.build
atk_cflags = [ '-DG_LOG_DOMAIN="Atk"', '-DG_LOG_USE_STRUCTURED=1', '-DGLIB_DISABLE_DEPRECATION_WARNINGS', '-DATK_DISABLE_DEPRECATION_WARNINGS', '-DATK_COMPILATION', '-DATK_LOCALEDIR="@0@"'.format(join_paths(atk_datadir, 'locale')), ]
if get_option('introspection') gnome.generate_gir(libatk, sources: atk_sources + atk_headers + [ atk_enum_h ] + [ atk_version_h ], namespace: 'Atk', nsversion: atk_api_version, identifier_prefix: 'Atk', symbol_prefix: 'atk', export_packages: 'atk', includes: [ 'GObject-2.0' ], install: true, extra_args: [ '--quiet', '--c-include=atk/atk.h', '-DATK_COMPILATION', ]) endif
They do, and they pass it via extra_args, not add_project_arguments. Well then, let's modify libgusb to also do it.
Fixing
patching
Let's patch the package.
diff --git a/gusb/meson.build b/gusb/meson.build index 5276259..b6a04d5 100644 --- gusb/meson.build +++ gusb/meson.build @@ -113,6 +113,7 @@ libgusb_girtarget = gnome.generate_gir(gusb, export_packages : 'gusb', extra_args : [ '--c-include=gusb.h', + '-DGUSB_COMPILATION', ], link_with : gusb, dependencies : [
building
Looks good enough, let's try building it.
$ xbps-src -f -a aarch64 pkg libgusb => Registering new packages to /host/binpkgs/libgusb index: added `libgusb-0.3.0_4' (aarch64). index: added `libgusb-devel-0.3.0_4' (aarch64). index: 2 packages registered. $ env XBPS_TARGET_ARCH=aarch64 xls libgusb{,-devel} | grep -E ',(gir|typelib) /usr/lib/girepository-1.0/GUsb-1.0.typelib /usr/share/gir-1.0/GUsb-1.0.gir
Upstreaming
A problem is rarely fixed unless it is upstream, so lets make a pull request.
Closing out
This has been a very annoying bug, that is now fixed.