From 584458bf211264f6d8c2108be05b489fae00c4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Gouveia?= Date: Thu, 11 Jun 2026 20:24:46 +0000 Subject: [PATCH] Add --cxxflags option to cpp-rule-preprocessor --- cpp2rust/cpp_rule_preprocessor.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cpp2rust/cpp_rule_preprocessor.cpp b/cpp2rust/cpp_rule_preprocessor.cpp index e7d1ae2f..e1421bce 100644 --- a/cpp2rust/cpp_rule_preprocessor.cpp +++ b/cpp2rust/cpp_rule_preprocessor.cpp @@ -16,6 +16,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -760,8 +763,10 @@ class ActionFactory : public clang::tooling::FrontendActionFactory { Callback cb_; }; -void Extract(const std::filesystem::path &src_path, llvm::json::Object &out) { +void Extract(const std::filesystem::path &src_path, llvm::json::Object &out, + llvm::ArrayRef cxx_flags) { auto flags = getPlatformClangBeginFlags(); + flags.insert(flags.end(), cxx_flags.begin(), cxx_flags.end()); auto end_flags = getPlatformClangEndFlags(); flags.insert(flags.end(), end_flags.begin(), end_flags.end()); clang::tooling::FixedCompilationDatabase compilations(".", flags); @@ -788,12 +793,19 @@ llvm::cl::opt llvm::cl::value_desc("out.json"), llvm::cl::Required, llvm::cl::cat(cat)); +llvm::cl::list CXXFlags("cxxflags", + llvm::cl::desc("Additional CXXFLAGS"), + llvm::cl::value_desc("cxxflags"), + llvm::cl::ZeroOrMore, llvm::cl::cat(cat)); + } // namespace int main(int argc, char *argv[]) { llvm::cl::HideUnrelatedOptions(cat); llvm::cl::ParseCommandLineOptions(argc, argv); + llvm::SmallVector cxx_flags(CXXFlags.begin(), + CXXFlags.end()); fs::path dir = SrcDir.getValue(); llvm::json::Object root; for (const char *name : {"src.c", "src.cpp"}) { @@ -803,7 +815,7 @@ int main(int argc, char *argv[]) { } llvm::errs() << "Preprocessing " << path.string() << '\n'; llvm::json::Object file_root; - cpp2rust::Extract(path, file_root); + cpp2rust::Extract(path, file_root, cxx_flags); for (auto &[k, v] : file_root) { if (!root.try_emplace(k, std::move(v)).second) { llvm::errs() << "ERROR: rule name " << k.str()