blob: 4db52473cf0904b6a40078b675f5c7c72cef63af [file] [log] [blame]
Aaron Greenf3c3d2b2020-04-02 23:12:31 -07001# 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
Alexei Frolovedd2f142020-06-09 19:11:27 -070015import("$dir_pw_build/target_types.gni")
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070016import("$dir_pw_docgen/docs.gni")
17import("$dir_pw_fuzzer/fuzzer.gni")
Alexei Frolov844ff0f2020-05-06 12:15:29 -070018import("$dir_pw_fuzzer/oss_fuzz.gni")
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070019
Aaron Green33c67822020-04-06 13:47:38 -070020config("default_config") {
21 include_dirs = [ "public" ]
22}
23
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070024# This is added automatically by the `pw_fuzzer` template.
Aaron Green33c67822020-04-06 13:47:38 -070025config("fuzzing") {
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070026 common_flags = [ "-fsanitize=fuzzer" ]
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070027 cflags = common_flags
28 ldflags = common_flags
29}
30
Aaron Greenb3ae1dc2020-04-13 11:37:05 -070031config("sanitize_address") {
32 cflags = [ "-fsanitize=address" ]
33 ldflags = cflags
34}
35
36config("sanitize_memory") {
37 cflags = [ "-fsanitize=memory" ]
38 ldflags = cflags
39}
40
41config("sanitize_undefined") {
42 cflags = [ "-fsanitize=undefined" ]
43 ldflags = cflags
44}
45
Aaron Green7d79f372020-04-16 08:16:46 -070046config("sanitize_coverage") {
47 cflags = [
48 "-fprofile-instr-generate",
49 "-fcoverage-mapping",
50 ]
51 ldflags = cflags
52}
53
Aaron Greenb3ae1dc2020-04-13 11:37:05 -070054# OSS-Fuzz needs to be able to specify its own compilers and add flags.
55config("oss_fuzz") {
56 # OSS-Fuzz doesn't always link with -fsanitize=fuzzer, sometimes it uses
57 #-fsanitize=fuzzer-no-link and provides the fuzzing engine explicitly to be
58 # passed to the linker.
59 ldflags = [ getenv("LIB_FUZZING_ENGINE") ]
60}
61
Alexei Frolov844ff0f2020-05-06 12:15:29 -070062config("oss_fuzz_extra") {
63 cflags_c = oss_fuzz_extra_cflags_c
64 cflags_cc = oss_fuzz_extra_cflags_cc
65 ldflags = oss_fuzz_extra_ldflags
66}
67
Alexei Frolovedd2f142020-06-09 19:11:27 -070068pw_source_set("pw_fuzzer") {
Aaron Green33c67822020-04-06 13:47:38 -070069 public_configs = [ ":default_config" ]
Aaron Green0ce7f412020-04-06 13:39:40 -070070 public = [
71 "public/pw_fuzzer/asan_interface.h",
72 "public/pw_fuzzer/fuzzed_data_provider.h",
73 ]
Aaron Green33c67822020-04-06 13:47:38 -070074 sources = public
75 public_deps = [ "$dir_pw_log" ]
76}
77
78# See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode
79config("fuzzing_build_mode_unsafe_for_production") {
80 defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ]
81}
82
83config("fuzzing_verbose_logging") {
84 defines = [ "FUZZING_VERBOSE_LOGGING" ]
85}
86
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070087pw_doc_group("docs") {
88 inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ]
89 sources = [ "docs.rst" ]
90}
91
92# Sample fuzzer
93pw_fuzzer("toy_fuzzer") {
94 sources = [ "examples/toy_fuzzer.cc" ]
95 deps = [ "$dir_pw_string" ]
96}
97
98pw_test_group("tests") {
99 tests = [ ":toy_fuzzer" ]
100}