blob: 0bfe9458118b4319a4a65c2363db549bd4e97c2a [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001inherit python3native meson-routines qemu
Brad Bishop316dfdd2018-06-25 12:45:53 -04002
Patrick Williams213cb262021-08-07 19:21:33 -05003DEPENDS:append = " meson-native ninja-native"
Brad Bishop316dfdd2018-06-25 12:45:53 -04004
Andrew Geissler595f6302022-01-24 19:11:47 +00005EXEWRAPPER_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
Brad Bishop316dfdd2018-06-25 12:45:53 -040010# 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
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050020MESON_BUILDTYPE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'debug', 'plain', d)}"
21MESON_BUILDTYPE[vardeps] += "DEBUG_BUILD"
Brad Bishop316dfdd2018-06-25 12:45:53 -040022MESONOPTS = " --prefix ${prefix} \
Andrew Geissler82c905d2020-04-13 13:39:40 -050023 --buildtype ${MESON_BUILDTYPE} \
Brad Bishop316dfdd2018-06-25 12:45:53 -040024 --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 Geissler82c905d2020-04-13 13:39:40 -050034 --sharedstatedir ${sharedstatedir} \
Andrew Geissler95ac1b82021-03-31 14:34:31 -050035 --wrap-mode nodownload \
36 --native-file ${WORKDIR}/meson.native"
Brad Bishop316dfdd2018-06-25 12:45:53 -040037
Patrick Williams213cb262021-08-07 19:21:33 -050038EXTRA_OEMESON:append = " ${PACKAGECONFIG_CONFARGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040039
40MESON_CROSS_FILE = ""
Patrick Williams213cb262021-08-07 19:21:33 -050041MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
42MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
Brad Bishop316dfdd2018-06-25 12:45:53 -040043
Andrew Geissler595f6302022-01-24 19:11:47 +000044# 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
Brad Bishop316dfdd2018-06-25 12:45:53 -040054addtask write_config before do_configure
Andrew Geissler595f6302022-01-24 19:11:47 +000055do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS"
Brad Bishop316dfdd2018-06-25 12:45:53 -040056do_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 Bishop1a4b7ee2018-12-16 17:11:34 -080060c = ${@meson_array('CC', d)}
61cpp = ${@meson_array('CXX', d)}
62ar = ${@meson_array('AR', d)}
63nm = ${@meson_array('NM', d)}
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080064strip = ${@meson_array('STRIP', d)}
65readelf = ${@meson_array('READELF', d)}
Andrew Geissler595f6302022-01-24 19:11:47 +000066objcopy = ${@meson_array('OBJCOPY', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -040067pkgconfig = 'pkg-config'
Brad Bishop08902b02019-08-20 09:16:51 -040068llvm-config = 'llvm-config${LLVMVERSION}'
Andrew Geissler635e0e42020-08-21 15:58:33 -050069cups-config = 'cups-config'
Andrew Geissler90fd73c2021-03-05 15:25:55 -060070g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
71g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
Andrew Geissler595f6302022-01-24 19:11:47 +000072${@rust_tool(d, "HOST_SYS")}
73${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""}
Brad Bishop316dfdd2018-06-25 12:45:53 -040074
Andrew Geissler95ac1b82021-03-31 14:34:31 -050075[built-in options]
Brad Bishop96ff1982019-08-19 13:50:42 -040076c_args = ${@meson_array('CFLAGS', d)}
77c_link_args = ${@meson_array('LDFLAGS', d)}
78cpp_args = ${@meson_array('CXXFLAGS', d)}
79cpp_link_args = ${@meson_array('LDFLAGS', d)}
Andrew Geissler95ac1b82021-03-31 14:34:31 -050080
81[properties]
82needs_exe_wrapper = true
Brad Bishop316dfdd2018-06-25 12:45:53 -040083
84[host_machine]
Andrew Geissler82c905d2020-04-13 13:39:40 -050085system = '${@meson_operating_system('HOST_OS', d)}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080086cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040087cpu = '${HOST_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080088endian = '${@meson_endian('HOST', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040089
90[target_machine]
Andrew Geissler82c905d2020-04-13 13:39:40 -050091system = '${@meson_operating_system('TARGET_OS', d)}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080092cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040093cpu = '${TARGET_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080094endian = '${@meson_endian('TARGET', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040095EOF
Andrew Geissler95ac1b82021-03-31 14:34:31 -050096
97 cat >${WORKDIR}/meson.native <<EOF
98[binaries]
99c = ${@meson_array('BUILD_CC', d)}
100cpp = ${@meson_array('BUILD_CXX', d)}
101ar = ${@meson_array('BUILD_AR', d)}
102nm = ${@meson_array('BUILD_NM', d)}
103strip = ${@meson_array('BUILD_STRIP', d)}
104readelf = ${@meson_array('BUILD_READELF', d)}
Andrew Geissler595f6302022-01-24 19:11:47 +0000105objcopy = ${@meson_array('BUILD_OBJCOPY', d)}
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500106pkgconfig = 'pkg-config-native'
Andrew Geissler595f6302022-01-24 19:11:47 +0000107${@rust_tool(d, "BUILD_SYS")}
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500108
109[built-in options]
110c_args = ${@meson_array('BUILD_CFLAGS', d)}
111c_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
112cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)}
113cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
114EOF
Brad Bishop316dfdd2018-06-25 12:45:53 -0400115}
116
Andrew Geissler595f6302022-01-24 19:11:47 +0000117do_write_config:append:class-target() {
118 # Write out a qemu wrapper that will be used as exe_wrapper so that meson
119 # can run target helper binaries through that.
120 qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
121 cat > ${WORKDIR}/meson-qemuwrapper << EOF
122#!/bin/sh
123# Use a modules directory which doesn't exist so we don't load random things
124# which may then get deleted (or their dependencies) and potentially segfault
125export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
126
127# meson sets this wrongly (only to libs in build-dir), qemu_wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
128unset LD_LIBRARY_PATH
129
130$qemu_binary "\$@"
131EOF
132 chmod +x ${WORKDIR}/meson-qemuwrapper
133}
134
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500135# Tell externalsrc that changes to this file require a reconfigure
Brad Bishop316dfdd2018-06-25 12:45:53 -0400136CONFIGURE_FILES = "meson.build"
137
138meson_do_configure() {
Andrew Geissler82c905d2020-04-13 13:39:40 -0500139 # Meson requires this to be 'bfd, 'lld' or 'gold' from 0.53 onwards
140 # https://github.com/mesonbuild/meson/commit/ef9aeb188ea2bc7353e59916c18901cde90fa2b3
141 unset LD
142
Andrew Geisslereff27472021-10-29 15:35:00 -0500143 # sstate.bbclass no longer removes empty directories to avoid a race (see
144 # commit 4f94d929 "sstate/staging: Handle directory creation race issue").
145 # Unfortunately Python apparently treats an empty egg-info directory as if
146 # the version it previously contained still exists and fails if a newer
147 # version is required, which Meson does. To avoid this, make sure there are
148 # no empty egg-info directories from previous versions left behind. Ignore
149 # all errors from rmdir since the egg-info may be a file rather than a
150 # directory.
151 rmdir ${STAGING_LIBDIR_NATIVE}/${PYTHON_DIR}/site-packages/*.egg-info 2>/dev/null || :
152
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800153 # Work around "Meson fails if /tmp is mounted with noexec #2972"
154 mkdir -p "${B}/meson-private/tmp"
155 export TMPDIR="${B}/meson-private/tmp"
156 bbnote Executing meson ${EXTRA_OEMESON}...
Brad Bishop316dfdd2018-06-25 12:45:53 -0400157 if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400158 bbfatal_log meson failed
159 fi
160}
161
Andrew Geissler82c905d2020-04-13 13:39:40 -0500162python meson_do_qa_configure() {
163 import re
164 warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE)
Andrew Geisslerc182c622020-05-15 14:13:32 -0500165 with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile:
166 log = logfile.read()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500167 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}
170do_configure[postfuncs] += "meson_do_qa_configure"
171
Brad Bishop316dfdd2018-06-25 12:45:53 -0400172do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
173meson_do_compile() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800174 ninja -v ${PARALLEL_MAKE}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400175}
176
177meson_do_install() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800178 DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install
Brad Bishop316dfdd2018-06-25 12:45:53 -0400179}
180
181EXPORT_FUNCTIONS do_configure do_compile do_install