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)} |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 62 | cython = 'cython3' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 63 | ar = ${@meson_array('AR', d)} |
| 64 | nm = ${@meson_array('NM', d)} |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 65 | strip = ${@meson_array('STRIP', d)} |
| 66 | readelf = ${@meson_array('READELF', d)} |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 67 | objcopy = ${@meson_array('OBJCOPY', d)} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 68 | pkgconfig = 'pkg-config' |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 69 | llvm-config = 'llvm-config${LLVMVERSION}' |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 70 | cups-config = 'cups-config' |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 71 | g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper' |
| 72 | g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper' |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 73 | ${@rust_tool(d, "HOST_SYS")} |
| 74 | ${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 75 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 76 | [built-in options] |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 77 | c_args = ${@meson_array('CFLAGS', d)} |
| 78 | c_link_args = ${@meson_array('LDFLAGS', d)} |
| 79 | cpp_args = ${@meson_array('CXXFLAGS', d)} |
| 80 | cpp_link_args = ${@meson_array('LDFLAGS', d)} |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 81 | |
| 82 | [properties] |
| 83 | needs_exe_wrapper = true |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 84 | |
| 85 | [host_machine] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 86 | system = '${@meson_operating_system('HOST_OS', d)}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 87 | cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 88 | cpu = '${HOST_ARCH}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 89 | endian = '${@meson_endian('HOST', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 90 | |
| 91 | [target_machine] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 92 | system = '${@meson_operating_system('TARGET_OS', d)}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 93 | cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 94 | cpu = '${TARGET_ARCH}' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 95 | endian = '${@meson_endian('TARGET', d)}' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 96 | EOF |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 97 | |
| 98 | cat >${WORKDIR}/meson.native <<EOF |
| 99 | [binaries] |
| 100 | c = ${@meson_array('BUILD_CC', d)} |
| 101 | cpp = ${@meson_array('BUILD_CXX', d)} |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 102 | cython = 'cython3' |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 103 | ar = ${@meson_array('BUILD_AR', d)} |
| 104 | nm = ${@meson_array('BUILD_NM', d)} |
| 105 | strip = ${@meson_array('BUILD_STRIP', d)} |
| 106 | readelf = ${@meson_array('BUILD_READELF', d)} |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 107 | objcopy = ${@meson_array('BUILD_OBJCOPY', d)} |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 108 | pkgconfig = 'pkg-config-native' |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 109 | ${@rust_tool(d, "BUILD_SYS")} |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 110 | |
| 111 | [built-in options] |
| 112 | c_args = ${@meson_array('BUILD_CFLAGS', d)} |
| 113 | c_link_args = ${@meson_array('BUILD_LDFLAGS', d)} |
| 114 | cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)} |
| 115 | cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)} |
| 116 | EOF |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 119 | do_write_config:append:class-target() { |
| 120 | # Write out a qemu wrapper that will be used as exe_wrapper so that meson |
| 121 | # can run target helper binaries through that. |
| 122 | qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}" |
| 123 | cat > ${WORKDIR}/meson-qemuwrapper << EOF |
| 124 | #!/bin/sh |
| 125 | # Use a modules directory which doesn't exist so we don't load random things |
| 126 | # which may then get deleted (or their dependencies) and potentially segfault |
| 127 | export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy |
| 128 | |
| 129 | # meson sets this wrongly (only to libs in build-dir), qemu_wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly |
| 130 | unset LD_LIBRARY_PATH |
| 131 | |
| 132 | $qemu_binary "\$@" |
| 133 | EOF |
| 134 | chmod +x ${WORKDIR}/meson-qemuwrapper |
| 135 | } |
| 136 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 137 | # Tell externalsrc that changes to this file require a reconfigure |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 138 | CONFIGURE_FILES = "meson.build" |
| 139 | |
| 140 | meson_do_configure() { |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 141 | # Meson requires this to be 'bfd, 'lld' or 'gold' from 0.53 onwards |
| 142 | # https://github.com/mesonbuild/meson/commit/ef9aeb188ea2bc7353e59916c18901cde90fa2b3 |
| 143 | unset LD |
| 144 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 145 | # Work around "Meson fails if /tmp is mounted with noexec #2972" |
| 146 | mkdir -p "${B}/meson-private/tmp" |
| 147 | export TMPDIR="${B}/meson-private/tmp" |
| 148 | bbnote Executing meson ${EXTRA_OEMESON}... |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 149 | if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 150 | bbfatal_log meson failed |
| 151 | fi |
| 152 | } |
| 153 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 154 | python meson_do_qa_configure() { |
| 155 | import re |
| 156 | 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] | 157 | with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile: |
| 158 | log = logfile.read() |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 159 | for (prop, value) in warn_re.findall(log): |
| 160 | bb.warn("Meson cross property %s used without explicit assignment, defaulting to %s" % (prop, value)) |
| 161 | } |
| 162 | do_configure[postfuncs] += "meson_do_qa_configure" |
| 163 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 164 | do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+" |
| 165 | meson_do_compile() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 166 | ninja -v ${PARALLEL_MAKE} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | meson_do_install() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 170 | DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | EXPORT_FUNCTIONS do_configure do_compile do_install |