diff --git a/BUILD b/BUILD index 7e7c560e2e3..0a9d5ac10df 100644 --- a/BUILD +++ b/BUILD @@ -58,6 +58,12 @@ config_setting( values = {"apple_platform_type": "ios"}, ) +# Fuzzers can be built as fuzzers or as tests +config_setting( + name = "grpc_build_fuzzers", + values = {"define": "grpc_build_fuzzers=true"}, +) + selects.config_setting_group( name = "grpc_no_xds", match_any = [ diff --git a/test/core/util/grpc_fuzzer.bzl b/test/core/util/grpc_fuzzer.bzl index 99594b29e1d..97f51c68206 100644 --- a/test/core/util/grpc_fuzzer.bzl +++ b/test/core/util/grpc_fuzzer.bzl @@ -18,12 +18,18 @@ def grpc_fuzzer(name, corpus, srcs = [], deps = [], data = [], size = "large", * grpc_cc_test( name = name, srcs = srcs, - deps = deps + ["//test/core/util:fuzzer_corpus_test"], + deps = deps + select({ + "//:grpc_build_fuzzers": [], + "//conditions:default": ["//test/core/util:fuzzer_corpus_test"], + }), data = data + native.glob([corpus + "/**"]), external_deps = [ "gtest", ], size = size, - args = ["--directory=" + native.package_name() + "/" + corpus], + args = select({ + "//:grpc_build_fuzzers": [native.package_name() + "/" + corpus], + "//conditions:default": ["--directory=" + native.package_name() + "/" + corpus], + }), **kwargs ) diff --git a/tools/bazel.rc b/tools/bazel.rc index 480fdcbeb5e..9733eafb978 100644 --- a/tools/bazel.rc +++ b/tools/bazel.rc @@ -25,6 +25,20 @@ build:asan --linkopt=-fsanitize=address build:asan --action_env=ASAN_OPTIONS=detect_leaks=1:color=always build:asan --action_env=LSAN_OPTIONS=suppressions=test/core/util/lsan_suppressions.txt:report_objects=1 +build:fuzzer_asan --strip=never +build:fuzzer_asan --define=grpc_build_fuzzers=true +build:fuzzer_asan --copt=-fsanitize=fuzzer,address +build:fuzzer_asan --copt=-fsanitize-coverage=edge +build:fuzzer_asan --copt=-fsanitize-coverage=trace-cmp +build:fuzzer_asan --copt=-O0 +build:fuzzer_asan --copt=-fno-omit-frame-pointer +build:fuzzer_asan --copt=-DGPR_NO_DIRECT_SYSCALLS +build:fuzzer_asan --copt=-DGRPC_ASAN +build:fuzzer_asan --copt=-DADDRESS_SANITIZER # used by absl +build:fuzzer_asan --linkopt=-fsanitize=fuzzer,address +build:fuzzer_asan --action_env=ASAN_OPTIONS=detect_leaks=1:color=always +build:fuzzer_asan --action_env=LSAN_OPTIONS=suppressions=test/core/util/lsan_suppressions.txt:report_objects=1 + # We have a separate ASAN config for Mac OS to workaround a couple of bugs: # 1. https://github.com/bazelbuild/bazel/issues/6932 # _FORTIFY_SOURCE=1 is enabled by default on Mac OS, which breaks ASAN.