Files
carbon-lang/explorer/fuzzing/BUILD
T
pk19604014 150057f260 Added GetRunfilesFile() to be able to reliably determine prelude location under various invocation scenarios
The logic is using bazel Runfiles API per Jon's suggestion.

One of the scenarios used by the fuzzing framework is to place the binary and its runfiles into a folder, resulting in a directory layout like this:

[temp dir]
fuzzer
fuzzer.runfiles/

Tested:
bazel test -c opt explorer/fuzzing:explorer_fuzzer
bazel build -c opt explorer/fuzzing:explorer_fuzzer + run the binary from various locations
2022-05-02 10:36:21 -04:00

134 lines
3.4 KiB
Python

# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("//bazel/fuzzing:rules.bzl", "cc_fuzz_test")
cc_library(
name = "ast_to_proto_lib",
testonly = 1,
srcs = ["ast_to_proto.cpp"],
hdrs = ["ast_to_proto.h"],
deps = [
"//common/fuzzing:carbon_cc_proto",
"//explorer/ast",
"//explorer/ast:declaration",
"//explorer/ast:expression",
"@llvm-project//llvm:Support",
],
)
cc_library(
name = "fuzzer_util",
testonly = 1,
srcs = ["fuzzer_util.cpp"],
hdrs = ["fuzzer_util.h"],
deps = [
"//common:check",
"//common:error",
"//common/fuzzing:carbon_cc_proto",
"//common/fuzzing:proto_to_carbon_lib",
"//explorer/interpreter:exec_program",
"//explorer/syntax",
"//explorer/syntax:prelude",
"@bazel_tools//tools/cpp/runfiles",
"@com_google_protobuf//:protobuf_headers",
"@llvm-project//llvm:Support",
],
)
cc_test(
name = "ast_to_proto_test",
srcs = ["ast_to_proto_test.cpp"],
args = [
"$(locations //explorer:standard_libraries)",
"$(locations //explorer/testdata:carbon_files)",
],
data = [
"//explorer:standard_libraries",
"//explorer/testdata:carbon_files",
],
deps = [
":ast_to_proto_lib",
"//common/fuzzing:carbon_cc_proto",
"//explorer/syntax",
"@com_google_googletest//:gtest",
"@com_google_protobuf//:protobuf_headers",
"@llvm-project//llvm:Support",
],
)
cc_binary(
name = "fuzzverter",
testonly = 1,
srcs = ["fuzzverter.cpp"],
deps = [
":ast_to_proto_lib",
":fuzzer_util",
"//common:error",
"//common/fuzzing:carbon_cc_proto",
"//explorer/common:error_builders",
"//explorer/common:nonnull",
"//explorer/syntax",
"@com_google_protobuf//:protobuf_headers",
"@llvm-project//llvm:Support",
],
)
filegroup(
name = "fuzzer_corpus_files",
srcs = glob(["fuzzer_corpus/**"]),
)
cc_test(
name = "fuzzer_util_test",
srcs = ["fuzzer_util_test.cpp"],
args = [
"$(locations fuzzer_corpus_files)",
],
data = [
":fuzzer_corpus_files",
],
deps = [
":fuzzer_util",
"@com_google_googletest//:gtest",
"@com_google_protobuf//:protobuf_headers",
"@llvm-project//llvm:Support",
],
)
cc_test(
name = "proto_to_carbon_test",
srcs = ["proto_to_carbon_test.cpp"],
args = [
"$(locations //explorer:standard_libraries)",
"$(locations //explorer/testdata:carbon_files)",
],
data = [
"//explorer:standard_libraries",
"//explorer/testdata:carbon_files",
],
deps = [
":ast_to_proto_lib",
"//common/fuzzing:carbon_cc_proto",
"//common/fuzzing:proto_to_carbon_lib",
"//explorer/syntax",
"@com_google_googletest//:gtest",
"@com_google_protobuf//:protobuf_headers",
"@llvm-project//llvm:Support",
],
)
# Needs `--config=proto-fuzzer` for `bazel build`.
cc_binary(
name = "explorer_fuzzer",
testonly = 1,
srcs = ["explorer_fuzzer.cpp"],
features = ["fuzzer"],
deps = [
":fuzzer_util",
"@com_google_libprotobuf_mutator//:libprotobuf_mutator",
"@llvm-project//llvm:Support",
],
)