blob: 7f5e9b1943394d63ca18b3e304a2839a8286821b [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7inherit python3native meson-routines qemu
8
9DEPENDS:append = " meson-native ninja-native"
10
11EXEWRAPPER_ENABLED:class-native = "False"
12EXEWRAPPER_ENABLED:class-nativesdk = "False"
13EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}"
14DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}"
15
16# As Meson enforces out-of-tree builds we can just use cleandirs
17B = "${WORKDIR}/build"
18do_configure[cleandirs] = "${B}"
19
20# Where the meson.build build configuration is
21MESON_SOURCEPATH = "${S}"
22
23def noprefix(var, d):
24 return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
25
26MESON_BUILDTYPE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'debug', 'plain', d)}"
27MESON_BUILDTYPE[vardeps] += "DEBUG_BUILD"
28MESONOPTS = " --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
44EXTRA_OEMESON:append = " ${PACKAGECONFIG_CONFARGS}"
45
46MESON_CROSS_FILE = ""
47MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
48MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
49
50# Needed to set up qemu wrapper below
51export STAGING_DIR_HOST
52
53def 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
60addtask write_config before do_configure
61do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS"
62do_write_config() {
63 # This needs to be Py to split the args into single-element lists
64 cat >${WORKDIR}/meson.cross <<EOF
65[binaries]
66c = ${@meson_array('CC', d)}
67cpp = ${@meson_array('CXX', d)}
68cython = 'cython3'
69ar = ${@meson_array('AR', d)}
70nm = ${@meson_array('NM', d)}
71strip = ${@meson_array('STRIP', d)}
72readelf = ${@meson_array('READELF', d)}
73objcopy = ${@meson_array('OBJCOPY', d)}
74pkgconfig = 'pkg-config'
Andrew Geissler517393d2023-01-13 08:55:19 -060075llvm-config = 'llvm-config'
Patrick Williams92b42cb2022-09-03 06:53:57 -050076cups-config = 'cups-config'
77g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
78g-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]
83c_args = ${@meson_array('CFLAGS', d)}
84c_link_args = ${@meson_array('LDFLAGS', d)}
85cpp_args = ${@meson_array('CXXFLAGS', d)}
86cpp_link_args = ${@meson_array('LDFLAGS', d)}
87
88[properties]
89needs_exe_wrapper = true
90
91[host_machine]
92system = '${@meson_operating_system('HOST_OS', d)}'
93cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
94cpu = '${HOST_ARCH}'
95endian = '${@meson_endian('HOST', d)}'
96
97[target_machine]
98system = '${@meson_operating_system('TARGET_OS', d)}'
99cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
100cpu = '${TARGET_ARCH}'
101endian = '${@meson_endian('TARGET', d)}'
102EOF
103
104 cat >${WORKDIR}/meson.native <<EOF
105[binaries]
106c = ${@meson_array('BUILD_CC', d)}
107cpp = ${@meson_array('BUILD_CXX', d)}
108cython = 'cython3'
109ar = ${@meson_array('BUILD_AR', d)}
110nm = ${@meson_array('BUILD_NM', d)}
111strip = ${@meson_array('BUILD_STRIP', d)}
112readelf = ${@meson_array('BUILD_READELF', d)}
113objcopy = ${@meson_array('BUILD_OBJCOPY', d)}
Andrew Geissler8f840682023-07-21 09:09:43 -0500114llvm-config = '${STAGING_BINDIR_NATIVE}/llvm-config'
Patrick Williams92b42cb2022-09-03 06:53:57 -0500115pkgconfig = 'pkg-config-native'
116${@rust_tool(d, "BUILD_SYS")}
117
118[built-in options]
119c_args = ${@meson_array('BUILD_CFLAGS', d)}
120c_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
121cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)}
122cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
123EOF
124}
125
126do_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
134export 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
137unset LD_LIBRARY_PATH
138
139$qemu_binary "\$@"
140EOF
141 chmod +x ${WORKDIR}/meson-qemuwrapper
142}
143
144# Tell externalsrc that changes to this file require a reconfigure
145CONFIGURE_FILES = "meson.build"
146
147meson_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 Geissler517393d2023-01-13 08:55:19 -0600156 if ! meson setup ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then
Patrick Williams92b42cb2022-09-03 06:53:57 -0500157 bbfatal_log meson failed
158 fi
159}
160
161python 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}
169do_configure[postfuncs] += "meson_do_qa_configure"
170
171do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
172meson_do_compile() {
Andrew Geissler517393d2023-01-13 08:55:19 -0600173 meson compile -v ${PARALLEL_MAKE}
Patrick Williams92b42cb2022-09-03 06:53:57 -0500174}
175
176meson_do_install() {
Andrew Geissler517393d2023-01-13 08:55:19 -0600177 meson install --destdir ${D} --no-rebuild
Patrick Williams92b42cb2022-09-03 06:53:57 -0500178}
179
180EXPORT_FUNCTIONS do_configure do_compile do_install