blob: 91cbd0884b67adeb6b0d2ddae0b613a406079372 [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
Wyatt Heplerb93749b2021-05-11 09:38:22 -070022config("public_include_path") {
Aaron Green33c67822020-04-06 13:47:38 -070023 include_dirs = [ "public" ]
Wyatt Heplerb93749b2021-05-11 09:38:22 -070024 visibility = [ ":*" ]
Aaron Green33c67822020-04-06 13:47:38 -070025}
26
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070027# This is added automatically by the `pw_fuzzer` template.
Aaron Green33c67822020-04-06 13:47:38 -070028config("fuzzing") {
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070029 common_flags = [ "-fsanitize=fuzzer" ]
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070030 cflags = common_flags
31 ldflags = common_flags
32}
33
Aaron Greenb3ae1dc2020-04-13 11:37:05 -070034# OSS-Fuzz needs to be able to specify its own compilers and add flags.
35config("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 Frolov844ff0f2020-05-06 12:15:29 -070042config("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 Frolovedd2f142020-06-09 19:11:27 -070048pw_source_set("pw_fuzzer") {
Wyatt Heplerb93749b2021-05-11 09:38:22 -070049 public_configs = [ ":public_include_path" ]
Aaron Green0ce7f412020-04-06 13:39:40 -070050 public = [
51 "public/pw_fuzzer/asan_interface.h",
52 "public/pw_fuzzer/fuzzed_data_provider.h",
53 ]
Aaron Green33c67822020-04-06 13:47:38 -070054 public_deps = [ "$dir_pw_log" ]
55}
56
Alexei Frolovf39fbf42020-09-08 14:41:53 -070057pw_source_set("run_as_unit_test") {
Wyatt Heplerb93749b2021-05-11 09:38:22 -070058 configs = [ ":public_include_path" ]
Wyatt Heplerc5e511e2020-06-12 16:56:22 -070059 sources = [ "pw_fuzzer_disabled.cc" ]
60 deps = [
61 dir_pw_log,
62 dir_pw_unit_test,
63 ]
64}
65
Aaron Green33c67822020-04-06 13:47:38 -070066# See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode
67config("fuzzing_build_mode_unsafe_for_production") {
68 defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ]
69}
70
71config("fuzzing_verbose_logging") {
72 defines = [ "FUZZING_VERBOSE_LOGGING" ]
73}
74
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070075pw_doc_group("docs") {
76 inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ]
77 sources = [ "docs.rst" ]
78}
79
80# Sample fuzzer
81pw_fuzzer("toy_fuzzer") {
82 sources = [ "examples/toy_fuzzer.cc" ]
Ewout van Bekkumf89f1372021-05-03 11:15:54 -070083 deps = [
84 "$dir_pw_result",
85 "$dir_pw_string",
86 ]
Aaron Greenf3c3d2b2020-04-02 23:12:31 -070087}
88
89pw_test_group("tests") {
90 tests = [ ":toy_fuzzer" ]
91}