1inherit python3native meson-routines qemu 2 3DEPENDS:append = " meson-native ninja-native" 4 5EXEWRAPPER_ENABLED:class-native = "False" 6EXEWRAPPER_ENABLED:class-nativesdk = "False" 7EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}" 8DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}" 9 10# As Meson enforces out-of-tree builds we can just use cleandirs 11B = "${WORKDIR}/build" 12do_configure[cleandirs] = "${B}" 13 14# Where the meson.build build configuration is 15MESON_SOURCEPATH = "${S}" 16 17def noprefix(var, d): 18 return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1) 19 20MESON_BUILDTYPE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'debug', 'plain', d)}" 21MESON_BUILDTYPE[vardeps] += "DEBUG_BUILD" 22MESONOPTS = " --prefix ${prefix} \ 23 --buildtype ${MESON_BUILDTYPE} \ 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} \ 34 --sharedstatedir ${sharedstatedir} \ 35 --wrap-mode nodownload \ 36 --native-file ${WORKDIR}/meson.native" 37 38EXTRA_OEMESON:append = " ${PACKAGECONFIG_CONFARGS}" 39 40MESON_CROSS_FILE = "" 41MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross" 42MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross" 43 44# Needed to set up qemu wrapper below 45export STAGING_DIR_HOST 46 47def 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 54addtask write_config before do_configure 55do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS" 56do_write_config() { 57 # This needs to be Py to split the args into single-element lists 58 cat >${WORKDIR}/meson.cross <<EOF 59[binaries] 60c = ${@meson_array('CC', d)} 61cpp = ${@meson_array('CXX', d)} 62cython = 'cython3' 63ar = ${@meson_array('AR', d)} 64nm = ${@meson_array('NM', d)} 65strip = ${@meson_array('STRIP', d)} 66readelf = ${@meson_array('READELF', d)} 67objcopy = ${@meson_array('OBJCOPY', d)} 68pkgconfig = 'pkg-config' 69llvm-config = 'llvm-config${LLVMVERSION}' 70cups-config = 'cups-config' 71g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper' 72g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper' 73${@rust_tool(d, "HOST_SYS")} 74${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""} 75 76[built-in options] 77c_args = ${@meson_array('CFLAGS', d)} 78c_link_args = ${@meson_array('LDFLAGS', d)} 79cpp_args = ${@meson_array('CXXFLAGS', d)} 80cpp_link_args = ${@meson_array('LDFLAGS', d)} 81 82[properties] 83needs_exe_wrapper = true 84 85[host_machine] 86system = '${@meson_operating_system('HOST_OS', d)}' 87cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}' 88cpu = '${HOST_ARCH}' 89endian = '${@meson_endian('HOST', d)}' 90 91[target_machine] 92system = '${@meson_operating_system('TARGET_OS', d)}' 93cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}' 94cpu = '${TARGET_ARCH}' 95endian = '${@meson_endian('TARGET', d)}' 96EOF 97 98 cat >${WORKDIR}/meson.native <<EOF 99[binaries] 100c = ${@meson_array('BUILD_CC', d)} 101cpp = ${@meson_array('BUILD_CXX', d)} 102cython = 'cython3' 103ar = ${@meson_array('BUILD_AR', d)} 104nm = ${@meson_array('BUILD_NM', d)} 105strip = ${@meson_array('BUILD_STRIP', d)} 106readelf = ${@meson_array('BUILD_READELF', d)} 107objcopy = ${@meson_array('BUILD_OBJCOPY', d)} 108pkgconfig = 'pkg-config-native' 109${@rust_tool(d, "BUILD_SYS")} 110 111[built-in options] 112c_args = ${@meson_array('BUILD_CFLAGS', d)} 113c_link_args = ${@meson_array('BUILD_LDFLAGS', d)} 114cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)} 115cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)} 116EOF 117} 118 119do_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 127export 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 130unset LD_LIBRARY_PATH 131 132$qemu_binary "\$@" 133EOF 134 chmod +x ${WORKDIR}/meson-qemuwrapper 135} 136 137# Tell externalsrc that changes to this file require a reconfigure 138CONFIGURE_FILES = "meson.build" 139 140meson_do_configure() { 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 145 # sstate.bbclass no longer removes empty directories to avoid a race (see 146 # commit 4f94d929 "sstate/staging: Handle directory creation race issue"). 147 # Unfortunately Python apparently treats an empty egg-info directory as if 148 # the version it previously contained still exists and fails if a newer 149 # version is required, which Meson does. To avoid this, make sure there are 150 # no empty egg-info directories from previous versions left behind. Ignore 151 # all errors from rmdir since the egg-info may be a file rather than a 152 # directory. 153 rmdir ${STAGING_LIBDIR_NATIVE}/${PYTHON_DIR}/site-packages/*.egg-info 2>/dev/null || : 154 155 # Work around "Meson fails if /tmp is mounted with noexec #2972" 156 mkdir -p "${B}/meson-private/tmp" 157 export TMPDIR="${B}/meson-private/tmp" 158 bbnote Executing meson ${EXTRA_OEMESON}... 159 if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then 160 bbfatal_log meson failed 161 fi 162} 163 164python meson_do_qa_configure() { 165 import re 166 warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE) 167 with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile: 168 log = logfile.read() 169 for (prop, value) in warn_re.findall(log): 170 bb.warn("Meson cross property %s used without explicit assignment, defaulting to %s" % (prop, value)) 171} 172do_configure[postfuncs] += "meson_do_qa_configure" 173 174do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+" 175meson_do_compile() { 176 ninja -v ${PARALLEL_MAKE} 177} 178 179meson_do_install() { 180 DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install 181} 182 183EXPORT_FUNCTIONS do_configure do_compile do_install 184