Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 1 | # 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 Montanez | fb3d3fb | 2020-06-09 18:12:12 -0700 | [diff] [blame] | 15 | import("//build_overrides/pigweed.gni") |
| 16 | |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame] | 17 | import("$dir_pw_build/target_types.gni") |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 18 | import("$dir_pw_docgen/docs.gni") |
| 19 | import("$dir_pw_fuzzer/fuzzer.gni") |
Alexei Frolov | 844ff0f | 2020-05-06 12:15:29 -0700 | [diff] [blame] | 20 | import("$dir_pw_fuzzer/oss_fuzz.gni") |
Wyatt Hepler | d49f8fe | 2020-10-15 10:13:47 -0700 | [diff] [blame^] | 21 | |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 22 | config("default_config") { |
| 23 | include_dirs = [ "public" ] |
| 24 | } |
| 25 | |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 26 | # This is added automatically by the `pw_fuzzer` template. |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 27 | config("fuzzing") { |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 28 | common_flags = [ "-fsanitize=fuzzer" ] |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 29 | cflags = common_flags |
| 30 | ldflags = common_flags |
| 31 | } |
| 32 | |
Aaron Green | b3ae1dc | 2020-04-13 11:37:05 -0700 | [diff] [blame] | 33 | config("sanitize_address") { |
| 34 | cflags = [ "-fsanitize=address" ] |
| 35 | ldflags = cflags |
| 36 | } |
| 37 | |
| 38 | config("sanitize_memory") { |
| 39 | cflags = [ "-fsanitize=memory" ] |
| 40 | ldflags = cflags |
| 41 | } |
| 42 | |
| 43 | config("sanitize_undefined") { |
| 44 | cflags = [ "-fsanitize=undefined" ] |
| 45 | ldflags = cflags |
| 46 | } |
| 47 | |
Aaron Green | 7d79f37 | 2020-04-16 08:16:46 -0700 | [diff] [blame] | 48 | config("sanitize_coverage") { |
| 49 | cflags = [ |
| 50 | "-fprofile-instr-generate", |
| 51 | "-fcoverage-mapping", |
| 52 | ] |
| 53 | ldflags = cflags |
| 54 | } |
| 55 | |
Aaron Green | b3ae1dc | 2020-04-13 11:37:05 -0700 | [diff] [blame] | 56 | # OSS-Fuzz needs to be able to specify its own compilers and add flags. |
| 57 | config("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 Frolov | 844ff0f | 2020-05-06 12:15:29 -0700 | [diff] [blame] | 64 | config("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 Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame] | 70 | pw_source_set("pw_fuzzer") { |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 71 | public_configs = [ ":default_config" ] |
Aaron Green | 0ce7f41 | 2020-04-06 13:39:40 -0700 | [diff] [blame] | 72 | public = [ |
| 73 | "public/pw_fuzzer/asan_interface.h", |
| 74 | "public/pw_fuzzer/fuzzed_data_provider.h", |
| 75 | ] |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 76 | public_deps = [ "$dir_pw_log" ] |
| 77 | } |
| 78 | |
Alexei Frolov | f39fbf4 | 2020-09-08 14:41:53 -0700 | [diff] [blame] | 79 | pw_source_set("run_as_unit_test") { |
Wyatt Hepler | c5e511e | 2020-06-12 16:56:22 -0700 | [diff] [blame] | 80 | configs = [ ":default_config" ] |
| 81 | sources = [ "pw_fuzzer_disabled.cc" ] |
| 82 | deps = [ |
| 83 | dir_pw_log, |
| 84 | dir_pw_unit_test, |
| 85 | ] |
| 86 | } |
| 87 | |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 88 | # See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode |
| 89 | config("fuzzing_build_mode_unsafe_for_production") { |
| 90 | defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ] |
| 91 | } |
| 92 | |
| 93 | config("fuzzing_verbose_logging") { |
| 94 | defines = [ "FUZZING_VERBOSE_LOGGING" ] |
| 95 | } |
| 96 | |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 97 | pw_doc_group("docs") { |
| 98 | inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ] |
| 99 | sources = [ "docs.rst" ] |
| 100 | } |
| 101 | |
| 102 | # Sample fuzzer |
| 103 | pw_fuzzer("toy_fuzzer") { |
| 104 | sources = [ "examples/toy_fuzzer.cc" ] |
| 105 | deps = [ "$dir_pw_string" ] |
| 106 | } |
| 107 | |
| 108 | pw_test_group("tests") { |
| 109 | tests = [ ":toy_fuzzer" ] |
| 110 | } |