blob: 264033b0004bfcb4653ca1c0df41be8037d99da6 [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 -070015import("//build_overrides/pigweed.gni")
16
Alexei Frolovedd2f142020-06-09 19:11:27 -070017import("$dir_pw_build/target_types.gni")
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070018import("$dir_pw_docgen/docs.gni")
19import("$dir_pw_fuzzer/fuzzer.gni")
Alexei Frolov844ff0f2020-05-06 12:15:29 -070020import("$dir_pw_fuzzer/oss_fuzz.gni")
Wyatt Heplerd49f8fe2020-10-15 10:13:47 -070021
Aaron Green33c67822020-04-06 13:47:38 -070022config("default_config") {
23 include_dirs = [ "public" ]
24}
25
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070026# This is added automatically by the `pw_fuzzer` template.
Aaron Green33c67822020-04-06 13:47:38 -070027config("fuzzing") {
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070028 common_flags = [ "-fsanitize=fuzzer" ]
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070029 cflags = common_flags
30 ldflags = common_flags
31}
32
Aaron Greenb3ae1dc2020-04-13 11:37:05 -070033config("sanitize_address") {
34 cflags = [ "-fsanitize=address" ]
35 ldflags = cflags
36}
37
38config("sanitize_memory") {
39 cflags = [ "-fsanitize=memory" ]
40 ldflags = cflags
41}
42
43config("sanitize_undefined") {
44 cflags = [ "-fsanitize=undefined" ]
45 ldflags = cflags
46}
47
Aaron Green7d79f372020-04-16 08:16:46 -070048config("sanitize_coverage") {
49 cflags = [
50 "-fprofile-instr-generate",
51 "-fcoverage-mapping",
52 ]
53 ldflags = cflags
54}
55
Aaron Greenb3ae1dc2020-04-13 11:37:05 -070056# OSS-Fuzz needs to be able to specify its own compilers and add flags.
57config("oss_fuzz") {
58 # OSS-Fuzz doesn't always link with -fsanitize=fuzzer, sometimes it uses
59 #-fsanitize=fuzzer-no-link and provides the fuzzing engine explicitly to be
60 # passed to the linker.
61 ldflags = [ getenv("LIB_FUZZING_ENGINE") ]
62}
63
Alexei Frolov844ff0f2020-05-06 12:15:29 -070064config("oss_fuzz_extra") {
65 cflags_c = oss_fuzz_extra_cflags_c
66 cflags_cc = oss_fuzz_extra_cflags_cc
67 ldflags = oss_fuzz_extra_ldflags
68}
69
Alexei Frolovedd2f142020-06-09 19:11:27 -070070pw_source_set("pw_fuzzer") {
Aaron Green33c67822020-04-06 13:47:38 -070071 public_configs = [ ":default_config" ]
Aaron Green0ce7f412020-04-06 13:39:40 -070072 public = [
73 "public/pw_fuzzer/asan_interface.h",
74 "public/pw_fuzzer/fuzzed_data_provider.h",
75 ]
Aaron Green33c67822020-04-06 13:47:38 -070076 public_deps = [ "$dir_pw_log" ]
77}
78
Alexei Frolovf39fbf42020-09-08 14:41:53 -070079pw_source_set("run_as_unit_test") {
Wyatt Heplerc5e511e2020-06-12 16:56:22 -070080 configs = [ ":default_config" ]
81 sources = [ "pw_fuzzer_disabled.cc" ]
82 deps = [
83 dir_pw_log,
84 dir_pw_unit_test,
85 ]
86}
87
Aaron Green33c67822020-04-06 13:47:38 -070088# See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode
89config("fuzzing_build_mode_unsafe_for_production") {
90 defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ]
91}
92
93config("fuzzing_verbose_logging") {
94 defines = [ "FUZZING_VERBOSE_LOGGING" ]
95}
96
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070097pw_doc_group("docs") {
98 inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ]
99 sources = [ "docs.rst" ]
100}
101
102# Sample fuzzer
103pw_fuzzer("toy_fuzzer") {
104 sources = [ "examples/toy_fuzzer.cc" ]
105 deps = [ "$dir_pw_string" ]
106}
107
108pw_test_group("tests") {
109 tests = [ ":toy_fuzzer" ]
110}