1# Copyright 2020 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pw_build/target_types.gni") 18import("$dir_pw_docgen/docs.gni") 19import("$dir_pw_fuzzer/fuzzer.gni") 20import("$dir_pw_fuzzer/oss_fuzz.gni") 21 22config("default_config") { 23 include_dirs = [ "public" ] 24} 25 26# This is added automatically by the `pw_fuzzer` template. 27config("fuzzing") { 28 common_flags = [ "-fsanitize=fuzzer" ] 29 cflags = common_flags 30 ldflags = common_flags 31} 32 33# OSS-Fuzz needs to be able to specify its own compilers and add flags. 34config("oss_fuzz") { 35 # OSS-Fuzz doesn't always link with -fsanitize=fuzzer, sometimes it uses 36 #-fsanitize=fuzzer-no-link and provides the fuzzing engine explicitly to be 37 # passed to the linker. 38 ldflags = [ getenv("LIB_FUZZING_ENGINE") ] 39} 40 41config("oss_fuzz_extra") { 42 cflags_c = oss_fuzz_extra_cflags_c 43 cflags_cc = oss_fuzz_extra_cflags_cc 44 ldflags = oss_fuzz_extra_ldflags 45} 46 47pw_source_set("pw_fuzzer") { 48 public_configs = [ ":default_config" ] 49 public = [ 50 "public/pw_fuzzer/asan_interface.h", 51 "public/pw_fuzzer/fuzzed_data_provider.h", 52 ] 53 public_deps = [ "$dir_pw_log" ] 54} 55 56pw_source_set("run_as_unit_test") { 57 configs = [ ":default_config" ] 58 sources = [ "pw_fuzzer_disabled.cc" ] 59 deps = [ 60 dir_pw_log, 61 dir_pw_unit_test, 62 ] 63} 64 65# See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode 66config("fuzzing_build_mode_unsafe_for_production") { 67 defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ] 68} 69 70config("fuzzing_verbose_logging") { 71 defines = [ "FUZZING_VERBOSE_LOGGING" ] 72} 73 74pw_doc_group("docs") { 75 inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ] 76 sources = [ "docs.rst" ] 77} 78 79# Sample fuzzer 80pw_fuzzer("toy_fuzzer") { 81 sources = [ "examples/toy_fuzzer.cc" ] 82 deps = [ "$dir_pw_string" ] 83} 84 85pw_test_group("tests") { 86 tests = [ ":toy_fuzzer" ] 87} 88