Repository navigation
Expand file tree
/
Copy pathmeson.build
More file actions
199 lines (179 loc) · 7.53 KB
/
Copy pathmeson.build
File metadata and controls
199 lines (179 loc) · 7.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
project(
'ycpp',
'cpp',
version: '0.1.3',
license: 'MIT',
meson_version: '>=1.5',
default_options: [
# MSVC (in the Meson versions wheels use) only knows c++latest; gcc and clang take c++23.
'cpp_std=c++23,c++latest',
'warning_level=3',
'default_library=static',
],
)
ycpp_include = include_directories('include')
# The options reach the sources as one generated header rather than as a compile argument, so a
# consumer that looks at <ycpp/config.hpp> sees the configuration the library was built with.
text_enabled = get_option('text').enabled()
array_enabled = get_option('array').enabled()
# The xml types are built on text and array: auto follows them, an explicit -Dxml=enabled without
# them is a configuration error rather than a link error.
xml_enabled = get_option('xml').require(text_enabled and array_enabled,
error_message: 'the xml types need -Dtext and -Darray').allowed()
subdoc_enabled = get_option('subdoc').enabled()
undo_enabled = get_option('undo').enabled()
observe_deep_enabled = get_option('observe_deep').enabled()
ycpp_config = configuration_data()
ycpp_config.set10('YCPP_FEATURE_TEXT', text_enabled)
ycpp_config.set10('YCPP_FEATURE_ARRAY', array_enabled)
ycpp_config.set10('YCPP_FEATURE_XML', xml_enabled)
ycpp_config.set10('YCPP_FEATURE_SUBDOC', subdoc_enabled)
ycpp_config.set10('YCPP_FEATURE_UNDO', undo_enabled)
ycpp_config.set10('YCPP_FEATURE_DEEP_OBSERVE', observe_deep_enabled)
# Generated into <builddir>/include/ycpp/config.hpp, which include_directories('include') covers.
subdir('include/ycpp')
# Floating point formatting/parsing without libstdc++'s floating charconv, which costs ~200 KB of
# text on Cortex-M (see scripts/size_check.sh).
# Static always: a board has no shared libraries, and the two are small.
dragonbox_dep = dependency('dragonbox', fallback: ['dragonbox', 'dragonbox_dep'], default_options: ['default_library=static'])
fast_float_dep = dependency('FastFloat', fallback: ['fast_float', 'fast_float_dep'])
ycpp_sources = files(
'src/encoding.cpp',
'src/any.cpp',
'src/state_vector.cpp',
'src/delete_set.cpp',
'src/content.cpp',
'src/utf8.cpp',
'src/sequence.cpp',
'src/index.cpp',
'src/store.cpp',
'src/update.cpp',
'src/update_v2.cpp',
'src/integrate.cpp',
'src/doc.cpp',
'src/map.cpp',
'src/json_parse.cpp',
# The sync and awareness protocols are bytes over a Doc: no transport, no timer, so every build that
# has a document has them.
'src/sync.cpp',
'src/awareness.cpp',
# The store-side half of the text type: Yjs runs it on every transaction, so it stays compiled even
# when the text API is off (see src/text_cleanup.cpp).
'src/text_cleanup.cpp',
)
if text_enabled
ycpp_sources += files('src/text.cpp')
endif
if array_enabled
ycpp_sources += files('src/array.cpp')
endif
# Relative positions name a list position, so only a build with a list has one: a map-only image does
# not pay for the walk or for the JSON form.
if text_enabled or array_enabled
ycpp_sources += files('src/relative_position.cpp')
endif
if xml_enabled
ycpp_sources += files('src/xml.cpp')
endif
if subdoc_enabled
ycpp_sources += files('src/subdoc.cpp')
endif
# Snapshots are the wire form of a document's history: small, and a peer may send one, so they stay
# compiled. The undo manager needs a hook in transaction cleanup, so a build without it pays nothing
# for the feature at all.
ycpp_sources += files('src/snapshot.cpp')
if undo_enabled
ycpp_sources += files('src/undo_manager.cpp')
endif
ycpp_depth_arg = '-DYCPP_MAX_ANY_DEPTH=@0@'.format(get_option('max_any_depth'))
# The UTF-8 helpers are the whole cost of pasting or applying a large text (see .superpowers/utf8-simd.md).
# `none` keeps the portable scalar code; every other choice compiles the xsimd kernels and fixes the
# instruction set at build time, because a wheel cannot dispatch per call and a board build must stay
# scalar (and small).
simd_choice = get_option('simd')
cpp_compiler = meson.get_compiler('cpp')
# GCC 14 reports std::variant alternatives (Any, a path step) as maybe used uninitialized once it
# inlines their copies at -O2 or under sanitizers: false positives, and a consumer building with
# -Werror (PRISM's wheels and sanitizer jobs) fails on them. Clang, which has no such warning, still
# checks the same code with -Werror in CI.
if cpp_compiler.get_id() == 'gcc'
add_project_arguments('-Wno-maybe-uninitialized', language: 'cpp')
endif
simd_args = []
simd_deps = []
if simd_choice != 'none'
simd_deps += dependency('xsimd', fallback: ['xsimd', 'xsimd_dep'])
simd_args += '-DYCPP_UTF8_SIMD'
x86 = host_machine.cpu_family() in ['x86', 'x86_64']
if not x86
# An arm build has no x86 level to fix: keep the kernels, leave the ISA to the compiler, which on
# arm64 is NEON anyway.
if simd_choice == 'native'
simd_args += '-march=native'
else
warning('simd=' + simd_choice + ' has no x86 meaning on ' + host_machine.cpu_family() + '; using the default ISA')
endif
elif cpp_compiler.get_id() == 'msvc'
# MSVC has no switch that targets SSE4.2: the intrinsics are always available, and xsimd chooses
# its kernels from the predefined macros, so the define is what selects the sse4_2 path. For AVX2
# the switch exists, and it is also the highest level MSVC can fix at build time.
if simd_choice == 'sse4.2'
# The whole ladder: xsimd's sse4_2 kernels also use SSSE3 and SSE4.1 intrinsics, and MSVC still
# emits them without an /arch switch as long as the macros say the level exists.
simd_args += ['-D__SSE3__', '-D__SSSE3__', '-D__SSE4_1__', '-D__SSE4_2__']
else
simd_args += '/arch:AVX2'
endif
else
# gcc, clang and clang-cl all take the GNU flags.
simd_isa = {'sse4.2': '-msse4.2', 'avx2': '-mavx2', 'native': '-march=native'}
simd_args += simd_isa[simd_choice]
endif
endif
# No exceptions: the decoder returns std::expected and nothing below throws. MSVC has no switch for
# that which keeps its standard library usable (`_HAS_EXCEPTIONS=0` is a well-known source of header
# incompatibilities), so it keeps the default and pays only the unwind tables: ycpp never throws, so
# the behaviour is the same. Every other compiler gets the real thing.
no_exceptions_args = []
if cpp_compiler.get_id() != 'msvc'
no_exceptions_args += '-fno-exceptions'
endif
ycpp_lib = library(
'ycpp',
ycpp_sources,
include_directories: ycpp_include,
dependencies: [dragonbox_dep, fast_float_dep] + simd_deps,
cpp_args: no_exceptions_args + [ycpp_depth_arg] + simd_args,
)
ycpp_dep = declare_dependency(
link_with: ycpp_lib,
include_directories: ycpp_include,
dependencies: [dragonbox_dep, fast_float_dep],
compile_args: [ycpp_depth_arg],
)
meson.override_dependency('ycpp', ycpp_dep)
# A subproject user (PRISM) wants the library and nothing else: its tests, fuzzer and benchmarks
# are not a consumer's business, and a board build has no host to run them on.
if not meson.is_subproject()
if get_option('fuzz')
if cpp_compiler.get_id() != 'clang'
error('-Dfuzz=true needs clang: -fsanitize=fuzzer is a clang feature, not an MSVC or gcc one')
endif
# Not registered as a test: run it by hand, e.g.
# builddir-fuzz/fuzz_apply_update -max_total_time=300
executable(
'fuzz_apply_update',
'tests/fuzz_apply_update.cpp',
dependencies: ycpp_dep,
cpp_args: ['-fsanitize=fuzzer,address'],
link_args: ['-fsanitize=fuzzer,address'],
)
endif
subdir('tests')
if get_option('benchmarks') or get_option('utf8_check')
subdir('benchmarks')
endif
endif
if get_option('python').enabled()
subdir('python')
endif