Skip to content

Commit 96cab23

Browse files
authored
Merge pull request #193 from keszybz/fuzz
oss-fuzz hookup
2 parents 5738346 + fd031d8 commit 96cab23

File tree

16 files changed

+475
-191
lines changed

16 files changed

+475
-191
lines changed

meson.build

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ project('casync', 'c',
88
'prefix=/usr',
99
'sysconfdir=/etc',
1010
'localstatedir=/var',
11+
'auto_features=enabled',
1112
],
12-
meson_version : '>= 0.40')
13+
meson_version : '>= 0.47')
1314

1415
cc = meson.get_compiler('c')
1516

@@ -62,6 +63,15 @@ foreach arg : c_args
6263
endif
6364
endforeach
6465

66+
want_ossfuzz = get_option('oss-fuzz')
67+
want_libfuzzer = get_option('llvm-fuzz')
68+
if want_ossfuzz and want_libfuzzer
69+
error('only one of oss-fuzz and llvm-fuzz can be specified')
70+
endif
71+
fuzzer_build = want_ossfuzz or want_libfuzzer
72+
73+
add_languages('cpp', required : fuzzer_build)
74+
6575
conf = configuration_data()
6676
conf.set_quoted('PACKAGE_VERSION', meson.project_version())
6777

@@ -101,18 +111,27 @@ docdir = join_paths(datadir, 'doc/casync')
101111
protocoldir = join_paths(prefixdir, 'lib/casync/protocols')
102112
conf.set_quoted('CASYNC_PROTOCOL_PATH', protocoldir)
103113

104-
liblzma = dependency('liblzma',
105-
version : '>= 5.1.0')
114+
liblzma = dependency(
115+
'liblzma',
116+
version : '>= 5.1.0',
117+
required : get_option('liblzma'))
118+
conf.set10('HAVE_LIBLZMA', liblzma.found())
119+
120+
libz = dependency(
121+
'zlib',
122+
required : get_option('libz'))
123+
conf.set10('HAVE_LIBZ', libz.found())
124+
125+
libzstd = dependency(
126+
'libzstd',
127+
version : '>= 0.8.1',
128+
required : get_option('libzstd'))
129+
conf.set10('HAVE_LIBZSTD', libzstd.found())
130+
106131
libcurl = dependency('libcurl',
107132
version : '>= 7.29.0')
108133
openssl = dependency('openssl',
109134
version : '>= 1.0')
110-
111-
libz = dependency('zlib')
112-
113-
libzstd = dependency('libzstd',
114-
version : '>= 0.8.1')
115-
116135
libacl = cc.find_library('acl')
117136

118137
if get_option('fuse')
@@ -140,6 +159,12 @@ conf.set10('HAVE_UDEV', get_option('udev'))
140159
threads = dependency('threads')
141160
math = cc.find_library('m')
142161

162+
if want_libfuzzer
163+
fuzzing_engine = meson.get_compiler('cpp').find_library('Fuzzer')
164+
elif want_ossfuzz
165+
fuzzing_engine = meson.get_compiler('cpp').find_library('FuzzingEngine')
166+
endif
167+
143168
config_h = configure_file(
144169
output : 'config.h',
145170
configuration : conf)
@@ -227,6 +252,9 @@ substs = configuration_data()
227252
substs.set_quoted('top_builddir', meson.build_root())
228253
substs.set_quoted('top_srcdir', meson.source_root())
229254
substs.set('bindir_unquoted', bindir)
255+
substs.set10('HAVE_LIBLZMA', liblzma.found())
256+
substs.set10('HAVE_LIBZ', libz.found())
257+
substs.set10('HAVE_LIBZSTD', libzstd.found())
230258

231259
test_script_sh = configure_file(
232260
output : 'test-script.sh',
@@ -315,28 +343,57 @@ non_test_sources = '''
315343
test-calc-digest
316344
'''.split()
317345

346+
test_dependencies = [
347+
libacl,
348+
liblzma,
349+
libselinux,
350+
libz,
351+
libzstd,
352+
math,
353+
openssl,
354+
threads]
355+
318356
foreach test_name : test_sources + non_test_sources
319357
exe = executable(
320358
test_name,
321359
'test/@[email protected]'.format(test_name),
322-
link_with : libshared,
323360
include_directories : includes,
324-
dependencies : [
325-
libacl,
326-
liblzma,
327-
libselinux,
328-
libz,
329-
libzstd,
330-
math,
331-
openssl,
332-
threads])
361+
link_with : libshared,
362+
dependencies : test_dependencies)
333363

334364
if test_sources.contains(test_name)
335365
test(test_name, exe,
336366
timeout : 3 * 60)
337367
endif
338368
endforeach
339369

370+
fuzzer_exes = []
371+
372+
foreach tuple : fuzzers
373+
sources = tuple[0]
374+
375+
deps = test_dependencies
376+
if fuzzer_build
377+
deps += fuzzing_engine
378+
else
379+
sources += fuzz_main_c
380+
endif
381+
382+
name = sources[0].split('/')[-1].split('.')[0]
383+
384+
fuzzer_exes += executable(
385+
name,
386+
sources,
387+
include_directories : [includes, include_directories('test/fuzz')],
388+
link_with : libshared,
389+
dependencies : deps,
390+
install : false)
391+
endforeach
392+
393+
run_target('fuzzers',
394+
depends : fuzzer_exes,
395+
command : ['true'])
396+
340397
############################################################
341398

342399
meson_check_help = find_program('test/meson-check-help.sh')

meson_options.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ option('udevrulesdir', type : 'string', value: '',
1111
description: 'Path where udev rules are installed to (Defaults to udevdir specified in udev.pc)')
1212
option('man', type : 'boolean', value : true,
1313
description : 'build and install man pages (requires sphinx-build')
14+
option('libzstd', type : 'feature',
15+
description : 'link to libzstd')
16+
option('liblzma', type : 'feature',
17+
description : 'link to liblzma (for XZ compression)')
18+
option('libz', type : 'feature',
19+
description : 'link to zlib')
20+
21+
option('oss-fuzz', type : 'boolean', value : 'false',
22+
description : 'build against oss-fuzz')
23+
option('llvm-fuzz', type : 'boolean', value : 'false',
24+
description : 'build against LLVM libFuzzer')

0 commit comments

Comments
 (0)