-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmeson.build
More file actions
549 lines (486 loc) · 19.9 KB
/
Copy pathmeson.build
File metadata and controls
549 lines (486 loc) · 19.9 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
project(
'wirelog',
'c',
version: '0.54.99',
license: 'LGPL-3.0-or-later',
meson_version: '>=0.62.0',
default_options: [
'buildtype=release',
'optimization=s',
'b_lto=true',
'b_sanitize=none',
]
)
#Project metadata
project_name = meson.project_name()
project_version = meson.project_version()
project_license = 'LGPL-3.0-or-later'
project_url = 'https://github.com/semantic-reasoning/wirelog'
#Directories
wirelog_libdir = get_option('libdir')
wirelog_includedir = get_option('includedir')
wirelog_datadir = get_option('datadir') / project_name
#Build options (must be read before compiler settings for CRC-32 variant)
crc32_variant_option = get_option('crc32_variant')
#Compiler settings
cc = meson.get_compiler('c')
# CRC-32 variant define
crc32_defines = []
if crc32_variant_option == 'ethernet'
crc32_defines = ['-DCRC32_DEFAULT_VARIANT_ETHERNET']
elif crc32_variant_option == 'castagnoli'
crc32_defines = ['-DCRC32_DEFAULT_VARIANT_CASTAGNOLI']
endif
if cc.get_id() == 'msvc'
# MSVC C11 atomics are incomplete
# Define __STDC_NO_ATOMICS__ to skip C11 atomics declarations
add_project_arguments(
['/W3', '/D__STDC_NO_ATOMICS__'] + crc32_defines,
language: 'c'
)
else
# GCC/Clang: enforce C11 standard
add_project_arguments(
['-std=c11'] + crc32_defines,
language: 'c'
)
# GCC/Clang: add SIMD support flags for AVX2 and NEON optimization
simd_flags = []
if host_machine.cpu_family() == 'aarch64'
simd_flags = ['-march=armv8-a+simd'] # ARM64: enable NEON
elif host_machine.cpu_family() == 'x86_64'
simd_flags = ['-mavx2'] # x86-64: enable AVX2 (portable base)
endif
add_project_arguments(
[
'-Wall',
'-Wextra',
'-Wno-unused-parameter',
'-Wno-missing-field-initializers',
] + simd_flags,
language: 'c'
)
endif
# Issue #287: structured logger compile-time ceiling.
_log_level_map = {'error': 1, 'warn': 2, 'info': 3, 'debug': 4, 'trace': 5}
_log_opt = get_option('wirelog_log_max_level')
add_project_arguments(
'-DWL_LOG_COMPILE_MAX_LEVEL=' + _log_level_map[_log_opt].to_string(),
language: 'c',
)
if _log_opt == 'trace' and get_option('buildtype') == 'release'
warning(
'wirelog_log_max_level=trace in release build; pass -Dwirelog_log_max_level=error for zero-cost disabled log sites.'
)
endif
#Platform detection
platform = host_machine.system()
is_embedded = get_option('embedded')
is_windows = platform == 'windows'
is_macos = platform == 'darwin'
is_linux = platform == 'linux'
is_android = get_option('android')
# Issue #464: Android packaging needs 16 KB ELF page alignment on aarch64
# so the same .so loads on both 4 KB and 16 KB kernels (Android 14+ on
# arm64). Gated on cpu_family == 'aarch64' because 16 KB pages are an
# arm64-only kernel feature; the flag is meaningless on armv7 (deprecated)
# and harmless-but-irrelevant on x86_64 emulator builds.
#
# Note: on an aarch64 Linux host (e.g., Ampere / Apple Silicon Linux)
# invoking `-Dandroid=true` without a cross-file would also add the flag
# to a *Linux* .so. Linux honors -Wl,-z,max-page-size as the maximum
# alignment a load segment may take, so the resulting .so is forward-
# compatible with hypothetical 16 KB Linux kernels and unchanged on
# normal 4 KB hosts. Cross-compilation via cross/android-*.ini is the
# supported path; native-host -Dandroid=true is meant for option-flow
# testing, not shipping.
wirelog_android_link_args = []
if is_android and host_machine.cpu_family() == 'aarch64'
wirelog_android_link_args += ['-Wl,-z,max-page-size=16384']
endif
#Build options
ipc_option = get_option('ipc')
threads_option = get_option('threads')
tests_option = get_option('tests')
docs_option = get_option('documentation')
# crc32_variant_option already defined earlier before compiler settings
io_plugin_dlopen_option = get_option('io_plugin_dlopen')
ios_option = get_option('ios')
message('wirelog ' + project_version)
message(' Platform: ' + platform)
message(' Embedded: @0@'.format(is_embedded))
message(' IPC support: ' + ipc_option)
message(' Threading: ' + threads_option)
message(' CRC-32 variant: ' + crc32_variant_option)
message(' Plugin loader (dlopen): ' + io_plugin_dlopen_option)
message(' iOS: @0@'.format(ios_option))
mobile_cross = is_android or ios_option
wirelog_ios_link_args = []
if ios_option
ios_min_version = meson.get_external_property('wirelog_ios_min_version', '13.0')
ios_platform = meson.get_external_property('wirelog_ios_platform', 'iphoneos')
ios_arch = meson.get_external_property('wirelog_ios_arch',
host_machine.cpu_family() == 'x86_64' ? 'x86_64' : 'arm64')
if ios_platform == 'iphonesimulator'
ios_target = ios_arch + '-apple-ios' + ios_min_version + '-simulator'
else
ios_target = ios_arch + '-apple-ios' + ios_min_version
endif
add_project_arguments(['-target', ios_target], language: 'c')
wirelog_ios_link_args += ['-target', ios_target]
message(' iOS target: ' + ios_target)
endif
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Dependencies
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#pthreads for threading
threads_dep = []
_td = dependency('threads', required: false)
if not _td.found()
_td = cc.find_library('pthread', required: false)
endif
if _td.found()
threads_dep = [_td]
endif
#Optional : zlib for IPC compression(future)
zlib_dep = []
if ipc_option == 'enabled'
_zd = dependency('zlib', required: false)
if _zd.found()
zlib_dep = [_zd]
endif
endif
#Phase 2A : nanoarrow for columnar backend(via meson wrap)
nanoarrow_proj = subproject('nanoarrow', default_options: ['tests=disabled', 'apps=disabled', 'ipc=disabled', 'device=disabled', 'testing=disabled'])
nanoarrow_dep = nanoarrow_proj.get_variable('nanoarrow_dep')
#Built-in functions : xxHash3 for hash() function
xxhash_proj = subproject('xxhash', default_options: [])
#Optional : mbedTLS for cryptographic functions (Issue #73)
mbedtls_option = get_option('mbedTLS')
mbedtls_dep = []
mbedtls_required_headers = [
'psa/crypto.h',
]
mbedtls_psa_probe = '''
#include <psa/crypto.h>
int main(void) {
unsigned char input[8] = {0};
unsigned char output[64] = {0};
size_t output_len = 0;
psa_hash_operation_t hash_op = PSA_HASH_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_id_t key = 0;
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) return 1;
(void)psa_hash_compute(PSA_ALG_MD5, input, sizeof(input),
output, sizeof(output), &output_len);
(void)psa_hash_compute(PSA_ALG_SHA_1, input, sizeof(input),
output, sizeof(output), &output_len);
(void)psa_hash_compute(PSA_ALG_SHA_256, input, sizeof(input),
output, sizeof(output), &output_len);
(void)psa_hash_compute(PSA_ALG_SHA_512, input, sizeof(input),
output, sizeof(output), &output_len);
(void)psa_hash_setup(&hash_op, PSA_ALG_SHA_1);
(void)psa_hash_update(&hash_op, input, sizeof(input));
(void)psa_hash_finish(&hash_op, output, sizeof(output), &output_len);
psa_set_key_type(&attributes, PSA_KEY_TYPE_HMAC);
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_MESSAGE);
psa_set_key_algorithm(&attributes, PSA_ALG_HMAC(PSA_ALG_SHA_256));
status = psa_import_key(&attributes, input, sizeof(input), &key);
psa_reset_key_attributes(&attributes);
if (status != PSA_SUCCESS) return 1;
(void)psa_mac_compute(key, PSA_ALG_HMAC(PSA_ALG_SHA_256), input,
sizeof(input), output, sizeof(output), &output_len);
(void)psa_destroy_key(key);
(void)psa_generate_random(output, 16);
return 0;
}
'''
mbedtls_psa_candidates = [
'tfpsacrypto',
'mbedcrypto',
'mbedtls',
]
if mbedtls_option == 'auto' or mbedtls_option == 'enabled'
mbedtls_psa_provider = ''
mbedtls_psa_provider_version = ''
mbedtls_psa_rejections = []
foreach _mbedtls_candidate : mbedtls_psa_candidates
if mbedtls_psa_provider != ''
continue
endif
_mbedtls_crypto = dependency(_mbedtls_candidate, required: false)
if not _mbedtls_crypto.found()
mbedtls_psa_rejections += [_mbedtls_candidate + ': not found']
continue
endif
_mbedtls_candidate_dep = [_mbedtls_crypto]
_mbedtls_missing_headers = []
foreach _mbedtls_header : mbedtls_required_headers
if not cc.has_header(_mbedtls_header, dependencies: _mbedtls_candidate_dep)
_mbedtls_missing_headers += [_mbedtls_header]
endif
endforeach
if _mbedtls_missing_headers.length() > 0
mbedtls_psa_rejections += [_mbedtls_candidate + ': missing headers <' + '>, <'.join(_mbedtls_missing_headers) + '>']
continue
endif
if cc.links(mbedtls_psa_probe,
dependencies: _mbedtls_candidate_dep,
name: 'PSA Crypto hash, HMAC, and random APIs via ' + _mbedtls_candidate)
mbedtls_dep = _mbedtls_candidate_dep
mbedtls_psa_provider = _mbedtls_candidate
mbedtls_psa_provider_version = _mbedtls_crypto.version()
else
mbedtls_psa_rejections += [_mbedtls_candidate + ': failed PSA Crypto link probe']
endif
endforeach
if mbedtls_psa_provider != ''
message(' mbedTLS PSA provider: ' + mbedtls_psa_provider + ' ' + mbedtls_psa_provider_version)
add_project_arguments('-DWL_MBEDTLS_ENABLED=1', language: 'c')
elif mbedtls_option == 'auto'
warning('mbedTLS auto-detection did not find a linkable PSA Crypto provider; crypto built-ins will remain disabled. Candidates: ' + '; '.join(mbedtls_psa_rejections))
else
error('mbedTLS enabled requires a linkable PSA Crypto provider exposing <psa/crypto.h>. Candidates: ' + '; '.join(mbedtls_psa_rejections))
endif
endif
xxhash_dep = xxhash_proj.get_variable('xxhash_dep')
# Math library for col_compute_worker_cap (Issue #409)
# On most POSIX systems libm is separate; on some (musl, glibc 2.38+) it is
# part of libc and find_library may return not-found. Fall back to a raw
# -lm link_args which is harmless when libm is folded into libc.
_math_lib = cc.find_library('m', required: false)
if _math_lib.found()
math_dep = [_math_lib]
else
math_dep = [declare_dependency(link_args: '-lm')]
endif
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Configuration
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
config_h = configuration_data()
config_h.set_quoted('WIRELOG_PLATFORM', platform)
config_h.set('WIRELOG_EMBEDDED', is_embedded)
config_h.set('WIRELOG_IPC', ipc_option == 'enabled')
config_h.set('WIRELOG_THREADS', true)
#Generate config header
config_h_file = configure_file(
input: 'config.h.in',
output: 'wirelog-config.h',
configuration: config_h,
install_dir: wirelog_includedir / 'wirelog'
)
#Version header (Issue #688 / #704)
#The integer triple (WIRELOG_VERSION_MAJOR/MINOR/PATCH) is parsed from
#project_version with any '-rcN' / '-dev' suffix stripped; the suffix is
#preserved verbatim in WIRELOG_VERSION_STRING. The configure_file()
#call lives in wirelog/meson.build so the generated header lands in
#build/wirelog/wirelog-version.h, where include_directories('.') below
#picks it up under the canonical "wirelog/wirelog-version.h" path.
version_release = project_version.split('-')[0]
version_parts = version_release.split('.')
assert(version_parts.length() == 3,
'project_version must be MAJOR.MINOR.PATCH (got: @0@)'.format(project_version))
version_h = configuration_data()
version_h.set('WIRELOG_VERSION_MAJOR', version_parts[0].to_int())
version_h.set('WIRELOG_VERSION_MINOR', version_parts[1].to_int())
version_h.set('WIRELOG_VERSION_PATCH', version_parts[2].to_int())
version_h.set('WIRELOG_VERSION_STRING', project_version)
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Include directories
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
wirelog_inc = include_directories('.')
wirelog_src_inc = include_directories('wirelog')
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Source files
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Collect source files for each module
subdir('wirelog')
#Combine all sources
wirelog_sources = []
wirelog_sources += wirelog_parser_src
wirelog_sources += wirelog_ir_src
wirelog_sources += wirelog_optimizer_src
wirelog_sources += wirelog_arena_src
wirelog_sources += wirelog_thread_src
wirelog_sources += wirelog_backend_src
wirelog_sources += wirelog_crc32_src
wirelog_sources += wirelog_workqueue_src
wirelog_sources += wirelog_io_src
wirelog_sources += wirelog_string_ops_src
wirelog_sources += wirelog_wl_easy_src
wirelog_sources += wirelog_advanced_src
wirelog_sources += wirelog_api_facade_src
wirelog_sources += wirelog_util_log_src
#Public headers
wirelog_public_headers = [
'wirelog/wirelog.h',
'wirelog/wirelog-types.h',
'wirelog/wirelog-parser.h',
'wirelog/wirelog-ir.h',
'wirelog/wirelog-optimizer.h',
'wirelog/wirelog-export.h',
'wirelog/wirelog-easy.h',
'wirelog/wirelog-advanced.h',
]
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Build targets
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Shared library
wirelog_lib = library(
'wirelog',
wirelog_sources,
config_h_file,
include_directories: [wirelog_inc, wirelog_src_inc],
c_args: ['-DWIRELOG_BUILDING'],
link_args: wirelog_android_link_args + wirelog_ios_link_args,
dependencies: [threads_dep, zlib_dep, nanoarrow_dep, xxhash_dep, mbedtls_dep, math_dep],
install: true,
# SOVERSION ('soversion') is decoupled from project_version so the
# 1.0 ABI commitment is fixed at SOVERSION=1 ahead of project_version
# actually reaching 1.0.0. Linux: libwirelog.so.1 -> libwirelog.so.1.0.0.
# macOS: compatibility_version=1, current_version=1.0.0.
# Windows: meson auto-derives wirelog-1.dll from version major.
# See #733.
version: project_version,
soversion: '1',
darwin_versions: ['1', '1.0.0'],
# Symbol-visibility default: hidden. Every public-API function on the
# 9 installed headers carries WIRELOG_API (alias of WIRELOG_PUBLIC =
# visibility("default") / dllexport) per #733 K0 + #782. Internal
# symbols (wl_*, col_*, arr_*) are now hidden from the dynamic-symbol
# table; consumers who relied on resolving them through libwirelog.so
# must rebuild against the public surface. See #733.
gnu_symbol_visibility: ios_option ? 'default' : 'hidden',
)
#Static library(optional)
# Note: `wirelog_android_link_args` is intentionally NOT threaded here.
# Static archives carry object code only, not link-time attributes; ELF
# page alignment is decided when the .a is finally linked into a .so
# or executable by the downstream consumer.
wirelog_static_lib = static_library(
'wirelog_static',
wirelog_sources,
config_h_file,
include_directories: [wirelog_inc, wirelog_src_inc],
c_args: ['-DWIRELOG_BUILDING'],
link_args: wirelog_ios_link_args,
dependencies: [threads_dep, zlib_dep, nanoarrow_dep, xxhash_dep, mbedtls_dep, math_dep],
install: false, # Not installed by default
)
#Install public headers
install_headers(
wirelog_public_headers,
subdir: 'wirelog'
)
install_headers(
'wirelog/io/io_adapter.h',
subdir: 'wirelog/io'
)
install_data(
'wirelog/module.modulemap',
install_dir: wirelog_includedir / 'wirelog'
)
#pkg - config file
pkg = import('pkgconfig')
pkg.generate(
wirelog_lib,
name: project_name,
description: 'Embedded-to-Enterprise Datalog Engine',
version: project_version,
filebase: project_name,
)
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#CLI Driver
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
# Optional plugin loader via dlopen (Issue #461)
# Excluded from Windows builds (no dlopen); Android/iOS excluded via option default.
cli_plugin_src = []
cli_plugin_deps = []
cli_plugin_args = []
if io_plugin_dlopen_option == 'enabled' and not (is_windows or ios_option)
_dl_dep = cc.find_library('dl', required: false)
if _dl_dep.found()
cli_plugin_deps += [_dl_dep]
endif
cli_plugin_src = files('wirelog/cli/plugin_loader.c')
cli_plugin_args = ['-DWL_HAVE_PLUGIN_LOADER']
endif
#Build wirelog-cli executable (wirelog_cli_src defined in wirelog/meson.build)
#Include all wirelog sources to ensure proper linking with LTO
# Mobile builds do not ship the CLI: Android loads the library into a
# host process, and iOS uses the library/module surface rather than a
# command-line entry point.
if not mobile_cross
wirelog_cli = executable(
'wirelog_cli',
wirelog_cli_src,
cli_plugin_src,
wirelog_sources,
config_h_file,
include_directories: [wirelog_inc, wirelog_src_inc],
c_args: cli_plugin_args,
dependencies: [threads_dep, zlib_dep, nanoarrow_dep, xxhash_dep, mbedtls_dep, math_dep] + cli_plugin_deps,
install: true,
)
endif
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Benchmarks
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
if not mobile_cross
subdir('bench')
endif
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Tests
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
if tests_option and not mobile_cross
subdir('tests')
endif
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Examples
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
if not mobile_cross
# 04, 05 and 06 are golden-diff tests over wirelog_cli rather than their
# own executables; they run the committed .dl programs in a temporary tree.
subdir('examples/04-hash-functions')
subdir('examples/05-crc32-checksum')
subdir('examples/06-timestamp-lww')
subdir('examples/08-delta-queries')
subdir('examples/09-retraction-basics')
subdir('examples/10-recursive-under-update')
subdir('examples/11-time-evolution')
subdir('examples/12-snapshot-vs-delta')
subdir('examples/13-daemon-style')
endif
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Documentation
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
if docs_option
#Documentation build(optional, not yet implemented)
message('Documentation: enabled (not yet implemented)')
endif
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Git Hooks Setup
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
# Setup uncrustify pre-commit hook (optional, non-blocking)
python3 = find_program('python3', required: false)
if python3.found()
run_command(
python3,
'scripts/setup_uncrustify_hook.py',
check: false # Don't fail build if hook setup has issues
)
endif
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
#Summary
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
message('')
message('wirelog ' + project_version + ' Configuration:')
message(' Library: ' + wirelog_libdir)
message(' Headers: ' + wirelog_includedir / 'wirelog')
message(' Embedded mode: @0@'.format(is_embedded))
message(' IPC support: ' + ipc_option)
message(' Threading: ' + threads_option)
message(' Tests: @0@'.format(tests_option))
message('')
message('Git Hooks: uncrustify pre-commit hook configured')