blob: 61271c3a5d040d14422411c107a2e5eb4ffd6e7d [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
Alexei Frolovedd2f142020-06-09 19:11:27 -070018import("$dir_pw_build/target_types.gni")
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070019import("$dir_pw_docgen/docs.gni")
20import("$dir_pw_fuzzer/fuzzer.gni")
Alexei Frolov844ff0f2020-05-06 12:15:29 -070021import("$dir_pw_fuzzer/oss_fuzz.gni")
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 sources = public
77 public_deps = [ "$dir_pw_log" ]
78}
79
Wyatt Heplerc5e511e2020-06-12 16:56:22 -070080source_set("run_as_unit_test") {
81 configs = [ ":default_config" ]
82 sources = [ "pw_fuzzer_disabled.cc" ]
83 deps = [
84 dir_pw_log,
85 dir_pw_unit_test,
86 ]
87}
88
Aaron Green33c67822020-04-06 13:47:38 -070089# See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode
90config("fuzzing_build_mode_unsafe_for_production") {
91 defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ]
92}
93
94config("fuzzing_verbose_logging") {
95 defines = [ "FUZZING_VERBOSE_LOGGING" ]
96}
97
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070098pw_doc_group("docs") {
99 inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ]
100 sources = [ "docs.rst" ]
101}
102
103# Sample fuzzer
104pw_fuzzer("toy_fuzzer") {
105 sources = [ "examples/toy_fuzzer.cc" ]
106 deps = [ "$dir_pw_string" ]
107}
108
109pw_test_group("tests") {
110 tests = [ ":toy_fuzzer" ]
111}