blob: 48688bed755184e382608d7fa6bbed746b6759ab [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)}
114pkgconfig = 'pkg-config-native'
115${@rust_tool(d, "BUILD_SYS")}
116
117[built-in options]
118c_args = ${@meson_array('BUILD_CFLAGS', d)}
119c_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
120cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)}
121cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
122EOF
123}
124
125do_write_config:append:class-target() {
126 # Write out a qemu wrapper that will be used as exe_wrapper so that meson
127 # can run target helper binaries through that.
128 qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
129 cat > ${WORKDIR}/meson-qemuwrapper << EOF
130#!/bin/sh
131# Use a modules directory which doesn't exist so we don't load random things
132# which may then get deleted (or their dependencies) and potentially segfault
133export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
134
135# meson sets this wrongly (only to libs in build-dir), qemu_wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
136unset LD_LIBRARY_PATH
137
138$qemu_binary "\$@"
139EOF
140 chmod +x ${WORKDIR}/meson-qemuwrapper
141}
142
143# Tell externalsrc that changes to this file require a reconfigure
144CONFIGURE_FILES = "meson.build"
145
146meson_do_configure() {
147 # Meson requires this to be 'bfd, 'lld' or 'gold' from 0.53 onwards
148 # https://github.com/mesonbuild/meson/commit/ef9aeb188ea2bc7353e59916c18901cde90fa2b3
149 unset LD
150
151 # Work around "Meson fails if /tmp is mounted with noexec #2972"
152 mkdir -p "${B}/meson-private/tmp"
153 export TMPDIR="${B}/meson-private/tmp"
154 bbnote Executing meson ${EXTRA_OEMESON}...
Andrew Geissler517393d2023-01-13 08:55:19 -0600155 if ! meson setup ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then
Patrick Williams92b42cb2022-09-03 06:53:57 -0500156 bbfatal_log meson failed
157 fi
158}
159
160python meson_do_qa_configure() {
161 import re
162 warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE)
163 with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile:
164 log = logfile.read()
165 for (prop, value) in warn_re.findall(log):
166 bb.warn("Meson cross property %s used without explicit assignment, defaulting to %s" % (prop, value))
167}
168do_configure[postfuncs] += "meson_do_qa_configure"
169
170do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
171meson_do_compile() {
Andrew Geissler517393d2023-01-13 08:55:19 -0600172 meson compile -v ${PARALLEL_MAKE}
Patrick Williams92b42cb2022-09-03 06:53:57 -0500173}
174
175meson_do_install() {
Andrew Geissler517393d2023-01-13 08:55:19 -0600176 meson install --destdir ${D} --no-rebuild
Patrick Williams92b42cb2022-09-03 06:53:57 -0500177}
178
179EXPORT_FUNCTIONS do_configure do_compile do_install