# Copyright 2020 The Pigweed Authors # # Licensed under the Apache License, Version 2.0 (the "License"); you may not # use this file except in compliance with the License. You may obtain a copy of # the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. import("//build_overrides/pigweed.gni") import("$dir_pw_build/target_types.gni") import("$dir_pw_docgen/docs.gni") import("$dir_pw_fuzzer/fuzzer.gni") config("public_include_path") { include_dirs = [ "public" ] visibility = [ ":*" ] } # Add flags for adding LLVM sanitizer coverage for fuzzing. This is added by # the host_clang_fuzz toolchains. config("instrumentation") { if (pw_toolchain_OSS_FUZZ_ENABLED) { # OSS-Fuzz manipulates compiler flags directly. See # google.github.io/oss-fuzz/getting-started/new-project-guide/#Requirements. cflags_c = string_split(getenv("CFLAGS")) cflags_cc = string_split(getenv("CXXFLAGS")) # OSS-Fuzz sets "-stdlib=libc++", which conflicts with the "-nostdinc++" set # by `pw_minimal_cpp_stdlib`. cflags_cc += [ "-Wno-unused-command-line-argument" ] } else { cflags = [ "-fsanitize=fuzzer-no-link" ] } } # Add flags for linking against compiler-rt's libFuzzer. This is added # automatically by `pw_fuzzer`. config("engine") { if (pw_toolchain_OSS_FUZZ_ENABLED) { # OSS-Fuzz manipulates linker flags directly. See # google.github.io/oss-fuzz/getting-started/new-project-guide/#Requirements. ldflags = string_split(getenv("LDFLAGS")) + [ getenv("LIB_FUZZING_ENGINE") ] } else { ldflags = [ "-fsanitize=fuzzer" ] } } pw_source_set("pw_fuzzer") { public_configs = [ ":public_include_path" ] public = [ "public/pw_fuzzer/asan_interface.h", "public/pw_fuzzer/fuzzed_data_provider.h", ] public_deps = [ "$dir_pw_log" ] } pw_source_set("run_as_unit_test") { configs = [ ":public_include_path" ] sources = [ "pw_fuzzer_disabled.cc" ] deps = [ dir_pw_log, dir_pw_unit_test, ] } # See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode config("fuzzing_build_mode_unsafe_for_production") { defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ] } config("fuzzing_verbose_logging") { defines = [ "FUZZING_VERBOSE_LOGGING" ] } pw_doc_group("docs") { inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ] sources = [ "docs.rst" ] } # Sample fuzzer pw_fuzzer("toy_fuzzer") { sources = [ "examples/toy_fuzzer.cc" ] deps = [ ":pw_fuzzer", dir_pw_status, ] } pw_test_group("tests") { tests = [ ":toy_fuzzer_test" ] } group("fuzzers") { deps = [ ":toy_fuzzer" ] }