Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | inherit python3native meson-routines qemu |
| 8 | |
| 9 | DEPENDS:append = " meson-native ninja-native" |
| 10 | |
| 11 | EXEWRAPPER_ENABLED:class-native = "False" |
| 12 | EXEWRAPPER_ENABLED:class-nativesdk = "False" |
| 13 | EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}" |
| 14 | DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}" |
| 15 | |
| 16 | # As Meson enforces out-of-tree builds we can just use cleandirs |
| 17 | B = "${WORKDIR}/build" |
| 18 | do_configure[cleandirs] = "${B}" |
| 19 | |
| 20 | # Where the meson.build build configuration is |
| 21 | MESON_SOURCEPATH = "${S}" |
| 22 | |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 23 | # The target to build in do_compile. If unset the default targets are built. |
| 24 | MESON_TARGET ?= "" |
| 25 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 26 | def noprefix(var, d): |
| 27 | return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1) |
| 28 | |
| 29 | MESON_BUILDTYPE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'debug', 'plain', d)}" |
| 30 | MESON_BUILDTYPE[vardeps] += "DEBUG_BUILD" |
| 31 | MESONOPTS = " --prefix ${prefix} \ |
| 32 | --buildtype ${MESON_BUILDTYPE} \ |
| 33 | --bindir ${@noprefix('bindir', d)} \ |
| 34 | --sbindir ${@noprefix('sbindir', d)} \ |
| 35 | --datadir ${@noprefix('datadir', d)} \ |
| 36 | --libdir ${@noprefix('libdir', d)} \ |
| 37 | --libexecdir ${@noprefix('libexecdir', d)} \ |
| 38 | --includedir ${@noprefix('includedir', d)} \ |
| 39 | --mandir ${@noprefix('mandir', d)} \ |
| 40 | --infodir ${@noprefix('infodir', d)} \ |
| 41 | --sysconfdir ${sysconfdir} \ |
| 42 | --localstatedir ${localstatedir} \ |
| 43 | --sharedstatedir ${sharedstatedir} \ |
| 44 | --wrap-mode nodownload \ |
| 45 | --native-file ${WORKDIR}/meson.native" |
| 46 | |
| 47 | EXTRA_OEMESON:append = " ${PACKAGECONFIG_CONFARGS}" |
| 48 | |
| 49 | MESON_CROSS_FILE = "" |
| 50 | MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross" |
| 51 | MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross" |
| 52 | |
| 53 | # Needed to set up qemu wrapper below |
| 54 | export STAGING_DIR_HOST |
| 55 | |
| 56 | def rust_tool(d, target_var): |
| 57 | rustc = d.getVar('RUSTC') |
| 58 | if not rustc: |
| 59 | return "" |
| 60 | cmd = [rustc, "--target", d.getVar(target_var)] + d.getVar("RUSTFLAGS").split() |
| 61 | return "rust = %s" % repr(cmd) |
| 62 | |
| 63 | addtask write_config before do_configure |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 64 | do_write_config[vardeps] += "CC CXX AR NM STRIP READELF OBJCOPY CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS EXEWRAPPER_ENABLED" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 65 | do_write_config() { |
| 66 | # This needs to be Py to split the args into single-element lists |
| 67 | cat >${WORKDIR}/meson.cross <<EOF |
| 68 | [binaries] |
Patrick Williams | 3965356 | 2024-03-01 08:54:02 -0600 | [diff] [blame] | 69 | c = ${@meson_array('CC', d)} |
| 70 | cpp = ${@meson_array('CXX', d)} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 71 | cython = 'cython3' |
| 72 | ar = ${@meson_array('AR', d)} |
| 73 | nm = ${@meson_array('NM', d)} |
| 74 | strip = ${@meson_array('STRIP', d)} |
| 75 | readelf = ${@meson_array('READELF', d)} |
| 76 | objcopy = ${@meson_array('OBJCOPY', d)} |
Patrick Williams | 705982a | 2024-01-12 09:51:57 -0600 | [diff] [blame] | 77 | pkg-config = 'pkg-config' |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 78 | llvm-config = 'llvm-config' |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 79 | cups-config = 'cups-config' |
| 80 | g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper' |
| 81 | g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper' |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 82 | ${@rust_tool(d, "RUST_HOST_SYS")} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 83 | ${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""} |
| 84 | |
| 85 | [built-in options] |
| 86 | c_args = ${@meson_array('CFLAGS', d)} |
| 87 | c_link_args = ${@meson_array('LDFLAGS', d)} |
| 88 | cpp_args = ${@meson_array('CXXFLAGS', d)} |
| 89 | cpp_link_args = ${@meson_array('LDFLAGS', d)} |
| 90 | |
| 91 | [properties] |
| 92 | needs_exe_wrapper = true |
Patrick Williams | 73bd93f | 2024-02-20 08:07:48 -0600 | [diff] [blame] | 93 | sys_root = '${STAGING_DIR_HOST}' |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 94 | |
| 95 | [host_machine] |
| 96 | system = '${@meson_operating_system('HOST_OS', d)}' |
| 97 | cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}' |
| 98 | cpu = '${HOST_ARCH}' |
| 99 | endian = '${@meson_endian('HOST', d)}' |
| 100 | |
| 101 | [target_machine] |
| 102 | system = '${@meson_operating_system('TARGET_OS', d)}' |
| 103 | cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}' |
| 104 | cpu = '${TARGET_ARCH}' |
| 105 | endian = '${@meson_endian('TARGET', d)}' |
| 106 | EOF |
| 107 | |
| 108 | cat >${WORKDIR}/meson.native <<EOF |
| 109 | [binaries] |
| 110 | c = ${@meson_array('BUILD_CC', d)} |
| 111 | cpp = ${@meson_array('BUILD_CXX', d)} |
| 112 | cython = 'cython3' |
| 113 | ar = ${@meson_array('BUILD_AR', d)} |
| 114 | nm = ${@meson_array('BUILD_NM', d)} |
| 115 | strip = ${@meson_array('BUILD_STRIP', d)} |
| 116 | readelf = ${@meson_array('BUILD_READELF', d)} |
| 117 | objcopy = ${@meson_array('BUILD_OBJCOPY', d)} |
Andrew Geissler | 8f84068 | 2023-07-21 09:09:43 -0500 | [diff] [blame] | 118 | llvm-config = '${STAGING_BINDIR_NATIVE}/llvm-config' |
Patrick Williams | 705982a | 2024-01-12 09:51:57 -0600 | [diff] [blame] | 119 | pkg-config = 'pkg-config-native' |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 120 | ${@rust_tool(d, "RUST_BUILD_SYS")} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 121 | |
| 122 | [built-in options] |
| 123 | c_args = ${@meson_array('BUILD_CFLAGS', d)} |
| 124 | c_link_args = ${@meson_array('BUILD_LDFLAGS', d)} |
| 125 | cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)} |
| 126 | cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)} |
| 127 | EOF |
| 128 | } |
| 129 | |
| 130 | do_write_config:append:class-target() { |
| 131 | # Write out a qemu wrapper that will be used as exe_wrapper so that meson |
| 132 | # can run target helper binaries through that. |
| 133 | qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}" |
| 134 | cat > ${WORKDIR}/meson-qemuwrapper << EOF |
| 135 | #!/bin/sh |
| 136 | # Use a modules directory which doesn't exist so we don't load random things |
| 137 | # which may then get deleted (or their dependencies) and potentially segfault |
| 138 | export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy |
| 139 | |
| 140 | # meson sets this wrongly (only to libs in build-dir), qemu_wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly |
| 141 | unset LD_LIBRARY_PATH |
| 142 | |
| 143 | $qemu_binary "\$@" |
| 144 | EOF |
| 145 | chmod +x ${WORKDIR}/meson-qemuwrapper |
| 146 | } |
| 147 | |
| 148 | # Tell externalsrc that changes to this file require a reconfigure |
| 149 | CONFIGURE_FILES = "meson.build" |
| 150 | |
| 151 | meson_do_configure() { |
| 152 | # Meson requires this to be 'bfd, 'lld' or 'gold' from 0.53 onwards |
| 153 | # https://github.com/mesonbuild/meson/commit/ef9aeb188ea2bc7353e59916c18901cde90fa2b3 |
| 154 | unset LD |
| 155 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 156 | bbnote Executing meson ${EXTRA_OEMESON}... |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 157 | if ! meson setup ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 158 | bbfatal_log meson failed |
| 159 | fi |
| 160 | } |
| 161 | |
| 162 | python meson_do_qa_configure() { |
| 163 | import re |
| 164 | warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE) |
| 165 | with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile: |
| 166 | log = logfile.read() |
| 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 | |
| 172 | do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+" |
| 173 | meson_do_compile() { |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 174 | meson compile -v ${PARALLEL_MAKE} ${MESON_TARGET} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | meson_do_install() { |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 178 | meson install --destdir ${D} --no-rebuild |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | EXPORT_FUNCTIONS do_configure do_compile do_install |