blob: 4d8d4ec4b04c6ab5420da92a8d1e873bf966e2ac [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
Armando Montanezfb3d3fb2020-06-09 18:12:12 -070015# gn-format disable
16import("//build_overrides/pigweed.gni")
17
18import("$dir_pigweed/legacy_target.gni")
Alexei Frolovedd2f142020-06-09 19:11:27 -070019import("$dir_pw_build/target_types.gni")
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070020import("$dir_pw_docgen/docs.gni")
21import("$dir_pw_fuzzer/fuzzer.gni")
Alexei Frolov844ff0f2020-05-06 12:15:29 -070022import("$dir_pw_fuzzer/oss_fuzz.gni")
Aaron Green33c67822020-04-06 13:47:38 -070023config("default_config") {
24 include_dirs = [ "public" ]
25}
26
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070027# This is added automatically by the `pw_fuzzer` template.
Aaron Green33c67822020-04-06 13:47:38 -070028config("fuzzing") {
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070029 common_flags = [ "-fsanitize=fuzzer" ]
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070030 cflags = common_flags
31 ldflags = common_flags
32}
33
Aaron Greenb3ae1dc2020-04-13 11:37:05 -070034config("sanitize_address") {
35 cflags = [ "-fsanitize=address" ]
36 ldflags = cflags
37}
38
39config("sanitize_memory") {
40 cflags = [ "-fsanitize=memory" ]
41 ldflags = cflags
42}
43
44config("sanitize_undefined") {
45 cflags = [ "-fsanitize=undefined" ]
46 ldflags = cflags
47}
48
Aaron Green7d79f372020-04-16 08:16:46 -070049config("sanitize_coverage") {
50 cflags = [
51 "-fprofile-instr-generate",
52 "-fcoverage-mapping",
53 ]
54 ldflags = cflags
55}
56
Aaron Greenb3ae1dc2020-04-13 11:37:05 -070057# OSS-Fuzz needs to be able to specify its own compilers and add flags.
58config("oss_fuzz") {
59 # OSS-Fuzz doesn't always link with -fsanitize=fuzzer, sometimes it uses
60 #-fsanitize=fuzzer-no-link and provides the fuzzing engine explicitly to be
61 # passed to the linker.
62 ldflags = [ getenv("LIB_FUZZING_ENGINE") ]
63}
64
Alexei Frolov844ff0f2020-05-06 12:15:29 -070065config("oss_fuzz_extra") {
66 cflags_c = oss_fuzz_extra_cflags_c
67 cflags_cc = oss_fuzz_extra_cflags_cc
68 ldflags = oss_fuzz_extra_ldflags
69}
70
Alexei Frolovedd2f142020-06-09 19:11:27 -070071pw_source_set("pw_fuzzer") {
Aaron Green33c67822020-04-06 13:47:38 -070072 public_configs = [ ":default_config" ]
Aaron Green0ce7f412020-04-06 13:39:40 -070073 public = [
74 "public/pw_fuzzer/asan_interface.h",
75 "public/pw_fuzzer/fuzzed_data_provider.h",
76 ]
Aaron Green33c67822020-04-06 13:47:38 -070077 sources = public
78 public_deps = [ "$dir_pw_log" ]
79}
80
81# See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode
82config("fuzzing_build_mode_unsafe_for_production") {
83 defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ]
84}
85
86config("fuzzing_verbose_logging") {
87 defines = [ "FUZZING_VERBOSE_LOGGING" ]
88}
89
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070090pw_doc_group("docs") {
91 inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ]
92 sources = [ "docs.rst" ]
93}
94
95# Sample fuzzer
96pw_fuzzer("toy_fuzzer") {
97 sources = [ "examples/toy_fuzzer.cc" ]
98 deps = [ "$dir_pw_string" ]
99}
100
101pw_test_group("tests") {
102 tests = [ ":toy_fuzzer" ]
103}