blob: 346660adf4b61979db3eb1a6b00bf3408ca115ef [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")
17
Aaron Green33c67822020-04-06 13:47:38 -070018config("default_config") {
19 include_dirs = [ "public" ]
20}
21
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070022# This is added automatically by the `pw_fuzzer` template.
Aaron Green33c67822020-04-06 13:47:38 -070023config("fuzzing") {
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070024 common_flags = [ "-fsanitize=fuzzer" ]
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070025 cflags = common_flags
26 ldflags = common_flags
27}
28
Aaron Greenb3ae1dc2020-04-13 11:37:05 -070029config("sanitize_address") {
30 cflags = [ "-fsanitize=address" ]
31 ldflags = cflags
32}
33
34config("sanitize_memory") {
35 cflags = [ "-fsanitize=memory" ]
36 ldflags = cflags
37}
38
39config("sanitize_undefined") {
40 cflags = [ "-fsanitize=undefined" ]
41 ldflags = cflags
42}
43
44# OSS-Fuzz needs to be able to specify its own compilers and add flags.
45config("oss_fuzz") {
46 # OSS-Fuzz doesn't always link with -fsanitize=fuzzer, sometimes it uses
47 #-fsanitize=fuzzer-no-link and provides the fuzzing engine explicitly to be
48 # passed to the linker.
49 ldflags = [ getenv("LIB_FUZZING_ENGINE") ]
50}
51
Aaron Green33c67822020-04-06 13:47:38 -070052source_set("pw_fuzzer") {
53 public_configs = [ ":default_config" ]
Aaron Green0ce7f412020-04-06 13:39:40 -070054 public = [
55 "public/pw_fuzzer/asan_interface.h",
56 "public/pw_fuzzer/fuzzed_data_provider.h",
57 ]
Aaron Green33c67822020-04-06 13:47:38 -070058 sources = public
59 public_deps = [ "$dir_pw_log" ]
60}
61
62# See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode
63config("fuzzing_build_mode_unsafe_for_production") {
64 defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ]
65}
66
67config("fuzzing_verbose_logging") {
68 defines = [ "FUZZING_VERBOSE_LOGGING" ]
69}
70
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070071pw_doc_group("docs") {
72 inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ]
73 sources = [ "docs.rst" ]
74}
75
76# Sample fuzzer
77pw_fuzzer("toy_fuzzer") {
78 sources = [ "examples/toy_fuzzer.cc" ]
79 deps = [ "$dir_pw_string" ]
80}
81
82pw_test_group("tests") {
83 tests = [ ":toy_fuzzer" ]
84}