diff --git a/.bazelrc b/.bazelrc index bfaa00cca8..2278545f3b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -24,4 +24,16 @@ build:analyzer --per_file_copt=json/parser@-fno-analyzer build:analyzer --per_file_copt=com_google_protobuf@-fno-analyzer build:analyzer --per_file_copt=com_github_google_benchmark@-fno-analyzer -build:asan-fuzzer --copt=-fsanitize=address,fuzzer --linkopt=-fsanitize=address,fuzzer --define fuzz=true +# --config=asan-libfuzzer +build:asan-libfuzzer --action_env=CC=clang +build:asan-libfuzzer --action_env=CXX=clang++ +build:asan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine=@rules_fuzzing//fuzzing/engines:libfuzzer +build:asan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine_instrumentation=libfuzzer +build:asan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine_sanitizer=asan + +# --config=msan-libfuzzer +build:msan-libfuzzer --action_env=CC=clang +build:msan-libfuzzer --action_env=CXX=clang++ +build:msan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine=@rules_fuzzing//fuzzing/engines:libfuzzer +build:msan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine_instrumentation=libfuzzer +build:msan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine_sanitizer=msan diff --git a/WORKSPACE b/WORKSPACE index f17c4458cf..72c5d53804 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,6 +3,7 @@ workspace(name = "upb") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") load("//bazel:workspace_deps.bzl", "upb_deps") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") upb_deps() @@ -38,3 +39,18 @@ new_git_repository( build_file = "//benchmarks:BUILD.googleapis", patch_cmds = ["find google -type f -name BUILD.bazel -delete"], ) + +http_archive( + name = "rules_fuzzing", + sha256 = "127d7c45e9b7520b3c42145b3cb1b8c26477cdaed0521b02a0298907339fefa1", + strip_prefix = "rules_fuzzing-0.2.0", + urls = ["https://github.com/bazelbuild/rules_fuzzing/archive/v0.2.0.zip"], +) + +load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") + +rules_fuzzing_dependencies() + +load("@rules_fuzzing//fuzzing:init.bzl", "rules_fuzzing_init") + +rules_fuzzing_init() diff --git a/bazel/workspace_deps.bzl b/bazel/workspace_deps.bzl index d9b799c50a..40afa4a1e3 100644 --- a/bazel/workspace_deps.bzl +++ b/bazel/workspace_deps.bzl @@ -25,12 +25,8 @@ def upb_deps(): maybe( http_archive, name = "rules_python", - sha256 = "e5470e92a18aa51830db99a4d9c492cc613761d5bdb7131c04bd92b9834380f6", - strip_prefix = "rules_python-4b84ad270387a7c439ebdccfd530e2339601ef27", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_python/archive/4b84ad270387a7c439ebdccfd530e2339601ef27.tar.gz", - "https://github.com/bazelbuild/rules_python/archive/4b84ad270387a7c439ebdccfd530e2339601ef27.tar.gz", - ], + url = "https://github.com/bazelbuild/rules_python/releases/download/0.3.0/rules_python-0.3.0.tar.gz", + sha256 = "934c9ceb552e84577b0faf1e5a2f0450314985b4d8712b2b70717dc679fdc01b", ) maybe( diff --git a/tests/BUILD b/tests/BUILD index 017c9b7f6c..eabca4bd8a 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -34,14 +34,10 @@ load( "upb_proto_library", "upb_proto_reflection_library", ) +load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test") licenses(["notice"]) -config_setting( - name = "fuzz", - values = {"define": "fuzz=true"}, -) - cc_library( name = "upb_test", testonly = 1, @@ -144,18 +140,9 @@ cc_test( ) # OSS-Fuzz test -cc_binary( +cc_fuzz_test( name = "file_descriptor_parsenew_fuzzer", - testonly = 1, srcs = ["file_descriptor_parsenew_fuzzer.cc"], - copts = UPB_DEFAULT_CPPOPTS + select({ - "//conditions:default": [], - ":fuzz": ["-fsanitize=fuzzer,address"], - }), - defines = select({ - "//conditions:default": [], - ":fuzz": ["HAVE_FUZZER"], - }), deps = [ "//:descriptor_upb_proto", "//:upb", diff --git a/tests/file_descriptor_parsenew_fuzzer.cc b/tests/file_descriptor_parsenew_fuzzer.cc index 55fff0408c..d1569e2531 100644 --- a/tests/file_descriptor_parsenew_fuzzer.cc +++ b/tests/file_descriptor_parsenew_fuzzer.cc @@ -34,7 +34,3 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { size, arena.ptr()); return 0; } - -#ifndef HAVE_FUZZER -int main() {} -#endif