Skip to content

Commit 1adfddf

Browse files
committed
clusterfuzzlite: update build to optionally build fuzzers
1 parent f989678 commit 1adfddf

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

.clusterfuzzlite/build.sh

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
11
#!/bin/bash -eu
22

3-
# Build libcss and dependencies
3+
# Install additional dependencies if needed (ClusterFuzzLite base has most, but ensure)
4+
apt-get update && apt-get install -y meson ninja-build python3 clang llvm
5+
6+
# Do NOT override CFLAGS/CXXFLAGS/LDFLAGS here, as ClusterFuzzLite already sets appropriate flags
7+
# like -fsanitize=address,undefined,fuzzer-no-link for compilation.
8+
# Overriding causes conflicts (e.g., duplicate/mismatched sanitizer flags) that break Meson's compiler check.
9+
10+
# Set CC and CXX to clang if not already (ClusterFuzzLite usually does this)
11+
export CC="${CC:-clang}"
12+
export CXX="${CXX:-clang++}"
13+
14+
# Build dependencies if not subprojects (assuming wrap files handle them)
415
cd $SRC/libcss
5-
rm -rf build || true # Wipe old build dir if it exists, ignore if not
6-
mkdir -p build
7-
cd build
8-
meson setup .. --default-library=static
9-
ninja -j$(nproc)
10-
ninja install
11-
cd ../..
12-
13-
14-
# Set executable permissions for fuzzer build scripts
15-
chmod +x $SRC/libcss/test/fuzzers/build_google_oss_fuzzers.sh
16-
chmod +x $SRC/libcss/test/fuzzers/build_seed_corpus.sh
17-
18-
# Build fuzzers and seed corpus
19-
$SRC/libcss/test/fuzzers/build_google_oss_fuzzers.sh
20-
$SRC/libcss/test/fuzzers/build_seed_corpus.sh
16+
meson subprojects update || true # If using subprojects/wraps for libwapcaplet, libparserutils
17+
18+
# Clean and setup Meson with fuzzing enabled
19+
rm -rf build || true
20+
meson setup build \
21+
--default-library=static \
22+
--buildtype=plain \
23+
-Db_sanitize=none \
24+
-Db_lundef=false \
25+
-Dfuzzing=true
26+
27+
# Build
28+
ninja -C build -j$(nproc)
29+
30+
# Install if needed (but for fuzzing, probably not necessary since static)
31+
ninja -C build install || true
32+
33+
# Copy the fuzzer binary to $OUT
34+
cp build/css_parse_fuzzer $OUT/
35+
36+
# Optional: Build seed corpus (zip test data or examples)
37+
mkdir -p css_parse_fuzzer_seed_corpus
38+
# Add some seed files, e.g., from test data
39+
cp -r test/data/* css_parse_fuzzer_seed_corpus/ || true # Adjust path to your test CSS files
40+
zip -r $OUT/css_parse_fuzzer_seed_corpus.zip css_parse_fuzzer_seed_corpus || true
41+
42+
# If you have multiple fuzzers, repeat cp and seed steps

meson.build

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project('libcss', 'c',
1+
project('libcss', ['c', 'cpp'],
22
version: '0.9.2',
33
default_options: ['c_std=c99', 'warning_level=2'])
44

@@ -395,4 +395,22 @@ if get_option('tests')
395395
)
396396
endif
397397
endforeach
398+
endif
399+
400+
401+
# Fuzzing option (enable with -Dfuzzing=true)
402+
if get_option('fuzzing')
403+
# Assume Clang is used for libFuzzer
404+
fuzz_c_args = ['-fsanitize=fuzzer,address,undefined', '-fno-omit-frame-pointer', '-g', '-O1']
405+
fuzz_link_args = ['-fsanitize=fuzzer,address,undefined']
406+
407+
executable('css_parse_fuzzer',
408+
sources: 'test/fuzzers/css_parse_fuzzer.cc',
409+
include_directories: inc,
410+
c_args: [cflags, fuzz_c_args],
411+
link_args: fuzz_link_args,
412+
dependencies: [parserutils_dep, wapcaplet_dep],
413+
link_with: libcss_lib,
414+
install: false
415+
)
398416
endif

meson_options.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
option('tests', type: 'boolean', value: false, description: 'Enable test suite')
1+
option('tests', type: 'boolean', value: false, description: 'Enable test suite')
2+
option('fuzzing', type: 'boolean', value: false, description: 'Enable fuzzer build')

0 commit comments

Comments
 (0)