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