[03/26] meson: configure and use generic exe_wrapper

Message ID 20211204071323.2480163-3-alex@linutronix.de
State Accepted, archived
Commit 17fb047282a413aae5af991ecf5bbb225e19581e
Headers show
Series [01/26] insane.bbclass: do not hardcode oe-core path in upstream-status check | expand

Commit Message

Alexander Kanavin Dec. 4, 2021, 7:13 a.m. UTC
This replaces the specific gtkdoc wrapper setting
(which was rejected by upstream in https://github.com/mesonbuild/meson/pull/9627)
with a generic, officially supported and documented exe_wrapper,
which is enabled subject to qemu usermode support
(just as is done for g-i and gtk-doc with autotools).

gtk-doc support is adjusted so that this wrapper is passed to
meson's gtk-doc module, which passes it to gtk-doc.

The adjusted patch is re-submitted upstream.

The side effect of this is that meson is now able to run
target binaries in a generic way when it wants to, so this
may affect cross-builds - hopefully in a positive way.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
 meta/classes/meson.bbclass                    | 30 +++++++++++++++++--
 ...sues-that-arise-when-cross-compiling.patch | 27 +++++++++++------
 2 files changed, 46 insertions(+), 11 deletions(-)

Comments

Hsia-Jun Li Dec. 8, 2021, 9:27 a.m. UTC | #1
On 12/4/21 15:13, Alexander Kanavin wrote:
> CAUTION: Email originated externally, do not click links or open attachments unless you recognize the sender and know the content is safe.
> 
> 
> This replaces the specific gtkdoc wrapper setting
> (which was rejected by upstream in https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_mesonbuild_meson_pull_9627&d=DwIDAg&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=d8BltpV_tYTB24NoB22HJJW4KZkMUZszeTnLXy4O-MA&e= )
> with a generic, officially supported and documented exe_wrapper,
> which is enabled subject to qemu usermode support
> (just as is done for g-i and gtk-doc with autotools).
> 
> gtk-doc support is adjusted so that this wrapper is passed to
> meson's gtk-doc module, which passes it to gtk-doc.
> 
> The adjusted patch is re-submitted upstream.
> 
> The side effect of this is that meson is now able to run
> target binaries in a generic way when it wants to, so this
> may affect cross-builds - hopefully in a positive way.

Unfortunately, the meta layer I made for android native would be the 
victim of that.

| DEBUG: Executing shell function do_configure
| NOTE: Executing meson ...
| qemu-arm: Could not open '/system/bin/linker': No such file or directory
| The Meson build system
| Version: 0.60.1

I am not sure how I should make qemu usermode be compatible with the 
Android environment. I just add "qemu-usermode" into 
MACHINE_FEATURES_BACKFILL_CONSIDERED in the machine configure of the 
meta-android-ndk.

I should report this more early but I can't spend much time on this 
android project.
> 
> Signed-off-by: Alexander Kanavin <alex@linutronix.de>
> ---
>   meta/classes/meson.bbclass                    | 30 +++++++++++++++++--
>   ...sues-that-arise-when-cross-compiling.patch | 27 +++++++++++------
>   2 files changed, 46 insertions(+), 11 deletions(-)
> 
> diff --git a/meta/classes/meson.bbclass b/meta/classes/meson.bbclass
> index a7981e481f..ffec5f3269 100644
> --- a/meta/classes/meson.bbclass
> +++ b/meta/classes/meson.bbclass
> @@ -1,7 +1,12 @@
> -inherit python3native meson-routines
> +inherit python3native meson-routines qemu
> 
>   DEPENDS:append = " meson-native ninja-native"
> 
> +EXEWRAPPER_ENABLED:class-native = "False"
> +EXEWRAPPER_ENABLED:class-nativesdk = "False"
> +EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}"
> +DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}"
> +
>   # As Meson enforces out-of-tree builds we can just use cleandirs
>   B = "${WORKDIR}/build"
>   do_configure[cleandirs] = "${B}"
> @@ -36,6 +41,9 @@ MESON_CROSS_FILE = ""
>   MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
>   MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
> 
> +# Needed to set up qemu wrapper below
> +export STAGING_DIR_HOST
> +
>   def rust_tool(d, target_var):
>       rustc = d.getVar('RUSTC')
>       if not rustc:
> @@ -62,6 +70,7 @@ cups-config = 'cups-config'
>   g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
>   g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
>   ${@rust_tool(d, "HOST_SYS")}
> +${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""}
> 
>   [built-in options]
>   c_args = ${@meson_array('CFLAGS', d)}
> @@ -71,7 +80,6 @@ cpp_link_args = ${@meson_array('LDFLAGS', d)}
> 
>   [properties]
>   needs_exe_wrapper = true
> -gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
> 
>   [host_machine]
>   system = '${@meson_operating_system('HOST_OS', d)}'
> @@ -106,6 +114,24 @@ cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
>   EOF
>   }
> 
> +do_write_config:append:class-target() {
> +    # Write out a qemu wrapper that will be used as exe_wrapper so that meson
> +    # can run target helper binaries through that.
> +    qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
> +    cat > ${WORKDIR}/meson-qemuwrapper << EOF
> +#!/bin/sh
> +# Use a modules directory which doesn't exist so we don't load random things
> +# which may then get deleted (or their dependencies) and potentially segfault
> +export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
> +
> +# meson sets this wrongly (only to libs in build-dir), qemu-wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
> +unset LD_LIBRARY_PATH
> +
> +$qemu_binary "\$@"
> +EOF
> +    chmod +x ${WORKDIR}/meson-qemuwrapper
> +}
> +
>   # Tell externalsrc that changes to this file require a reconfigure
>   CONFIGURE_FILES = "meson.build"
> 
> diff --git a/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch b/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
> index ab4d5969d9..b098c4a123 100644
> --- a/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
> +++ b/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
> @@ -1,29 +1,38 @@
> -From 2f9c59e0489e569c5382404667c10f5c200a72ad Mon Sep 17 00:00:00 2001
> +From bbdd6679e49bcba5ec022b240ac234a87b451e41 Mon Sep 17 00:00:00 2001
>   From: Alexander Kanavin <alex.kanavin@gmail.com>
>   Date: Fri, 4 Aug 2017 16:16:41 +0300
> -Subject: [PATCH] gtkdoc: fix issues that arise when cross-compiling
> +Subject: [PATCH] gtkdoc: add support for a binary wrapper
> 
>   Make it possible to specify a wrapper for executing binaries
> +in cross-compiling scenarios.
>   (usually, some kind of target hardware emulator, such as qemu)
> 
>   Upstream-Status: Submitted [https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_mesonbuild_meson_pull_9627&d=DwIDAg&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=d8BltpV_tYTB24NoB22HJJW4KZkMUZszeTnLXy4O-MA&e= ]
>   Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
> 
>   ---
> - mesonbuild/modules/gnome.py | 4 ++++
> - 1 file changed, 4 insertions(+)
> + mesonbuild/modules/gnome.py | 5 ++++-
> + 1 file changed, 4 insertions(+), 1 deletion(-)
> 
>   diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
> -index dc2979e..c9ff9bd 100644
> +index 1c6952d..5a6ff94 100644
>   --- a/mesonbuild/modules/gnome.py
>   +++ b/mesonbuild/modules/gnome.py
> -@@ -1053,6 +1053,10 @@ class GnomeModule(ExtensionModule):
> +@@ -35,7 +35,7 @@ from ..mesonlib import (
> + from ..dependencies import Dependency, PkgConfigDependency, InternalDependency
> + from ..interpreterbase import noPosargs, noKwargs, permittedKwargs, FeatureNew, FeatureNewKwargs, FeatureDeprecatedKwargs, FeatureDeprecated
> + from ..interpreterbase import typed_kwargs, KwargInfo, ContainerTypeInfo
> +-from ..programs import ExternalProgram, OverrideProgram
> ++from ..programs import ExternalProgram, OverrideProgram, EmptyExternalProgram
> + from ..build import CustomTarget, CustomTargetIndex, GeneratedList
> +
> + if T.TYPE_CHECKING:
> +@@ -1103,6 +1103,9 @@ class GnomeModule(ExtensionModule):
>                args.append(f'--{program_name}={path}')
>            if namespace:
>                args.append('--namespace=' + namespace)
> -+        gtkdoc_exe_wrapper = state.environment.properties.host.get('gtkdoc_exe_wrapper', None)
> -+        if gtkdoc_exe_wrapper is not None:
> -+            args.append('--run=' + gtkdoc_exe_wrapper)
> ++        if state.environment.need_exe_wrapper() and not isinstance(state.environment.get_exe_wrapper(), EmptyExternalProgram):
> ++            args.append('--run=' + ' '.join(state.environment.get_exe_wrapper().get_command()))
>   +
>            args += self._unpack_args('--htmlargs=', 'html_args', kwargs)
>            args += self._unpack_args('--scanargs=', 'scan_args', kwargs)
> --
> 2.20.1
> 
> 
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#159150): https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_message_159150&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=45V6_TRrNONJsAD5I2vogAQnnZusJBFo0xgaXn91aC8&e=
> Mute This Topic: https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_mt_87494764_6350696&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=r1-DZP8UnKe5blruwC2xC0yCg4vPMbgdQB7csVRG5FI&e=
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_unsub&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=aCJ012s9D9DQ3yG-GuuQFs_6APt34sTiwSp8typpm6Q&e=  [randy.li@synaptics.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Alexander Kanavin Dec. 8, 2021, 9:32 a.m. UTC | #2
It seems like the issue is not that qemu can't run the executable, it's
that executable it wants to run is not there. I'm not sure why it wants to
run something in a 'system' location through qemu, as I do not have access
to your layer.

If qemu-usermode is not in MACHINE_FEATURES, then the wrapper is not
configured at all, and so things should go back to what they were. Can you
check that it's not?

Alex

On Wed, 8 Dec 2021 at 10:27, Hsia-Jun Li <Randy.Li@synaptics.com> wrote:

>
>
> On 12/4/21 15:13, Alexander Kanavin wrote:
> > CAUTION: Email originated externally, do not click links or open
> attachments unless you recognize the sender and know the content is safe.
> >
> >
> > This replaces the specific gtkdoc wrapper setting
> > (which was rejected by upstream in
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_mesonbuild_meson_pull_9627&d=DwIDAg&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=d8BltpV_tYTB24NoB22HJJW4KZkMUZszeTnLXy4O-MA&e=
> )
> > with a generic, officially supported and documented exe_wrapper,
> > which is enabled subject to qemu usermode support
> > (just as is done for g-i and gtk-doc with autotools).
> >
> > gtk-doc support is adjusted so that this wrapper is passed to
> > meson's gtk-doc module, which passes it to gtk-doc.
> >
> > The adjusted patch is re-submitted upstream.
> >
> > The side effect of this is that meson is now able to run
> > target binaries in a generic way when it wants to, so this
> > may affect cross-builds - hopefully in a positive way.
>
> Unfortunately, the meta layer I made for android native would be the
> victim of that.
>
> | DEBUG: Executing shell function do_configure
> | NOTE: Executing meson ...
> | qemu-arm: Could not open '/system/bin/linker': No such file or directory
> | The Meson build system
> | Version: 0.60.1
>
> I am not sure how I should make qemu usermode be compatible with the
> Android environment. I just add "qemu-usermode" into
> MACHINE_FEATURES_BACKFILL_CONSIDERED in the machine configure of the
> meta-android-ndk.
>
> I should report this more early but I can't spend much time on this
> android project.
> >
> > Signed-off-by: Alexander Kanavin <alex@linutronix.de>
> > ---
> >   meta/classes/meson.bbclass                    | 30 +++++++++++++++++--
> >   ...sues-that-arise-when-cross-compiling.patch | 27 +++++++++++------
> >   2 files changed, 46 insertions(+), 11 deletions(-)
> >
> > diff --git a/meta/classes/meson.bbclass b/meta/classes/meson.bbclass
> > index a7981e481f..ffec5f3269 100644
> > --- a/meta/classes/meson.bbclass
> > +++ b/meta/classes/meson.bbclass
> > @@ -1,7 +1,12 @@
> > -inherit python3native meson-routines
> > +inherit python3native meson-routines qemu
> >
> >   DEPENDS:append = " meson-native ninja-native"
> >
> > +EXEWRAPPER_ENABLED:class-native = "False"
> > +EXEWRAPPER_ENABLED:class-nativesdk = "False"
> > +EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES',
> 'qemu-usermode', 'True', 'False', d)}"
> > +DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED')
> == 'True' else ''}"
> > +
> >   # As Meson enforces out-of-tree builds we can just use cleandirs
> >   B = "${WORKDIR}/build"
> >   do_configure[cleandirs] = "${B}"
> > @@ -36,6 +41,9 @@ MESON_CROSS_FILE = ""
> >   MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
> >   MESON_CROSS_FILE:class-nativesdk = "--cross-file
> ${WORKDIR}/meson.cross"
> >
> > +# Needed to set up qemu wrapper below
> > +export STAGING_DIR_HOST
> > +
> >   def rust_tool(d, target_var):
> >       rustc = d.getVar('RUSTC')
> >       if not rustc:
> > @@ -62,6 +70,7 @@ cups-config = 'cups-config'
> >   g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
> >   g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
> >   ${@rust_tool(d, "HOST_SYS")}
> > +${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if
> d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""}
> >
> >   [built-in options]
> >   c_args = ${@meson_array('CFLAGS', d)}
> > @@ -71,7 +80,6 @@ cpp_link_args = ${@meson_array('LDFLAGS', d)}
> >
> >   [properties]
> >   needs_exe_wrapper = true
> > -gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
> >
> >   [host_machine]
> >   system = '${@meson_operating_system('HOST_OS', d)}'
> > @@ -106,6 +114,24 @@ cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
> >   EOF
> >   }
> >
> > +do_write_config:append:class-target() {
> > +    # Write out a qemu wrapper that will be used as exe_wrapper so that
> meson
> > +    # can run target helper binaries through that.
> > +    qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST',
> ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
> > +    cat > ${WORKDIR}/meson-qemuwrapper << EOF
> > +#!/bin/sh
> > +# Use a modules directory which doesn't exist so we don't load random
> things
> > +# which may then get deleted (or their dependencies) and potentially
> segfault
> > +export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
> > +
> > +# meson sets this wrongly (only to libs in build-dir),
> qemu-wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
> > +unset LD_LIBRARY_PATH
> > +
> > +$qemu_binary "\$@"
> > +EOF
> > +    chmod +x ${WORKDIR}/meson-qemuwrapper
> > +}
> > +
> >   # Tell externalsrc that changes to this file require a reconfigure
> >   CONFIGURE_FILES = "meson.build"
> >
> > diff --git
> a/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
> b/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
> > index ab4d5969d9..b098c4a123 100644
> > ---
> a/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
> > +++
> b/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
> > @@ -1,29 +1,38 @@
> > -From 2f9c59e0489e569c5382404667c10f5c200a72ad Mon Sep 17 00:00:00 2001
> > +From bbdd6679e49bcba5ec022b240ac234a87b451e41 Mon Sep 17 00:00:00 2001
> >   From: Alexander Kanavin <alex.kanavin@gmail.com>
> >   Date: Fri, 4 Aug 2017 16:16:41 +0300
> > -Subject: [PATCH] gtkdoc: fix issues that arise when cross-compiling
> > +Subject: [PATCH] gtkdoc: add support for a binary wrapper
> >
> >   Make it possible to specify a wrapper for executing binaries
> > +in cross-compiling scenarios.
> >   (usually, some kind of target hardware emulator, such as qemu)
> >
> >   Upstream-Status: Submitted [
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_mesonbuild_meson_pull_9627&d=DwIDAg&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=d8BltpV_tYTB24NoB22HJJW4KZkMUZszeTnLXy4O-MA&e=
> ]
> >   Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
> >
> >   ---
> > - mesonbuild/modules/gnome.py | 4 ++++
> > - 1 file changed, 4 insertions(+)
> > + mesonbuild/modules/gnome.py | 5 ++++-
> > + 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> >   diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
> > -index dc2979e..c9ff9bd 100644
> > +index 1c6952d..5a6ff94 100644
> >   --- a/mesonbuild/modules/gnome.py
> >   +++ b/mesonbuild/modules/gnome.py
> > -@@ -1053,6 +1053,10 @@ class GnomeModule(ExtensionModule):
> > +@@ -35,7 +35,7 @@ from ..mesonlib import (
> > + from ..dependencies import Dependency, PkgConfigDependency,
> InternalDependency
> > + from ..interpreterbase import noPosargs, noKwargs, permittedKwargs,
> FeatureNew, FeatureNewKwargs, FeatureDeprecatedKwargs, FeatureDeprecated
> > + from ..interpreterbase import typed_kwargs, KwargInfo,
> ContainerTypeInfo
> > +-from ..programs import ExternalProgram, OverrideProgram
> > ++from ..programs import ExternalProgram, OverrideProgram,
> EmptyExternalProgram
> > + from ..build import CustomTarget, CustomTargetIndex, GeneratedList
> > +
> > + if T.TYPE_CHECKING:
> > +@@ -1103,6 +1103,9 @@ class GnomeModule(ExtensionModule):
> >                args.append(f'--{program_name}={path}')
> >            if namespace:
> >                args.append('--namespace=' + namespace)
> > -+        gtkdoc_exe_wrapper =
> state.environment.properties.host.get('gtkdoc_exe_wrapper', None)
> > -+        if gtkdoc_exe_wrapper is not None:
> > -+            args.append('--run=' + gtkdoc_exe_wrapper)
> > ++        if state.environment.need_exe_wrapper() and not
> isinstance(state.environment.get_exe_wrapper(), EmptyExternalProgram):
> > ++            args.append('--run=' + '
> '.join(state.environment.get_exe_wrapper().get_command()))
> >   +
> >            args += self._unpack_args('--htmlargs=', 'html_args', kwargs)
> >            args += self._unpack_args('--scanargs=', 'scan_args', kwargs)
> > --
> > 2.20.1
> >
> >
> >
> > -=-=-=-=-=-=-=-=-=-=-=-
> > Links: You receive all messages sent to this group.
> > View/Reply Online (#159150):
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_message_159150&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=45V6_TRrNONJsAD5I2vogAQnnZusJBFo0xgaXn91aC8&e=
> > Mute This Topic:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_mt_87494764_6350696&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=r1-DZP8UnKe5blruwC2xC0yCg4vPMbgdQB7csVRG5FI&e=
> > Group Owner: openembedded-core+owner@lists.openembedded.org
> > Unsubscribe:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_unsub&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=aCJ012s9D9DQ3yG-GuuQFs_6APt34sTiwSp8typpm6Q&e=
> [randy.li@synaptics.com]
> > -=-=-=-=-=-=-=-=-=-=-=-
> >
>
> --
> Hsia-Jun(Randy) Li
>
Hsia-Jun Li Dec. 9, 2021, 2:55 a.m. UTC | #3
On 12/8/21 17:32, Alexander Kanavin wrote:
> CAUTION: Email originated externally, do not click links or open 
> attachments unless you recognize the sender and know the content is safe.
> 
> It seems like the issue is not that qemu can't run the executable, it's 
> that executable it wants to run is not there. I'm not sure why it wants 
> to run something in a 'system' location through qemu, as I do not have 
> access to your layer.
/system/bin/linker is the dynamic linker in Android system.
https://android.googlesource.com/platform/bionic/
Of course it won't be there, it even doesn't exist in the toolchains.

That layer for android ndk is hosted here
https://github.com/hizukiayaka/meta-android-ndk

> 
> If qemu-usermode is not in MACHINE_FEATURES, then the wrapper is not 
> configured at all, and so things should go back to what they were. Can 
> you check that it's not?

Sorry, I don't understand what I could check.
The exe_wrapper option in meson cross file would disappear when that 
feature is removed. And everything would be fine then.
> 
> Alex
> 
> On Wed, 8 Dec 2021 at 10:27, Hsia-Jun Li <Randy.Li@synaptics.com 
> <mailto:Randy.Li@synaptics.com>> wrote:
> 
> 
> 
>     On 12/4/21 15:13, Alexander Kanavin wrote:
>      > CAUTION: Email originated externally, do not click links or open
>     attachments unless you recognize the sender and know the content is
>     safe.
>      >
>      >
>      > This replaces the specific gtkdoc wrapper setting
>      > (which was rejected by upstream in
>     https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_mesonbuild_meson_pull_9627&d=DwIDAg&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=d8BltpV_tYTB24NoB22HJJW4KZkMUZszeTnLXy4O-MA&e=
>     <https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_mesonbuild_meson_pull_9627&d=DwIDAg&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=d8BltpV_tYTB24NoB22HJJW4KZkMUZszeTnLXy4O-MA&e=>
>     )
>      > with a generic, officially supported and documented exe_wrapper,
>      > which is enabled subject to qemu usermode support
>      > (just as is done for g-i and gtk-doc with autotools).
>      >
>      > gtk-doc support is adjusted so that this wrapper is passed to
>      > meson's gtk-doc module, which passes it to gtk-doc.
>      >
>      > The adjusted patch is re-submitted upstream.
>      >
>      > The side effect of this is that meson is now able to run
>      > target binaries in a generic way when it wants to, so this
>      > may affect cross-builds - hopefully in a positive way.
> 
>     Unfortunately, the meta layer I made for android native would be the
>     victim of that.
> 
>     | DEBUG: Executing shell function do_configure
>     | NOTE: Executing meson ...
>     | qemu-arm: Could not open '/system/bin/linker': No such file or
>     directory
>     | The Meson build system
>     | Version: 0.60.1
> 
>     I am not sure how I should make qemu usermode be compatible with the
>     Android environment. I just add "qemu-usermode" into
>     MACHINE_FEATURES_BACKFILL_CONSIDERED in the machine configure of the
>     meta-android-ndk.
> 
>     I should report this more early but I can't spend much time on this
>     android project.
>      >
>      > Signed-off-by: Alexander Kanavin <alex@linutronix.de
>     <mailto:alex@linutronix.de>>
>      > ---
>      >   meta/classes/meson.bbclass                    | 30
>     +++++++++++++++++--
>      >   ...sues-that-arise-when-cross-compiling.patch | 27
>     +++++++++++------
>      >   2 files changed, 46 insertions(+), 11 deletions(-)
>      >
>      > diff --git a/meta/classes/meson.bbclass b/meta/classes/meson.bbclass
>      > index a7981e481f..ffec5f3269 100644
>      > --- a/meta/classes/meson.bbclass
>      > +++ b/meta/classes/meson.bbclass
>      > @@ -1,7 +1,12 @@
>      > -inherit python3native meson-routines
>      > +inherit python3native meson-routines qemu
>      >
>      >   DEPENDS:append = " meson-native ninja-native"
>      >
>      > +EXEWRAPPER_ENABLED:class-native = "False"
>      > +EXEWRAPPER_ENABLED:class-nativesdk = "False"
>      > +EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES',
>     'qemu-usermode', 'True', 'False', d)}"
>      > +DEPENDS:append = "${@' qemu-native' if
>     d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}"
>      > +
>      >   # As Meson enforces out-of-tree builds we can just use cleandirs
>      >   B = "${WORKDIR}/build"
>      >   do_configure[cleandirs] = "${B}"
>      > @@ -36,6 +41,9 @@ MESON_CROSS_FILE = ""
>      >   MESON_CROSS_FILE:class-target = "--cross-file
>     ${WORKDIR}/meson.cross"
>      >   MESON_CROSS_FILE:class-nativesdk = "--cross-file
>     ${WORKDIR}/meson.cross"
>      >
>      > +# Needed to set up qemu wrapper below
>      > +export STAGING_DIR_HOST
>      > +
>      >   def rust_tool(d, target_var):
>      >       rustc = d.getVar('RUSTC')
>      >       if not rustc:
>      > @@ -62,6 +70,7 @@ cups-config = 'cups-config'
>      >   g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
>      >   g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
>      >   ${@rust_tool(d, "HOST_SYS")}
>      > +${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if
>     d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""}
>      >
>      >   [built-in options]
>      >   c_args = ${@meson_array('CFLAGS', d)}
>      > @@ -71,7 +80,6 @@ cpp_link_args = ${@meson_array('LDFLAGS', d)}
>      >
>      >   [properties]
>      >   needs_exe_wrapper = true
>      > -gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
>      >
>      >   [host_machine]
>      >   system = '${@meson_operating_system('HOST_OS', d)}'
>      > @@ -106,6 +114,24 @@ cpp_link_args =
>     ${@meson_array('BUILD_LDFLAGS', d)}
>      >   EOF
>      >   }
>      >
>      > +do_write_config:append:class-target() {
>      > +    # Write out a qemu wrapper that will be used as exe_wrapper
>     so that meson
>      > +    # can run target helper binaries through that.
>      > +    qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST',
>     ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
>      > +    cat > ${WORKDIR}/meson-qemuwrapper << EOF
>      > +#!/bin/sh
>      > +# Use a modules directory which doesn't exist so we don't load
>     random things
>      > +# which may then get deleted (or their dependencies) and
>     potentially segfault
>      > +export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
>      > +
>      > +# meson sets this wrongly (only to libs in build-dir),
>     qemu-wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
>      > +unset LD_LIBRARY_PATH
>      > +
>      > +$qemu_binary "\$@"
>      > +EOF
>      > +    chmod +x ${WORKDIR}/meson-qemuwrapper
>      > +}
>      > +
>      >   # Tell externalsrc that changes to this file require a reconfigure
>      >   CONFIGURE_FILES = "meson.build"
>      >
>      > diff --git
>     a/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
>     b/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
>      > index ab4d5969d9..b098c4a123 100644
>      > ---
>     a/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
>      > +++
>     b/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
>      > @@ -1,29 +1,38 @@
>      > -From 2f9c59e0489e569c5382404667c10f5c200a72ad Mon Sep 17
>     00:00:00 2001
>      > +From bbdd6679e49bcba5ec022b240ac234a87b451e41 Mon Sep 17
>     00:00:00 2001
>      >   From: Alexander Kanavin <alex.kanavin@gmail.com
>     <mailto:alex.kanavin@gmail.com>>
>      >   Date: Fri, 4 Aug 2017 16:16:41 +0300
>      > -Subject: [PATCH] gtkdoc: fix issues that arise when cross-compiling
>      > +Subject: [PATCH] gtkdoc: add support for a binary wrapper
>      >
>      >   Make it possible to specify a wrapper for executing binaries
>      > +in cross-compiling scenarios.
>      >   (usually, some kind of target hardware emulator, such as qemu)
>      >
>      >   Upstream-Status: Submitted
>     [https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_mesonbuild_meson_pull_9627&d=DwIDAg&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=d8BltpV_tYTB24NoB22HJJW4KZkMUZszeTnLXy4O-MA&e=
>     <https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_mesonbuild_meson_pull_9627&d=DwIDAg&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=d8BltpV_tYTB24NoB22HJJW4KZkMUZszeTnLXy4O-MA&e=>
>     ]
>      >   Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com
>     <mailto:alex.kanavin@gmail.com>>
>      >
>      >   ---
>      > - mesonbuild/modules/gnome.py | 4 ++++
>      > - 1 file changed, 4 insertions(+)
>      > + mesonbuild/modules/gnome.py | 5 ++++-
>      > + 1 file changed, 4 insertions(+), 1 deletion(-)
>      >
>      >   diff --git a/mesonbuild/modules/gnome.py
>     b/mesonbuild/modules/gnome.py
>      > -index dc2979e..c9ff9bd 100644
>      > +index 1c6952d..5a6ff94 100644
>      >   --- a/mesonbuild/modules/gnome.py
>      >   +++ b/mesonbuild/modules/gnome.py
>      > -@@ -1053,6 +1053,10 @@ class GnomeModule(ExtensionModule):
>      > +@@ -35,7 +35,7 @@ from ..mesonlib import (
>      > + from ..dependencies import Dependency, PkgConfigDependency,
>     InternalDependency
>      > + from ..interpreterbase import noPosargs, noKwargs,
>     permittedKwargs, FeatureNew, FeatureNewKwargs,
>     FeatureDeprecatedKwargs, FeatureDeprecated
>      > + from ..interpreterbase import typed_kwargs, KwargInfo,
>     ContainerTypeInfo
>      > +-from ..programs import ExternalProgram, OverrideProgram
>      > ++from ..programs import ExternalProgram, OverrideProgram,
>     EmptyExternalProgram
>      > + from ..build import CustomTarget, CustomTargetIndex, GeneratedList
>      > +
>      > + if T.TYPE_CHECKING:
>      > +@@ -1103,6 +1103,9 @@ class GnomeModule(ExtensionModule):
>      >                args.append(f'--{program_name}={path}')
>      >            if namespace:
>      >                args.append('--namespace=' + namespace)
>      > -+        gtkdoc_exe_wrapper =
>     state.environment.properties.host.get('gtkdoc_exe_wrapper', None)
>      > -+        if gtkdoc_exe_wrapper is not None:
>      > -+            args.append('--run=' + gtkdoc_exe_wrapper)
>      > ++        if state.environment.need_exe_wrapper() and not
>     isinstance(state.environment.get_exe_wrapper(), EmptyExternalProgram):
>      > ++            args.append('--run=' + '
>     '.join(state.environment.get_exe_wrapper().get_command()))
>      >   +
>      >            args += self._unpack_args('--htmlargs=', 'html_args',
>     kwargs)
>      >            args += self._unpack_args('--scanargs=', 'scan_args',
>     kwargs)
>      > --
>      > 2.20.1
>      >
>      >
>      >
>      > -=-=-=-=-=-=-=-=-=-=-=-
>      > Links: You receive all messages sent to this group.
>      > View/Reply Online (#159150):
>     https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_message_159150&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=45V6_TRrNONJsAD5I2vogAQnnZusJBFo0xgaXn91aC8&e=
>     <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_message_159150&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=45V6_TRrNONJsAD5I2vogAQnnZusJBFo0xgaXn91aC8&e=>
>      > Mute This Topic:
>     https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_mt_87494764_6350696&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=r1-DZP8UnKe5blruwC2xC0yCg4vPMbgdQB7csVRG5FI&e=
>     <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_mt_87494764_6350696&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=r1-DZP8UnKe5blruwC2xC0yCg4vPMbgdQB7csVRG5FI&e=>
>      > Group Owner: openembedded-core+owner@lists.openembedded.org
>     <mailto:openembedded-core%2Bowner@lists.openembedded.org>
>      > Unsubscribe:
>     https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_unsub&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=aCJ012s9D9DQ3yG-GuuQFs_6APt34sTiwSp8typpm6Q&e=
>     <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_unsub&d=DwIFaQ&c=7dfBJ8cXbWjhc0BhImu8wVIoUFmBzj1s88r8EGyM0UY&r=P4xb2_7biqBxD4LGGPrSV6j-jf3C3xlR7PXU-mLTeZE&m=CAFnH4fxB5TbFzRZLDRgLtKrp2ZzM4vwpRgeHylkuqrk5HT83nok425kJ_nXRe4e&s=aCJ012s9D9DQ3yG-GuuQFs_6APt34sTiwSp8typpm6Q&e=>
>     [randy.li@synaptics.com <mailto:randy.li@synaptics.com>]
>      > -=-=-=-=-=-=-=-=-=-=-=-
>      >
> 
>     -- 
>     Hsia-Jun(Randy) Li
>
Matt Madison Dec. 15, 2021, 2:07 p.m. UTC | #4
On Fri, Dec 3, 2021 at 11:13 PM Alexander Kanavin <alex.kanavin@gmail.com>
wrote:

> This replaces the specific gtkdoc wrapper setting
> (which was rejected by upstream in
> https://github.com/mesonbuild/meson/pull/9627)
> with a generic, officially supported and documented exe_wrapper,
> which is enabled subject to qemu usermode support
> (just as is done for g-i and gtk-doc with autotools).
>
> gtk-doc support is adjusted so that this wrapper is passed to
> meson's gtk-doc module, which passes it to gtk-doc.
>
> The adjusted patch is re-submitted upstream.
>
> The side effect of this is that meson is now able to run
> target binaries in a generic way when it wants to, so this
> may affect cross-builds - hopefully in a positive way.
>

Inheriting the qemu class unconditionally causes task hash changes for
allarch recipes
that use meson (e.g. cantarell-fonts) when MACHINE is changed from, say, an
x86 architecture
to an aarch64 architecture, due to the qemu bbclass referencing the
OLDEST_KERNEL
variable.

I'm not sure of the best way to fix this; doing an overwrite of
OLDEST_KERNEL in
allarch.bbclass as is done for some other variables might be OK? I'm not
sure it
makes sense for allarch recipes to reference any QEMU stuff at all, so
maybe splitting
all of the exe_wrapper support into a separate bbclass that is only
inherited when
EXEWRAPPER_ENABLED is True is better?

Thanks,
-Matt


>
> Signed-off-by: Alexander Kanavin <alex@linutronix.de>
> ---
>  meta/classes/meson.bbclass                    | 30 +++++++++++++++++--
>  ...sues-that-arise-when-cross-compiling.patch | 27 +++++++++++------
>  2 files changed, 46 insertions(+), 11 deletions(-)
>
> diff --git a/meta/classes/meson.bbclass b/meta/classes/meson.bbclass
> index a7981e481f..ffec5f3269 100644
> --- a/meta/classes/meson.bbclass
> +++ b/meta/classes/meson.bbclass
> @@ -1,7 +1,12 @@
> -inherit python3native meson-routines
> +inherit python3native meson-routines qemu
>
>  DEPENDS:append = " meson-native ninja-native"
>
> +EXEWRAPPER_ENABLED:class-native = "False"
> +EXEWRAPPER_ENABLED:class-nativesdk = "False"
> +EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES',
> 'qemu-usermode', 'True', 'False', d)}"
> +DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') ==
> 'True' else ''}"
> +
>  # As Meson enforces out-of-tree builds we can just use cleandirs
>  B = "${WORKDIR}/build"
>  do_configure[cleandirs] = "${B}"
> @@ -36,6 +41,9 @@ MESON_CROSS_FILE = ""
>  MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
>  MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
>
> +# Needed to set up qemu wrapper below
> +export STAGING_DIR_HOST
> +
>  def rust_tool(d, target_var):
>      rustc = d.getVar('RUSTC')
>      if not rustc:
> @@ -62,6 +70,7 @@ cups-config = 'cups-config'
>  g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
>  g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
>  ${@rust_tool(d, "HOST_SYS")}
> +${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if
> d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""}
>
>  [built-in options]
>  c_args = ${@meson_array('CFLAGS', d)}
> @@ -71,7 +80,6 @@ cpp_link_args = ${@meson_array('LDFLAGS', d)}
>
>  [properties]
>  needs_exe_wrapper = true
> -gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
>
>  [host_machine]
>  system = '${@meson_operating_system('HOST_OS', d)}'
> @@ -106,6 +114,24 @@ cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
>  EOF
>  }
>
> +do_write_config:append:class-target() {
> +    # Write out a qemu wrapper that will be used as exe_wrapper so that
> meson
> +    # can run target helper binaries through that.
> +    qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST',
> ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
> +    cat > ${WORKDIR}/meson-qemuwrapper << EOF
> +#!/bin/sh
> +# Use a modules directory which doesn't exist so we don't load random
> things
> +# which may then get deleted (or their dependencies) and potentially
> segfault
> +export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
> +
> +# meson sets this wrongly (only to libs in build-dir),
> qemu-wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
> +unset LD_LIBRARY_PATH
> +
> +$qemu_binary "\$@"
> +EOF
> +    chmod +x ${WORKDIR}/meson-qemuwrapper
> +}
> +
>  # Tell externalsrc that changes to this file require a reconfigure
>  CONFIGURE_FILES = "meson.build"
>
> diff --git
> a/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
> b/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
> index ab4d5969d9..b098c4a123 100644
> ---
> a/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
> +++
> b/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
> @@ -1,29 +1,38 @@
> -From 2f9c59e0489e569c5382404667c10f5c200a72ad Mon Sep 17 00:00:00 2001
> +From bbdd6679e49bcba5ec022b240ac234a87b451e41 Mon Sep 17 00:00:00 2001
>  From: Alexander Kanavin <alex.kanavin@gmail.com>
>  Date: Fri, 4 Aug 2017 16:16:41 +0300
> -Subject: [PATCH] gtkdoc: fix issues that arise when cross-compiling
> +Subject: [PATCH] gtkdoc: add support for a binary wrapper
>
>  Make it possible to specify a wrapper for executing binaries
> +in cross-compiling scenarios.
>  (usually, some kind of target hardware emulator, such as qemu)
>
>  Upstream-Status: Submitted [https://github.com/mesonbuild/meson/pull/9627
> ]
>  Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
>
>  ---
> - mesonbuild/modules/gnome.py | 4 ++++
> - 1 file changed, 4 insertions(+)
> + mesonbuild/modules/gnome.py | 5 ++++-
> + 1 file changed, 4 insertions(+), 1 deletion(-)
>
>  diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
> -index dc2979e..c9ff9bd 100644
> +index 1c6952d..5a6ff94 100644
>  --- a/mesonbuild/modules/gnome.py
>  +++ b/mesonbuild/modules/gnome.py
> -@@ -1053,6 +1053,10 @@ class GnomeModule(ExtensionModule):
> +@@ -35,7 +35,7 @@ from ..mesonlib import (
> + from ..dependencies import Dependency, PkgConfigDependency,
> InternalDependency
> + from ..interpreterbase import noPosargs, noKwargs, permittedKwargs,
> FeatureNew, FeatureNewKwargs, FeatureDeprecatedKwargs, FeatureDeprecated
> + from ..interpreterbase import typed_kwargs, KwargInfo, ContainerTypeInfo
> +-from ..programs import ExternalProgram, OverrideProgram
> ++from ..programs import ExternalProgram, OverrideProgram,
> EmptyExternalProgram
> + from ..build import CustomTarget, CustomTargetIndex, GeneratedList
> +
> + if T.TYPE_CHECKING:
> +@@ -1103,6 +1103,9 @@ class GnomeModule(ExtensionModule):
>               args.append(f'--{program_name}={path}')
>           if namespace:
>               args.append('--namespace=' + namespace)
> -+        gtkdoc_exe_wrapper =
> state.environment.properties.host.get('gtkdoc_exe_wrapper', None)
> -+        if gtkdoc_exe_wrapper is not None:
> -+            args.append('--run=' + gtkdoc_exe_wrapper)
> ++        if state.environment.need_exe_wrapper() and not
> isinstance(state.environment.get_exe_wrapper(), EmptyExternalProgram):
> ++            args.append('--run=' + '
> '.join(state.environment.get_exe_wrapper().get_command()))
>  +
>           args += self._unpack_args('--htmlargs=', 'html_args', kwargs)
>           args += self._unpack_args('--scanargs=', 'scan_args', kwargs)
> --
> 2.20.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#159150):
> https://lists.openembedded.org/g/openembedded-core/message/159150
> Mute This Topic: https://lists.openembedded.org/mt/87494764/3618418
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub
> [matt@madison.systems]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
Alexander Kanavin Dec. 15, 2021, 2:52 p.m. UTC | #5
On Wed, 15 Dec 2021 at 15:07, Matt Madison <matt@madison.systems> wrote:

> Inheriting the qemu class unconditionally causes task hash changes for
> allarch recipes
> that use meson (e.g. cantarell-fonts) when MACHINE is changed from, say,
> an x86 architecture
> to an aarch64 architecture, due to the qemu bbclass referencing the
> OLDEST_KERNEL
> variable.
>
> I'm not sure of the best way to fix this; doing an overwrite of
> OLDEST_KERNEL in
> allarch.bbclass as is done for some other variables might be OK? I'm not
> sure it
> makes sense for allarch recipes to reference any QEMU stuff at all, so
> maybe splitting
> all of the exe_wrapper support into a separate bbclass that is only
> inherited when
> EXEWRAPPER_ENABLED is True is better?
>

To be honest, I have no idea why passing '-r OLDEST_KERNEL' is there to
begin with. It's very old code which I didn't write, so maybe you can
submit a patch that removes it and I'll give it a spin?

Alex
Khem Raj Dec. 15, 2021, 5:40 p.m. UTC | #6
On 12/15/21 6:52 AM, Alexander Kanavin wrote:
> On Wed, 15 Dec 2021 at 15:07, Matt Madison <matt@madison.systems> wrote:
> 
>     Inheriting the qemu class unconditionally causes task hash changes
>     for allarch recipes
>     that use meson (e.g. cantarell-fonts) when MACHINE is changed from,
>     say, an x86 architecture
>     to an aarch64 architecture, due to the qemu bbclass referencing the
>     OLDEST_KERNEL
>     variable.
> 
>     I'm not sure of the best way to fix this; doing an overwrite of
>     OLDEST_KERNEL in
>     allarch.bbclass as is done for some other variables might be OK? I'm
>     not sure it
>     makes sense for allarch recipes to reference any QEMU stuff at all,
>     so maybe splitting
>     all of the exe_wrapper support into a separate bbclass that is only
>     inherited when
>     EXEWRAPPER_ENABLED is True is better?
> 
> 
> To be honest, I have no idea why passing '-r OLDEST_KERNEL' is there to 
> begin with. It's very old code which I didn't write, so maybe you can 
> submit a patch that removes it and I'll give it a spin?

This option helps detach host kernel version from what target kernel is, 
many architectures requires newer kernels as minimum kernels due to them 
being new and stable ABIs for them being completed in newer releases. So 
if one built aarch64 on really old distro which has kernel < 3.8 then 
aarch64 binaries will fail to run in qemu user mode complaining about 
too old kernel.

having said that, since then qemu now defines arhitecture specific 
UNAME_MINIMUM_RELEASE and calibrates  UNAME to UNAME_MINIMUM_RELEASE if 
QEMU_UNAME is older which means we do not need to set it explicitly 
usiing -r option anymore.

I did however found a bug in qemu where this value was not set properly 
for riscv32 which I have sent a fix upstream.

Lets try dropping -r option, I think it should work. Good test would be
building qemuarm64 on a build host running < 3.8 kernel and see if all 
builds ok. or qemuriscv64 on hosts with kernel < 4.15



> 
> Alex
> 
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#159726): https://lists.openembedded.org/g/openembedded-core/message/159726
> Mute This Topic: https://lists.openembedded.org/mt/87494764/1997914
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Alexander Kanavin Dec. 15, 2021, 5:43 p.m. UTC | #7
On Wed, 15 Dec 2021 at 18:40, Khem Raj <raj.khem@gmail.com> wrote:

>
> Lets try dropping -r option, I think it should work. Good test would be
> building qemuarm64 on a build host running < 3.8 kernel and see if all
> builds ok. or qemuriscv64 on hosts with kernel < 4.15
>

I don't think such hosts are tested or supported, and they're going to
break in various other ways anyway.

Alex
Khem Raj Dec. 15, 2021, 5:56 p.m. UTC | #8
On 12/15/21 9:43 AM, Alexander Kanavin wrote:
> On Wed, 15 Dec 2021 at 18:40, Khem Raj <raj.khem@gmail.com 
> <mailto:raj.khem@gmail.com>> wrote:
> 
> 
>     Lets try dropping -r option, I think it should work. Good test would be
>     building qemuarm64 on a build host running < 3.8 kernel and see if all
>     builds ok. or qemuriscv64 on hosts with kernel < 4.15
> 
> 
> I don't think such hosts are tested or supported, and they're going to 
> break in various other ways anyway.
> 

Picking from set that yocto project supports

https://docs.yoctoproject.org/ref-manual/system-requirements.html?highlight=system%20requirement#supported-linux-distributions

( centos8 uses 4.18, centos7 uses 3.10, and debian8 uses 3.16 )

> Alex
Alexander Kanavin Dec. 15, 2021, 6:57 p.m. UTC | #9
On Wed, 15 Dec 2021 at 18:56, Khem Raj <raj.khem@gmail.com> wrote:

Picking from set that yocto project supports
>
>
> https://docs.yoctoproject.org/ref-manual/system-requirements.html?highlight=system%20requirement#supported-linux-distributions
>
> ( centos8 uses 4.18, centos7 uses 3.10, and debian8 uses 3.16 )
>

debian 8 has been retired from the AB, so it's just centos 7 - I wonder why
we still need to support it as a host for master; are there actual YP
members explicitly asking for it?

Alex

Patch

diff --git a/meta/classes/meson.bbclass b/meta/classes/meson.bbclass
index a7981e481f..ffec5f3269 100644
--- a/meta/classes/meson.bbclass
+++ b/meta/classes/meson.bbclass
@@ -1,7 +1,12 @@ 
-inherit python3native meson-routines
+inherit python3native meson-routines qemu
 
 DEPENDS:append = " meson-native ninja-native"
 
+EXEWRAPPER_ENABLED:class-native = "False"
+EXEWRAPPER_ENABLED:class-nativesdk = "False"
+EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}"
+DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}"
+
 # As Meson enforces out-of-tree builds we can just use cleandirs
 B = "${WORKDIR}/build"
 do_configure[cleandirs] = "${B}"
