mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:21:21 +01:00
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
31 lines
964 B
C++
31 lines
964 B
C++
// 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
|
|
|
|
#ifndef EXPLORER_FUZZING_FUZZER_UTIL_H_
|
|
#define EXPLORER_FUZZING_FUZZER_UTIL_H_
|
|
|
|
#include "common/error.h"
|
|
#include "common/fuzzing/carbon.pb.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// Converts `compilation_unit` to Carbon. Adds an default `Main()`
|
|
// definition if one is not present in the proto.
|
|
auto ProtoToCarbonWithMain(const Fuzzing::CompilationUnit& compilation_unit)
|
|
-> std::string;
|
|
|
|
// Parses and executes a fuzzer-generated program.
|
|
void ParseAndExecute(const Fuzzing::CompilationUnit& compilation_unit);
|
|
|
|
namespace Internal {
|
|
|
|
// Returns a full path for a file under bazel runfiles.
|
|
// Exposed for testing.
|
|
auto GetRunfilesFile(const std::string& file) -> ErrorOr<std::string>;
|
|
|
|
} // namespace Internal
|
|
} // namespace Carbon
|
|
|
|
#endif // EXPLORER_FUZZING_FUZZER_UTIL_H_
|