Skip to content

Commit de3e4d7

Browse files
committed
Use same toolchain as cpp2rust
1 parent 2362241 commit de3e4d7

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎cpp2rust/cpp_rule_preprocessor.cpp‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <llvm/Support/CommandLine.h>
2525
#include <llvm/Support/FormatVariadic.h>
2626
#include <llvm/Support/JSON.h>
27+
#include <llvm/Support/MemoryBuffer.h>
2728
#include <llvm/Support/raw_ostream.h>
2829

2930
#include <cstdlib>
@@ -988,10 +989,15 @@ void Extract(const std::filesystem::path &src_path, llvm::json::Object &out,
988989
flags.insert(flags.end(), cxx_flags.begin(), cxx_flags.end());
989990
auto end_flags = getPlatformClangEndFlags();
990991
flags.insert(flags.end(), end_flags.begin(), end_flags.end());
991-
clang::tooling::FixedCompilationDatabase compilations(".", flags);
992+
auto code = llvm::MemoryBuffer::getFile(src_path.string());
993+
if (!code) {
994+
llvm::errs() << "ERROR: cannot read " << src_path.string() << '\n';
995+
std::exit(EXIT_FAILURE);
996+
}
992997
ActionFactory factory(out);
993-
clang::tooling::ClangTool tool(compilations, {src_path.string()});
994-
tool.run(&factory);
998+
clang::tooling::runToolOnCodeWithArgs(
999+
factory.create(), (*code)->getBuffer(), flags, src_path.string(),
1000+
src_path.extension() == ".c" ? CLANG_C_COMPILER : CLANG_CXX_COMPILER);
9951001
}
9961002

9971003
} // namespace cpp2rust

0 commit comments

Comments
 (0)