@@ -36,6 +41,9 @@  MESON_CROSS_FILE = ""
 MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
 MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
 
+# Needed to set up qemu wrapper below
+export STAGING_DIR_HOST
+
 def rust_tool(d, target_var):
     rustc = d.getVar('RUSTC')
     if not rustc:
@@ -62,6 +70,7 @@  cups-config = 'cups-config'
 g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
 g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
 ${@rust_tool(d, "HOST_SYS")}
+${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""}
 
 [built-in options]
 c_args = ${@meson_array('CFLAGS', d)}
@@ -71,7 +80,6 @@  cpp_link_args = ${@meson_array('LDFLAGS', d)}
 
 [properties]
 needs_exe_wrapper = true
-gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
 
 [host_machine]
 system = '${@meson_operating_system('HOST_OS', d)}'
@@ -106,6 +114,24 @@  cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
 EOF
 }
 
+do_write_config:append:class-target() {
+    # Write out a qemu wrapper that will be used as exe_wrapper so that meson
+    # can run target helper binaries through that.
+    qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
+    cat > ${WORKDIR}/meson-qemuwrapper << EOF
+#!/bin/sh
+# Use a modules directory which doesn't exist so we don't load random things
+# which may then get deleted (or their dependencies) and potentially segfault
+export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
+
+# meson sets this wrongly (only to libs in build-dir), qemu-wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
+unset LD_LIBRARY_PATH
+
+$qemu_binary "\$@"
+EOF
+    chmod +x ${WORKDIR}/meson-qemuwrapper
+}
+
 # Tell externalsrc that changes to this file require a reconfigure
 CONFIGURE_FILES = "meson.build"
 
