From 8c3af43ff4d35f864b0ccaa74be5032ae150e264 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 16 May 2020 11:05:58 -0400 Subject: [PATCH] WIP: gobject-introspection cross with pkg-config gobject-introspection is infamous for being difficult to get working with cross compilation. But the situation has improved recently with https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/64, thanks to @kanavin from the Yocto project. The upshot is now only *some*, not all, of the executables need to be run on the host platform with the exe wrapper. On the meson side, there have been two attempts to fix things for cross: - https://github.com/mesonbuild/meson/pull/2965from @kanavin and the Yocto projejct, which because it predates https://github.com/mesonbuild/meson/pull/4010 had to be somewhat hacky - https://github.com/mesonbuild/meson/pull/7072 recently merged which allows specifying some binaries with a cross file. But, I think we can make a more seamless user interface that won't require extra config, like for native builds. gobject-introspection provides the binaries in its pkg-config file, and Meson now cleanly supports separate `native: true` and `native: false` pkg-config paths and lookup. We should just need to add separate `native: true` and `native: false` deps, and I have done that, but I am not sure exactly which should be used when. I am coming at this as a distro maintainer not even particularly involved with gnome things and so I'll need some advice on what to do next. --- mesonbuild/modules/gnome.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 01acb37f148c..f3be06c0bb03 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -29,8 +29,8 @@ from . import ExtensionModule from . import ModuleReturnValue from ..mesonlib import ( - MachineChoice, MesonException, OrderedSet, Popen_safe, extract_as_list, - join_args, unholder, + MachineChoice, MesonException, OrderedSet, Popen_safe, PerMachine, + extract_as_list, join_args, unholder, ) from ..dependencies import Dependency, PkgConfigDependency, InternalDependency, ExternalProgram from ..interpreterbase import noKwargs, permittedKwargs, FeatureNew, FeatureNewKwargs @@ -45,7 +45,7 @@ native_glib_version = None class GnomeModule(ExtensionModule): - gir_dep = None + gir_dep = PerMachine(None, None) @staticmethod def _get_native_glib_version(state): @@ -401,26 +401,26 @@ def _unwrap_gir_target(self, girtarget, state): return girtarget - def _get_gir_dep(self, state): - if not self.gir_dep: - kwargs = {'native': True, 'required': True} + def _get_gir_dep(self, state, for_machine: MachineChoice = MachineChoice.HOST): + if not self.gir_dep[for_machine]: + kwargs = {'native': True if for_machine == MachineChoice.BUILD else False, 'required': True} holder = self.interpreter.func_dependency(state.current_node, ['gobject-introspection-1.0'], kwargs) - self.gir_dep = holder.held_object - giscanner = state.environment.lookup_binary_entry(MachineChoice.HOST, 'g-ir-scanner') + self.gir_dep[for_machine] = holder.held_object + giscanner = state.environment.lookup_binary_entry(for_machine, 'g-ir-scanner') if giscanner is not None: self.giscanner = ExternalProgram.from_entry('g-ir-scanner', giscanner) - elif self.gir_dep.type_name == 'pkgconfig': + elif self.gir_dep[for_machine].type_name == 'pkgconfig': self.giscanner = ExternalProgram('g_ir_scanner', self.gir_dep.get_pkgconfig_variable('g_ir_scanner', {})) else: - self.giscanner = self.interpreter.find_program_impl('g-ir-scanner') - gicompiler = state.environment.lookup_binary_entry(MachineChoice.HOST, 'g-ir-compiler') + self.giscanner = self.interpreter.find_program_impl('g-ir-scanner', kwargs) + gicompiler = state.environment.lookup_binary_entry(for_machine, 'g-ir-compiler') if gicompiler is not None: self.gicompiler = ExternalProgram.from_entry('g-ir-compiler', gicompiler) - elif self.gir_dep.type_name == 'pkgconfig': + elif self.gir_dep[for_machine].type_name == 'pkgconfig': self.gicompiler = ExternalProgram('g_ir_compiler', self.gir_dep.get_pkgconfig_variable('g_ir_compiler', {})) else: - self.gicompiler = self.interpreter.find_program_impl('g-ir-compiler') - return self.gir_dep, self.giscanner, self.gicompiler + self.gicompiler = self.interpreter.find_program_impl('g-ir-compiler', kwargs) + return self.gir_dep[for_machine], self.giscanner, self.gicompiler @functools.lru_cache(maxsize=None) def _gir_has_option(self, option):