Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1 | inherit python3native meson-routines qemu |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 3 | DEPENDS:append = " meson-native ninja-native" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 4 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 5 | EXEWRAPPER_ENABLED:class-native = "False" |
| 6 | EXEWRAPPER_ENABLED:class-nativesdk = "False" |
| 7 | EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}" |
| 8 | DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}" |
| 9 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 10 | # As Meson enforces out-of-tree builds we can just use cleandirs |
| 11 | B = "${WORKDIR}/build" |
| 12 | do_configure[cleandirs] = "${B}" |
| 13 | |
| 14 | # Where the meson.build build configuration is |
| 15 | MESON_SOURCEPATH = "${S}" |
| 16 | |
| 17 | def noprefix(var, d): |
| 18 | return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1) |
| 19 | |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 20 | MESON_BUILDTYPE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'debug', 'plain', d)}" |
| 21 | MESON_BUILDTYPE[vardeps] += "DEBUG_BUILD" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 22 | MESONOPTS = " --prefix ${prefix} \ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 23 | --buildtype ${MESON_BUILDTYPE} \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 24 | --bindir ${@noprefix('bindir', d)} \ |
| 25 | --sbindir ${@noprefix('sbindir', d)} \ |
| 26 | --datadir ${@noprefix('datadir', d)} \ |
| 27 | --libdir ${@noprefix('libdir', d)} \ |
| 28 | --libexecdir ${@noprefix('libexecdir', d)} \ |
| 29 | --includedir ${@noprefix('includedir', d)} \ |
| 30 | --mandir ${@noprefix('mandir', d)} \ |
| 31 | --infodir ${@noprefix('infodir', d)} \ |
| 32 | --sysconfdir ${sysconfdir} \ |
| 33 | --localstatedir ${localstatedir} \ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 34 | --sharedstatedir ${sharedstatedir} \ |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 35 | --wrap-mode nodownload \ |
| 36 | --native-file ${WORKDIR}/meson.native" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 37 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 38 | EXTRA_OEMESON:append = " ${PACKAGECONFIG_CONFARGS}" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 39 | |
| 40 | MESON_CROSS_FILE = "" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 41 | MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross" |
| 42 | MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 43 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 44 | # Needed to set up qemu wrapper below |
| 45 | export STAGING_DIR_HOST |
| 46 | |
| 47 | def rust_tool(d, target_var): |
| 48 | rustc = d.getVar('RUSTC') |
| 49 | if not rustc: |
| 50 | return "" |
| 51 | cmd = [rustc, "--target", d.getVar(target_var)] + d.getVar("RUSTFLAGS").split() |
| 52 | return "rust = %s" % repr(cmd) |
| 53 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 54 | addtask write_config before do_configure |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 55 | do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 56 | do_write_config() { |
| 57 | # This needs to be Py to split the args into single-element lists |
| 58 | cat >${WORKDIR}/meson.cross <<EOF |
| 59 | [binaries] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 60 | c = ${@meson_array('CC', d)} |
| 61 | cpp = ${@meson_array('CXX', d)} |
| 62 | ar = ${@meson_array('AR', d)} |
| 63 | nm = ${@meson_array('NM', d)} |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 64 | strip = ${@meson_array('STRIP', d)} |
| 65 | readelf = ${@meson_array('READELF', d)} |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 66 | objcopy = ${@meson_array('OBJCOPY', d)} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 67 | pkgconfig = 'pkg-config' |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 68 | llvm-config = 'llvm-config${LLVMVERSION}' |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 69 | cups-config = 'cups-config' |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 70 | g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper' |
| 71 | g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper' |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 72 | ${@rust_tool(d, "HOST_SYS")} |
| 73 | ${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 74 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 75 | [built-in options] |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 76 | c_args = ${@meson_array('CFLAGS', d)} |
| 77 | c_link_args = ${@meson_array('LDFLAGS', d)} |
| 78 | cpp_args = ${@meson_array('CXXFLAGS', d)} |
| 79 | cpp_link_args = ${@meson_array('LDFLAGS', d)} |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 80 | |
| 81 | [properties] |
| 82 | needs_exe_wrapper = true |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 83 | |
| 84 | [host_machine] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 85 | system = '${@meson_operating_system('HOST_OS', d)}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 86 | cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 87 | cpu = '${HOST_ARCH}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 88 | endian = '${@meson_endian('HOST', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 89 | |
| 90 | [target_machine] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 91 | system = '${@meson_operating_system('TARGET_OS', d)}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 92 | cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 93 | cpu = '${TARGET_ARCH}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 94 | endian = '${@meson_endian('TARGET', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 95 | EOF |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 96 | |
| 97 | cat >${WORKDIR}/meson.native <<EOF |
| 98 | [binaries] |
| 99 | c = ${@meson_array('BUILD_CC', d)} |
| 100 | cpp = ${@meson_array('BUILD_CXX', d)} |
| 101 | ar = ${@meson_array('BUILD_AR', d)} |
| 102 | nm = ${@meson_array('BUILD_NM', d)} |
| 103 | strip = ${@meson_array('BUILD_STRIP', d)} |
| 104 | readelf = ${@meson_array('BUILD_READELF', d)} |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 105 | objcopy = ${@meson_array('BUILD_OBJCOPY', d)} |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 106 | pkgconfig = 'pkg-config-native' |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 107 | ${@rust_tool(d, "BUILD_SYS")} |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 108 | |
| 109 | [built-in options] |
| 110 | c_args = ${@meson_array('BUILD_CFLAGS', d)} |
| 111 | c_link_args = ${@meson_array('BUILD_LDFLAGS', d)} |
| 112 | cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)} |
| 113 | cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)} |
| 114 | EOF |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 117 | do_write_config:append:class-target() { |
| 118 | # Write out a qemu wrapper that will be used as exe_wrapper so that meson |
| 119 | # can run target helper binaries through that. |
| 120 | qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}" |
| 121 | cat > ${WORKDIR}/meson-qemuwrapper << EOF |
| 122 | #!/bin/sh |
| 123 | # Use a modules directory which doesn't exist so we don't load random things |
| 124 | # which may then get deleted (or their dependencies) and potentially segfault |
| 125 | export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy |
| 126 | |
| 127 | # meson sets this wrongly (only to libs in build-dir), qemu_wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly |
| 128 | unset LD_LIBRARY_PATH |
| 129 | |
| 130 | $qemu_binary "\$@" |
| 131 | EOF |
| 132 | chmod +x ${WORKDIR}/meson-qemuwrapper |
| 133 | } |
| 134 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 135 | # Tell externalsrc that changes to this file require a reconfigure |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 136 | CONFIGURE_FILES = "meson.build" |
| 137 | |
| 138 | meson_do_configure() { |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 139 | # Meson requires this to be 'bfd, 'lld' or 'gold' from 0.53 onwards |
| 140 | # https://github.com/mesonbuild/meson/commit/ef9aeb188ea2bc7353e59916c18901cde90fa2b3 |
| 141 | unset LD |
| 142 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 143 | # sstate.bbclass no longer removes empty directories to avoid a race (see |
| 144 | # commit 4f94d929 "sstate/staging: Handle directory creation race issue"). |
| 145 | # Unfortunately Python apparently treats an empty egg-info directory as if |
| 146 | # the version it previously contained still exists and fails if a newer |
| 147 | # version is required, which Meson does. To avoid this, make sure there are |
| 148 | # no empty egg-info directories from previous versions left behind. Ignore |
| 149 | # all errors from rmdir since the egg-info may be a file rather than a |
| 150 | # directory. |
| 151 | rmdir ${STAGING_LIBDIR_NATIVE}/${PYTHON_DIR}/site-packages/*.egg-info 2>/dev/null || : |
| 152 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 153 | # Work around "Meson fails if /tmp is mounted with noexec #2972" |
| 154 | mkdir -p "${B}/meson-private/tmp" |
| 155 | export TMPDIR="${B}/meson-private/tmp" |
| 156 | bbnote Executing meson ${EXTRA_OEMESON}... |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 157 | if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 158 | bbfatal_log meson failed |
| 159 | fi |
| 160 | } |
| 161 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 162 | python meson_do_qa_configure() { |
| 163 | import re |
| 164 | warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE) |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 165 | with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile: |
| 166 | log = logfile.read() |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 167 | for (prop, value) in warn_re.findall(log): |
| 168 | bb.warn("Meson cross property %s used without explicit assignment, defaulting to %s" % (prop, value)) |
| 169 | } |
| 170 | do_configure[postfuncs] += "meson_do_qa_configure" |
| 171 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 172 | do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+" |
| 173 | meson_do_compile() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 174 | ninja -v ${PARALLEL_MAKE} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | meson_do_install() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 178 | DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | EXPORT_FUNCTIONS do_configure do_compile do_install |