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