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 | |
Wyatt Hepler | b93749b | 2021-05-11 09:38:22 -0700 | [diff] [blame] | 22 | config("public_include_path") { |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 23 | include_dirs = [ "public" ] |
Wyatt Hepler | b93749b | 2021-05-11 09:38:22 -0700 | [diff] [blame] | 24 | visibility = [ ":*" ] |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 27 | # This is added automatically by the `pw_fuzzer` template. |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 28 | config("fuzzing") { |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 29 | common_flags = [ "-fsanitize=fuzzer" ] |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 30 | cflags = common_flags |
| 31 | ldflags = common_flags |
| 32 | } |
| 33 | |
Aaron Green | b3ae1dc | 2020-04-13 11:37:05 -0700 | [diff] [blame] | 34 | # OSS-Fuzz needs to be able to specify its own compilers and add flags. |
| 35 | config("oss_fuzz") { |
| 36 | # OSS-Fuzz doesn't always link with -fsanitize=fuzzer, sometimes it uses |
| 37 | #-fsanitize=fuzzer-no-link and provides the fuzzing engine explicitly to be |
| 38 | # passed to the linker. |
| 39 | ldflags = [ getenv("LIB_FUZZING_ENGINE") ] |
| 40 | } |
| 41 | |
Alexei Frolov | 844ff0f | 2020-05-06 12:15:29 -0700 | [diff] [blame] | 42 | config("oss_fuzz_extra") { |
| 43 | cflags_c = oss_fuzz_extra_cflags_c |
| 44 | cflags_cc = oss_fuzz_extra_cflags_cc |
| 45 | ldflags = oss_fuzz_extra_ldflags |
| 46 | } |
| 47 | |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame] | 48 | pw_source_set("pw_fuzzer") { |
Wyatt Hepler | b93749b | 2021-05-11 09:38:22 -0700 | [diff] [blame] | 49 | public_configs = [ ":public_include_path" ] |
Aaron Green | 0ce7f41 | 2020-04-06 13:39:40 -0700 | [diff] [blame] | 50 | public = [ |
| 51 | "public/pw_fuzzer/asan_interface.h", |
| 52 | "public/pw_fuzzer/fuzzed_data_provider.h", |
| 53 | ] |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 54 | public_deps = [ "$dir_pw_log" ] |
| 55 | } |
| 56 | |
Alexei Frolov | f39fbf4 | 2020-09-08 14:41:53 -0700 | [diff] [blame] | 57 | pw_source_set("run_as_unit_test") { |
Wyatt Hepler | b93749b | 2021-05-11 09:38:22 -0700 | [diff] [blame] | 58 | configs = [ ":public_include_path" ] |
Wyatt Hepler | c5e511e | 2020-06-12 16:56:22 -0700 | [diff] [blame] | 59 | sources = [ "pw_fuzzer_disabled.cc" ] |
| 60 | deps = [ |
| 61 | dir_pw_log, |
| 62 | dir_pw_unit_test, |
| 63 | ] |
| 64 | } |
| 65 | |
Aaron Green | 33c6782 | 2020-04-06 13:47:38 -0700 | [diff] [blame] | 66 | # See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode |
| 67 | config("fuzzing_build_mode_unsafe_for_production") { |
| 68 | defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ] |
| 69 | } |
| 70 | |
| 71 | config("fuzzing_verbose_logging") { |
| 72 | defines = [ "FUZZING_VERBOSE_LOGGING" ] |
| 73 | } |
| 74 | |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 75 | pw_doc_group("docs") { |
| 76 | inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ] |
| 77 | sources = [ "docs.rst" ] |
| 78 | } |
| 79 | |
| 80 | # Sample fuzzer |
| 81 | pw_fuzzer("toy_fuzzer") { |
| 82 | sources = [ "examples/toy_fuzzer.cc" ] |
Ewout van Bekkum | f89f137 | 2021-05-03 11:15:54 -0700 | [diff] [blame] | 83 | deps = [ |
| 84 | "$dir_pw_result", |
| 85 | "$dir_pw_string", |
| 86 | ] |
Aaron Green | f3c3d2b | 2020-04-02 23:12:31 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | pw_test_group("tests") { |
| 90 | tests = [ ":toy_fuzzer" ] |
| 91 | } |