Currently, we can't build meson into SDKs because we don't autogenerate the required meson.cross file.
Enable this by using the post-relocate hooks and generating a meson.cross file based on the SDK environment passed into the post-relocate hook. Signed-off-by: Martin Kelly <mke...@xevo.com> --- meta/recipes-devtools/meson/meson.inc | 23 +++++++ meta/recipes-devtools/meson/meson/meson-setup.py | 62 ++++++++++++++++++ meta/recipes-devtools/meson/meson/meson-wrapper | 14 ++++ meta/recipes-devtools/meson/meson_0.46.1.bb | 23 +------ .../meson/nativesdk-meson_0.46.1.bb | 74 ++++++++++++++++++++++ 5 files changed, 174 insertions(+), 22 deletions(-) create mode 100644 meta/recipes-devtools/meson/meson.inc create mode 100755 meta/recipes-devtools/meson/meson/meson-setup.py create mode 100755 meta/recipes-devtools/meson/meson/meson-wrapper create mode 100644 meta/recipes-devtools/meson/nativesdk-meson_0.46.1.bb diff --git a/meta/recipes-devtools/meson/meson.inc b/meta/recipes-devtools/meson/meson.inc new file mode 100644 index 0000000000..cf5af430e6 --- /dev/null +++ b/meta/recipes-devtools/meson/meson.inc @@ -0,0 +1,23 @@ +HOMEPAGE = "http://mesonbuild.com" +SUMMARY = "A high performance build system" + +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://COPYING;md5=3b83ef96387f14655fc854ddc3c6bd57" + +SRC_URI = "https://github.com/mesonbuild/meson/releases/download/${PV}/meson-${PV}.tar.gz \ + file://0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch \ + file://0002-gobject-introspection-determine-g-ir-scanner-and-g-i.patch \ + file://0001-Linker-rules-move-cross_args-in-front-of-output_args.patch \ + file://0003-native_bindir.patch \ + file://0004-make-ExternalProgram-get_path-a-bit-smarter.patch \ + file://0005-commandrunner-make-run-handle-python-options.patch \ + file://0006-mesonlib-handle-meson-exe-wrappers.patch \ + " + +SRC_URI[md5sum] = "1698f6526574839de5dcdc45e3f7d582" +SRC_URI[sha256sum] = "19497a03e7e5b303d8d11f98789a79aba59b5ad4a81bd00f4d099be0212cee78" +UPSTREAM_CHECK_URI = "https://github.com/mesonbuild/meson/releases" + +inherit setuptools3 + +RDEPENDS_${PN} = "ninja python3-core python3-modules" diff --git a/meta/recipes-devtools/meson/meson/meson-setup.py b/meta/recipes-devtools/meson/meson/meson-setup.py new file mode 100755 index 0000000000..a9749eae9d --- /dev/null +++ b/meta/recipes-devtools/meson/meson/meson-setup.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +import os +import sys + +def bail(msg): + print(msg, file=sys.stderr) + sys.exit(1) + +_MARKER = '@@' +def transform_line(line): + # Substitute any special markers of this form: + # @@ENV@@ + # with the value of ENV, split into meson array syntax. + start = line.find(_MARKER) + if start == -1: + return line + + end = line.rfind(_MARKER) + if end == start: + return line + + # Lookup value of the env var. + var = line[start+len(_MARKER):end] + try: + val = os.environ[var] + except KeyError: + bail('cannot generate meson.cross; env var %s not set' % var) + + # Transform into meson array. + val = ["'%s'" % x for x in val.split()] + val = ', '.join(val) + val = '[%s]' % val + + before = line[:start] + after = line[end+len(_MARKER):] + + return '%s%s%s' % (before, val, after) + +# Make sure this is really an SDK extraction environment. +try: + sysroot = os.environ['OECORE_NATIVE_SYSROOT'] +except KeyError: + bail('OECORE_NATIVE_SYSROOT env var must be set') + +cross_file = os.path.join(sysroot, 'usr/share/meson/meson.cross') +tmp_cross_file = '%s.tmp' % cross_file + +# Read through and transform the current meson.cross. +lines = [] +with open(cross_file, 'r') as f: + for line in f: + lines.append(transform_line(line)) + +# Write the transformed result to a tmp file and atomically rename it. In case +# we crash during the file write, we don't want an invalid meson.cross file. +with open(tmp_cross_file, 'w') as f: + for line in lines: + f.write(line) + f.flush() + os.fdatasync(f.fileno()) +os.rename(tmp_cross_file, cross_file) diff --git a/meta/recipes-devtools/meson/meson/meson-wrapper b/meta/recipes-devtools/meson/meson/meson-wrapper new file mode 100755 index 0000000000..b2e00da513 --- /dev/null +++ b/meta/recipes-devtools/meson/meson/meson-wrapper @@ -0,0 +1,14 @@ +#!/bin/sh + +if [ -z "$OECORE_NATIVE_SYSROOT" ]; then + echo "OECORE_NATIVE_SYSROOT not set; are you in a Yocto SDK environment?" >&2 +fi + +# If these are set to a cross-compile path, meson will get confused and try to +# use them as native tools. Unset them to prevent this, as all the cross-compile +# config is already in meson.cross. +unset CC CXX CPP LD AR NM STRIP + +exec "$OECORE_NATIVE_SYSROOT/usr/bin/meson.real" \ + --cross-file "$OECORE_NATIVE_SYSROOT/usr/share/meson/meson.cross" \ + "$@" diff --git a/meta/recipes-devtools/meson/meson_0.46.1.bb b/meta/recipes-devtools/meson/meson_0.46.1.bb index a1c9035e85..897fa148d9 100644 --- a/meta/recipes-devtools/meson/meson_0.46.1.bb +++ b/meta/recipes-devtools/meson/meson_0.46.1.bb @@ -1,24 +1,3 @@ -HOMEPAGE = "http://mesonbuild.com" -SUMMARY = "A high performance build system" - -LICENSE = "Apache-2.0" -LIC_FILES_CHKSUM = "file://COPYING;md5=3b83ef96387f14655fc854ddc3c6bd57" - -SRC_URI = "https://github.com/mesonbuild/meson/releases/download/${PV}/${BP}.tar.gz \ - file://0001-gtkdoc-fix-issues-that-arise-when-cross-compiling.patch \ - file://0002-gobject-introspection-determine-g-ir-scanner-and-g-i.patch \ - file://0001-Linker-rules-move-cross_args-in-front-of-output_args.patch \ - file://0003-native_bindir.patch \ - file://0004-make-ExternalProgram-get_path-a-bit-smarter.patch \ - file://0005-commandrunner-make-run-handle-python-options.patch \ - file://0006-mesonlib-handle-meson-exe-wrappers.patch \ - " -SRC_URI[md5sum] = "1698f6526574839de5dcdc45e3f7d582" -SRC_URI[sha256sum] = "19497a03e7e5b303d8d11f98789a79aba59b5ad4a81bd00f4d099be0212cee78" -UPSTREAM_CHECK_URI = "https://github.com/mesonbuild/meson/releases" - -inherit setuptools3 - -RDEPENDS_${PN} = "ninja python3-core python3-modules" +include meson.inc BBCLASSEXTEND = "native" diff --git a/meta/recipes-devtools/meson/nativesdk-meson_0.46.1.bb b/meta/recipes-devtools/meson/nativesdk-meson_0.46.1.bb new file mode 100644 index 0000000000..53503aa998 --- /dev/null +++ b/meta/recipes-devtools/meson/nativesdk-meson_0.46.1.bb @@ -0,0 +1,74 @@ +include meson.inc + +inherit nativesdk + +SRC_URI += "file://meson-setup.py \ + file://meson-wrapper" + +def meson_array(var, d): + return "', '".join(d.getVar(var).split()).join(("'", "'")) + +# both are required but not used by meson +MESON_SDK_ENDIAN = "bogus-endian" +MESON_TARGET_ENDIAN = "bogus-endian" + +MESON_TOOLCHAIN_ARGS = "${BUILDSDK_CC_ARCH}${TOOLCHAIN_OPTIONS}" +MESON_C_ARGS = "${MESON_TOOLCHAIN_ARGS} ${BUILDSDK_CFLAGS}" +MESON_CPP_ARGS = "${MESON_TOOLCHAIN_ARGS} ${BUILDSDK_CXXFLAGS}" +MESON_LINK_ARGS = "${MESON_TOOLCHAIN_ARGS} ${BUILDSDK_LDFLAGS}" + +# This logic is similar but not identical to that in meson.bbclass, since it's +# generating for an SDK rather than a cross-compile. Important differences are: +# - We can't set vars like CC, CXX, etc. yet because they will be filled in with +# real paths by meson-setup.sh when the SDK is extracted. +# - Some overrides aren't needed, since the SDK injects paths that take care of +# them. +addtask write_config before do_install +do_write_config[vardeps] += "MESON_C_ARGS MESON_CPP_ARGS MESON_LINK_ARGS CC CXX LD AR NM STRIP READELF" +do_write_config() { + # This needs to be Py to split the args into single-element lists + cat >${WORKDIR}/meson.cross <<EOF +[binaries] +c = @@CC@@ +cpp = @@CXX@@ +ar = @@AR@@ +nm = @@NM@@ +ld = @@LD@@ +strip = @@STRIP@@ +pkgconfig = 'pkg-config' + +[properties] +needs_exe_wrapper = true +c_args = @@CFLAGS@@ +c_link_args = @@LDFLAGS@@ +cpp_args = @@CPPFLAGS@@ +cpp_link_args = @@LDFLAGS@@ + +[host_machine] +system = '${SDK_OS}' +cpu_family = '${SDK_ARCH}' +cpu = '${SDK_ARCH}' +endian = '${MESON_SDK_ENDIAN}' +EOF +} + +do_install_append() { + install -d ${D}${datadir}/meson + install -m 0644 ${WORKDIR}/meson.cross ${D}${datadir}/meson/ + + install -d ${D}${SDKPATHNATIVE}/post-relocate-setup.d + install -m 0755 ${WORKDIR}/meson-setup.py ${D}${SDKPATHNATIVE}/post-relocate-setup.d/ + + # We need to wrap the real meson with a thin env setup wrapper. + mv ${D}${bindir}/meson ${D}${bindir}/meson.real + install -m 0755 ${WORKDIR}/meson-wrapper ${D}${bindir}/meson +} + +RDEPENDS_${PN} += "\ + nativesdk-ninja \ + nativesdk-python3-core \ + nativesdk-python3-misc \ + nativesdk-python3-modules \ + " + +FILES_${PN} += "${datadir}/meson ${SDKPATHNATIVE}" -- 2.11.0 -- _______________________________________________ Openembedded-core mailing list Openembedded-core@lists.openembedded.org http://lists.openembedded.org/mailman/listinfo/openembedded-core