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