From e01637fd3a0a59ffea320a7df9770e73f486c91e Mon Sep 17 00:00:00 2001 From: John Turner Date: Tue, 18 Nov 2025 22:43:22 +0000 Subject: [PATCH] setup meson to allow building multiple fuzzers easily --- Cargo.toml | 8 +-- fuzz/atom/meson.build | 1 + fuzz/{ => atom/parser}/fuzz.rs | 0 fuzz/{ => atom/parser}/gencorpus.rs | 0 fuzz/atom/parser/meson.build | 6 +++ fuzz/meson.build | 83 ++++++++++++++++++----------- 6 files changed, 62 insertions(+), 36 deletions(-) create mode 100644 fuzz/atom/meson.build rename fuzz/{ => atom/parser}/fuzz.rs (100%) rename fuzz/{ => atom/parser}/gencorpus.rs (100%) create mode 100644 fuzz/atom/parser/meson.build diff --git a/Cargo.toml b/Cargo.toml index 88fb826..0663f32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,9 @@ thiserror = "2.0.17" debug = true [[bin]] -path = "fuzz/gencorpus.rs" -name = "gencorpus" +path = "fuzz/atom/parser/gencorpus.rs" +name = "atom_parser_gencorpus" [[test]] -path = "fuzz/fuzz.rs" -name = "fuzz" \ No newline at end of file +path = "fuzz/atom/parser/fuzz.rs" +name = "atom_parser_fuzz" \ No newline at end of file diff --git a/fuzz/atom/meson.build b/fuzz/atom/meson.build new file mode 100644 index 0000000..57b0131 --- /dev/null +++ b/fuzz/atom/meson.build @@ -0,0 +1 @@ +subdir('parser') diff --git a/fuzz/fuzz.rs b/fuzz/atom/parser/fuzz.rs similarity index 100% rename from fuzz/fuzz.rs rename to fuzz/atom/parser/fuzz.rs diff --git a/fuzz/gencorpus.rs b/fuzz/atom/parser/gencorpus.rs similarity index 100% rename from fuzz/gencorpus.rs rename to fuzz/atom/parser/gencorpus.rs diff --git a/fuzz/atom/parser/meson.build b/fuzz/atom/parser/meson.build new file mode 100644 index 0000000..efc84c6 --- /dev/null +++ b/fuzz/atom/parser/meson.build @@ -0,0 +1,6 @@ +fuzzers += { + 'atom_parser': [ + meson.current_source_dir() / 'gencorpus.rs', + meson.current_source_dir() / 'fuzz.rs', + ], +} diff --git a/fuzz/meson.build b/fuzz/meson.build index c7652aa..1b61551 100644 --- a/fuzz/meson.build +++ b/fuzz/meson.build @@ -1,40 +1,59 @@ cbindgen = find_program('cbindgen') -gencorpus = executable( - 'gencorpus', - 'gencorpus.rs', - dependencies: [mon], - link_with: [gentoo_utils], -) +fuzzers = {} -corpus_directory = meson.current_build_dir() / 'corpus' +subdir('atom') -corpus = custom_target( - 'corpus', - output: 'corpus', - command: [gencorpus, corpus_directory], -) +foreach fuzzer, sources : fuzzers + gencorpus_rs = sources[0] + fuzz_rs = sources[1] -fuzz_h = custom_target( - 'fuzz_h', - input: 'fuzz.rs', - output: 'fuzz.h', - command: [cbindgen, '@INPUT@', '-o', '@OUTPUT'], -) + gencorpus = executable( + fuzzer + '_' + 'gencorpus', + gencorpus_rs, + dependencies: [mon], + link_with: [gentoo_utils], + ) -fuzz_rs = static_library( - 'fuzz_rs', - 'fuzz.rs', - rust_abi: 'c', - rust_args: [ - '-Cpasses=sancov-module', - '-Cllvm-args=-sanitizer-coverage-level=3', - '-Cllvm-args=-sanitizer-coverage-inline-8bit-counters', - ], - dependencies: [mon], - link_with: [gentoo_utils], -) + corpus_directory = fuzzer + '_' + 'corpus' -fuzz = executable('fuzz', link_args: ['-fsanitize=fuzzer'], link_with: [fuzz_rs]) + corpus = custom_target( + fuzzer + '_' + 'corpus', + output: fuzzer + '_' + 'corpus', + command: [gencorpus, corpus_directory], + ) -test('fuzz', fuzz, args: [corpus_directory], depends: [corpus], timeout: 0) + fuzz_h = custom_target( + fuzzer + '_' + 'fuzz_h', + input: fuzz_rs, + output: fuzzer + '_' + 'fuzz.h', + command: [cbindgen, '@INPUT@', '-o', '@OUTPUT'], + ) + + fuzz_rs = static_library( + fuzzer + '.rs', + fuzz_rs, + rust_abi: 'c', + rust_args: [ + '-Cpasses=sancov-module', + '-Cllvm-args=-sanitizer-coverage-level=3', + '-Cllvm-args=-sanitizer-coverage-inline-8bit-counters', + ], + dependencies: [mon], + link_with: [gentoo_utils], + ) + + fuzz = executable( + fuzzer + '_' + 'fuzzer', + link_args: ['-fsanitize=fuzzer'], + link_with: [fuzz_rs], + ) + + test( + fuzzer + '_' + 'fuzz', + fuzz, + args: [corpus_directory], + depends: [corpus], + timeout: 0, + ) +endforeach