nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1From 7c6adc3fbb3624261b9c4d4e0702018697486e3b Mon Sep 17 00:00:00 2001
2From: Andrea Pappacoda <andrea@pappacoda.it>
3Date: Wed, 7 Aug 2024 00:11:15 +0200
4Subject: [PATCH] build: add Meson support
5
6I was trying to package Vixl, but the SCons build system does not
7provide an install target, so I would've had to add it. It seemed too
8difficult, so I directly created a quite basic Meson build script.
9
10It provides most features of the SCons script, except for tests and
11benchmarks, while adding a rich install target, with library soname
12versioning and a pkg-config file.
13
14Meson is a simple yet powerful build system, and you're interested in
15using it as your main build system I could add tests and benchmarks :)
16
17Origin: upstream, https://github.com/Linaro/vixl/pull/7
18Last-Update: 2025-03-22
19---
20 AUTHORS | 1 +
21 doc/aarch32/meson.build | 12 +++
22 doc/aarch64/meson.build | 21 +++++
23 doc/aarch64/topics/meson.build | 21 +++++
24 doc/meson.build | 21 +++++
25 meson.build | 158 +++++++++++++++++++++++++++++++++
26 meson_options.txt | 40 +++++++++
27 src/aarch32/meson.build | 30 +++++++
28 src/aarch64/meson.build | 47 ++++++++++
29 9 files changed, 351 insertions(+)
30 create mode 100644 doc/aarch32/meson.build
31 create mode 100644 doc/aarch64/meson.build
32 create mode 100644 doc/aarch64/topics/meson.build
33 create mode 100644 doc/meson.build
34 create mode 100644 meson.build
35 create mode 100644 meson_options.txt
36 create mode 100644 src/aarch32/meson.build
37 create mode 100644 src/aarch64/meson.build
38
39diff --git a/AUTHORS b/AUTHORS
40index 257ec9d3..13809d26 100644
41--- a/AUTHORS
42+++ b/AUTHORS
43@@ -6,3 +6,4 @@
44 ARM Ltd. <*@arm.com>
45 Google Inc. <*@google.com>
46 Linaro <*@linaro.org>
47+Andrea Pappacoda <andrea@pappacoda.it>
48diff --git a/doc/aarch32/meson.build b/doc/aarch32/meson.build
49new file mode 100644
50index 00000000..e07fc46d
51--- /dev/null
52+++ b/doc/aarch32/meson.build
53@@ -0,0 +1,12 @@
54+# SPDX-FileCopyrightText: 2021 VIXL authors
55+# SPDX-License-Identifier: BSD-3-Clause
56+
57+custom_target(
58+ 'doc_aarch32',
59+ command: [markdown, '@INPUT@'],
60+ input: 'getting-started-aarch32.md',
61+ output: '@BASENAME@.html',
62+ capture: true,
63+ install: true,
64+ install_dir: doc_dir/'aarch32'
65+)
66diff --git a/doc/aarch64/meson.build b/doc/aarch64/meson.build
67new file mode 100644
68index 00000000..d25f8bfa
69--- /dev/null
70+++ b/doc/aarch64/meson.build
71@@ -0,0 +1,21 @@
72+# SPDX-FileCopyrightText: 2021 VIXL authors
73+# SPDX-License-Identifier: BSD-3-Clause
74+
75+doc_aarch64_files = [
76+ 'getting-started-aarch64',
77+ 'supported-instructions-aarch64'
78+]
79+
80+foreach file : doc_aarch64_files
81+ custom_target(
82+ 'doc_aarch64_' + file,
83+ command: [markdown, '@INPUT@'],
84+ input: file + '.md',
85+ output: file + '.html',
86+ capture: true,
87+ install: true,
88+ install_dir: doc_dir/'aarch64'
89+ )
90+endforeach
91+
92+subdir('topics')
93diff --git a/doc/aarch64/topics/meson.build b/doc/aarch64/topics/meson.build
94new file mode 100644
95index 00000000..c6e8542b
96--- /dev/null
97+++ b/doc/aarch64/topics/meson.build
98@@ -0,0 +1,21 @@
99+# SPDX-FileCopyrightText: 2021 VIXL authors
100+# SPDX-License-Identifier: BSD-3-Clause
101+
102+doc_aarch64_topics_files = [
103+ 'extending-the-disassembler',
104+ 'index',
105+ 'state-trace',
106+ 'ycm'
107+]
108+
109+foreach file : doc_aarch64_topics_files
110+ custom_target(
111+ 'doc_aarch64_topics_' + file,
112+ command: [markdown, '@INPUT@'],
113+ input: file + '.md',
114+ output: file + '.html',
115+ capture: true,
116+ install: true,
117+ install_dir: doc_dir/'aarch64'/'topics'
118+ )
119+endforeach
120diff --git a/doc/meson.build b/doc/meson.build
121new file mode 100644
122index 00000000..cbfe193d
123--- /dev/null
124+++ b/doc/meson.build
125@@ -0,0 +1,21 @@
126+# SPDX-FileCopyrightText: 2021 VIXL authors
127+# SPDX-License-Identifier: BSD-3-Clause
128+
129+doc_dir = get_option('datadir')/'doc'/meson.project_name()
130+
131+custom_target(
132+ 'doc',
133+ command: [markdown, '@INPUT@'],
134+ input: '..'/'README.md',
135+ output: '@BASENAME@.html',
136+ capture: true,
137+ install: true,
138+ install_dir: doc_dir
139+)
140+
141+if build_a32 or build_t32
142+ subdir('aarch32')
143+endif
144+if build_a64
145+ subdir('aarch64')
146+endif
147diff --git a/meson.build b/meson.build
148new file mode 100644
149index 00000000..e0f8f79a
150--- /dev/null
151+++ b/meson.build
152@@ -0,0 +1,158 @@
153+# SPDX-FileCopyrightText: 2021 VIXL authors
154+# SPDX-License-Identifier: BSD-3-Clause
155+
156+project(
157+ 'vixl',
158+ 'cpp',
159+ default_options: [
160+ 'cpp_std=c++17',
161+ 'buildtype=release',
162+ 'warning_level=3',
163+ 'werror=true',
164+ 'd_ndebug=if-release',
165+ 'b_lto=true'
166+ ],
167+ license: 'BSD-3-Clause',
168+ meson_version: '>=0.50.0',
169+ version: '8.0.0',
170+)
171+
172+deps = []
173+extra_args = []
174+
175+if get_option('debug')
176+ extra_args += '-DVIXL_DEBUG'
177+endif
178+
179+hosts_32bit = ['arc', 'arm', 'c2000', 'csky', 'mips', 'ppc', 'riscv32', 'rx', 'sparc', 'wasm32', 'x86']
180+can_target_aarch64 = not (host_machine.cpu_family() in hosts_32bit)
181+
182+build_a32 = false
183+build_t32 = false
184+build_a64 = false
185+
186+targets = get_option('target')
187+if 'auto' in targets or 'all' in targets
188+ if can_target_aarch64 or 'all' in targets
189+ extra_args += [
190+ '-DVIXL_INCLUDE_TARGET_A32',
191+ '-DVIXL_INCLUDE_TARGET_T32',
192+ '-DVIXL_INCLUDE_TARGET_A64'
193+ ]
194+ build_a32 = true
195+ build_t32 = true
196+ build_a64 = true
197+ else
198+ extra_args += [
199+ '-DVIXL_INCLUDE_TARGET_A32',
200+ '-DVIXL_INCLUDE_TARGET_T32'
201+ ]
202+ build_a32 = true
203+ build_t32 = true
204+ endif
205+else
206+ if 'a32' in targets or 'aarch32' in targets
207+ extra_args += [
208+ '-DVIXL_INCLUDE_TARGET_A32'
209+ ]
210+ build_a32 = true
211+ endif
212+ if 't32' in targets or 'aarch32' in targets
213+ extra_args += [
214+ '-DVIXL_INCLUDE_TARGET_T32'
215+ ]
216+ build_t32 = true
217+ endif
218+ if 'a64' in targets or 'aarch64' in targets
219+ extra_args += [
220+ '-DVIXL_INCLUDE_TARGET_A64'
221+ ]
222+ build_a64 = true
223+ endif
224+endif
225+
226+target_sources = []
227+if build_a32 or build_t32
228+ subdir('src'/'aarch32')
229+endif
230+if build_a64
231+ subdir('src'/'aarch64')
232+endif
233+
234+if get_option('simulator') == 'auto'
235+ if not (host_machine.cpu_family() == 'aarch64') and can_target_aarch64
236+ extra_args += '-DVIXL_INCLUDE_SIMULATOR_AARCH64'
237+ deps += dependency('threads')
238+ endif
239+elif get_option('simulator') == 'aarch64'
240+ if can_target_aarch64 and build_a64
241+ extra_args += '-DVIXL_INCLUDE_SIMULATOR_AARCH64'
242+ deps += dependency('threads')
243+ else
244+ error('Building an AArch64 simulator implies that VIXL targets AArch64. Set `target` to include `aarch64` or `a64`.')
245+ endif
246+endif
247+
248+allocator = get_option('code_buffer_allocator')
249+if (allocator == 'auto' and host_machine.system() == 'linux') or allocator == 'mmap'
250+ extra_args += '-DVIXL_CODE_BUFFER_MMAP'
251+else
252+ extra_args += '-DVIXL_CODE_BUFFER_MALLOC'
253+endif
254+
255+if get_option('implicit_checks')
256+ extra_args += '-DVIXL_ENABLE_IMPLICIT_CHECKS'
257+endif
258+
259+markdown = find_program('markdown', required: get_option('doc'))
260+if markdown.found()
261+ subdir('doc')
262+endif
263+
264+libvixl = library(
265+ 'vixl',
266+ 'src'/'code-buffer-vixl.cc',
267+ 'src'/'compiler-intrinsics-vixl.cc',
268+ 'src'/'cpu-features.cc',
269+ 'src'/'utils-vixl.cc',
270+ cpp_args: extra_args,
271+ include_directories: 'src',
272+ dependencies: deps,
273+ install: true,
274+ sources: target_sources,
275+ version: meson.project_version()
276+)
277+
278+vixl_dep = declare_dependency(
279+ compile_args: extra_args,
280+ include_directories: 'src',
281+ link_with: libvixl
282+)
283+
284+if meson.version().version_compare('>=0.54.0')
285+ meson.override_dependency('vixl', vixl_dep)
286+endif
287+
288+install_headers(
289+ 'src'/'assembler-base-vixl.h',
290+ 'src'/'code-buffer-vixl.h',
291+ 'src'/'code-generation-scopes-vixl.h',
292+ 'src'/'compiler-intrinsics-vixl.h',
293+ 'src'/'cpu-features.h',
294+ 'src'/'globals-vixl.h',
295+ 'src'/'invalset-vixl.h',
296+ 'src'/'macro-assembler-interface.h',
297+ 'src'/'platform-vixl.h',
298+ 'src'/'pool-manager-impl.h',
299+ 'src'/'pool-manager.h',
300+ 'src'/'utils-vixl.h',
301+ subdir: 'vixl'
302+)
303+
304+import('pkgconfig').generate(
305+ libvixl,
306+ description: 'ARMv8 Runtime Code Generation Library',
307+ extra_cflags: extra_args,
308+ subdirs: 'vixl',
309+ url: 'https://github.com/Linaro/vixl'
310+)
311diff --git a/meson_options.txt b/meson_options.txt
312new file mode 100644
313index 00000000..b7b5428d
314--- /dev/null
315+++ b/meson_options.txt
316@@ -0,0 +1,40 @@
317+# SPDX-FileCopyrightText: 2021 VIXL authors
318+# SPDX-License-Identifier: BSD-3-Clause
319+
320+option(
321+ 'target',
322+ type: 'array',
323+ choices: ['auto', 'all', 'aarch32', 'a32', 't32', 'aarch64', 'a64'],
324+ value: ['auto'],
325+ description: 'Target ISA/Architecture'
326+)
327+
328+option(
329+ 'simulator',
330+ type: 'combo',
331+ choices: ['auto', 'aarch64', 'none'],
332+ value: 'auto',
333+ description: 'Simulators to include'
334+)
335+
336+option(
337+ 'code_buffer_allocator',
338+ type: 'combo',
339+ choices: ['auto', 'malloc', 'mmap'],
340+ value: 'auto',
341+ description: 'Configure the allocation mechanism in the CodeBuffer'
342+)
343+
344+option(
345+ 'implicit_checks',
346+ type: 'boolean',
347+ value: false,
348+ description: 'Allow signals raised from simulated invalid (e.g: out of bounds) memory reads to be handled by the host.'
349+)
350+
351+option(
352+ 'doc',
353+ type: 'feature',
354+ value: 'auto',
355+ description: 'Convert documentation to HTML (requires the `markdown` program)'
356+)
357diff --git a/src/aarch32/meson.build b/src/aarch32/meson.build
358new file mode 100644
359index 00000000..0b22336f
360--- /dev/null
361+++ b/src/aarch32/meson.build
362@@ -0,0 +1,30 @@
363+# SPDX-FileCopyrightText: 2021 VIXL authors
364+# SPDX-License-Identifier: BSD-3-Clause
365+
366+# Need to wrap the filenames in files() otherwise this array would be treated
367+# as a simple array of strings, and when used in the master meson.build they
368+# would refer to nonexistent paths. Wrapping in files() ensures that the
369+# filenames will be always relative to this directory, even if referenced in
370+# a different one. As a general rule, when I need to refer to a file from a
371+# different build directory I should wrap it in files().
372+
373+target_sources += files(
374+ 'assembler-aarch32.cc',
375+ 'constants-aarch32.cc',
376+ 'disasm-aarch32.cc',
377+ 'instructions-aarch32.cc',
378+ 'location-aarch32.cc',
379+ 'macro-assembler-aarch32.cc',
380+ 'operands-aarch32.cc'
381+)
382+
383+install_headers(
384+ 'assembler-aarch32.h',
385+ 'constants-aarch32.h',
386+ 'disasm-aarch32.h',
387+ 'instructions-aarch32.h',
388+ 'location-aarch32.h',
389+ 'macro-assembler-aarch32.h',
390+ 'operands-aarch32.h',
391+ subdir: 'vixl'/'aarch32'
392+)
393diff --git a/src/aarch64/meson.build b/src/aarch64/meson.build
394new file mode 100644
395index 00000000..2898c8f6
396--- /dev/null
397+++ b/src/aarch64/meson.build
398@@ -0,0 +1,47 @@
399+# SPDX-FileCopyrightText: 2021 VIXL authors
400+# SPDX-License-Identifier: BSD-3-Clause
401+
402+# Need to wrap the filenames in files() otherwise this array would be treated
403+# as a simple array of strings, and when used in the master meson.build they
404+# would refer to nonexistent paths. Wrapping in files() ensures that the
405+# filenames will be always relative to this directory, even if referenced in
406+# a different one. As a general rule, when I need to refer to a file from a
407+# different build directory I should wrap it in files().
408+
409+target_sources += files(
410+ 'assembler-aarch64.cc',
411+ 'assembler-sve-aarch64.cc',
412+ 'cpu-aarch64.cc',
413+ 'cpu-features-auditor-aarch64.cc',
414+ 'debugger-aarch64.cc',
415+ 'decoder-aarch64.cc',
416+ 'disasm-aarch64.cc',
417+ 'instructions-aarch64.cc',
418+ 'logic-aarch64.cc',
419+ 'macro-assembler-aarch64.cc',
420+ 'macro-assembler-sve-aarch64.cc',
421+ 'operands-aarch64.cc',
422+ 'pointer-auth-aarch64.cc',
423+ 'registers-aarch64.cc',
424+ 'simulator-aarch64.cc'
425+)
426+
427+install_headers(
428+ 'abi-aarch64.h',
429+ 'assembler-aarch64.h',
430+ 'constants-aarch64.h',
431+ 'cpu-aarch64.h',
432+ 'cpu-features-auditor-aarch64.h',
433+ 'debugger-aarch64.h',
434+ 'decoder-aarch64.h',
435+ 'decoder-constants-aarch64.h',
436+ 'decoder-visitor-map-aarch64.h',
437+ 'disasm-aarch64.h',
438+ 'instructions-aarch64.h',
439+ 'macro-assembler-aarch64.h',
440+ 'operands-aarch64.h',
441+ 'registers-aarch64.h',
442+ 'simulator-aarch64.h',
443+ 'simulator-constants-aarch64.h',
444+ subdir: 'vixl'/'aarch64'
445+)