diff --git a/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch b/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
index ab4d5969d9..b098c4a123 100644
--- a/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
+++ b/meta/recipes-devtools/meson/meson/0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch
@@ -1,29 +1,38 @@ 
-From 2f9c59e0489e569c5382404667c10f5c200a72ad Mon Sep 17 00:00:00 2001
+From bbdd6679e49bcba5ec022b240ac234a87b451e41 Mon Sep 17 00:00:00 2001
 From: Alexander Kanavin <alex.kanavin@gmail.com>
 Date: Fri, 4 Aug 2017 16:16:41 +0300
-Subject: [PATCH] gtkdoc: fix issues that arise when cross-compiling
+Subject: [PATCH] gtkdoc: add support for a binary wrapper
 
 Make it possible to specify a wrapper for executing binaries
+in cross-compiling scenarios.
 (usually, some kind of target hardware emulator, such as qemu)
 
 Upstream-Status: Submitted [https://github.com/mesonbuild/meson/pull/9627]
 Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
 
 ---
- mesonbuild/modules/gnome.py | 4 ++++
- 1 file changed, 4 insertions(+)
+ mesonbuild/modules/gnome.py | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
 
 diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
-index dc2979e..c9ff9bd 100644
+index 1c6952d..5a6ff94 100644
 --- a/mesonbuild/modules/gnome.py
 +++ b/mesonbuild/modules/gnome.py
-@@ -1053,6 +1053,10 @@ class GnomeModule(ExtensionModule):
+@@ -35,7 +35,7 @@ from ..mesonlib import (
+ from ..dependencies import Dependency, PkgConfigDependency, InternalDependency
+ from ..interpreterbase import noPosargs, noKwargs, permittedKwargs, FeatureNew, FeatureNewKwargs, FeatureDeprecatedKwargs, FeatureDeprecated
+ from ..interpreterbase import typed_kwargs, KwargInfo, ContainerTypeInfo
+-from ..programs import ExternalProgram, OverrideProgram
++from ..programs import ExternalProgram, OverrideProgram, EmptyExternalProgram
+ from ..build import CustomTarget, CustomTargetIndex, GeneratedList
+ 
+ if T.TYPE_CHECKING:
+@@ -1103,6 +1103,9 @@ class GnomeModule(ExtensionModule):
              args.append(f'--{program_name}={path}')
          if namespace:
              args.append('--namespace=' + namespace)
-+        gtkdoc_exe_wrapper = state.environment.properties.host.get('gtkdoc_exe_wrapper', None)
-+        if gtkdoc_exe_wrapper is not None:
-+            args.append('--run=' + gtkdoc_exe_wrapper)
++        if state.environment.need_exe_wrapper() and not isinstance(state.environment.get_exe_wrapper(), EmptyExternalProgram):
++            args.append('--run=' + ' '.join(state.environment.get_exe_wrapper().get_command()))
 +
          args += self._unpack_args('--htmlargs=', 'html_args', kwargs)
          args += self._unpack_args('--scanargs=', 'scan_args', kwargs)