From 8f31c3b81f59346bcc50d600e18a9a0f820d2f95 Mon Sep 17 00:00:00 2001 From: DronCode Date: Wed, 4 Dec 2024 21:29:00 +0300 Subject: [PATCH 01/14] [0.0.24] Protobuf initial support (CI, small tests, base analyzer, base env) --- .github/workflows/build.yml | 33 +++- CMakeLists.txt | 7 +- Protobuf/CMakeLists.txt | 43 ++++++ Protobuf/include/RG3/Protobuf/Compiler.h | 44 ++++++ Protobuf/include/RG3/Protobuf/Protobuf.h | 4 + .../include/RG3/Protobuf/ProtobufAnalyzer.h | 41 +++++ Protobuf/source/Protobuf.cpp | 1 + Protobuf/source/ProtobufAnalyzer.cpp | 143 ++++++++++++++++++ PyBind/CMakeLists.txt | 2 +- Tests/Unit/CMakeLists.txt | 3 +- Tests/Unit/source/Tests_Protobuf.cpp | 66 ++++++++ 11 files changed, 379 insertions(+), 8 deletions(-) create mode 100644 Protobuf/CMakeLists.txt create mode 100644 Protobuf/include/RG3/Protobuf/Compiler.h create mode 100644 Protobuf/include/RG3/Protobuf/Protobuf.h create mode 100644 Protobuf/include/RG3/Protobuf/ProtobufAnalyzer.h create mode 100644 Protobuf/source/Protobuf.cpp create mode 100644 Protobuf/source/ProtobufAnalyzer.cpp create mode 100644 Tests/Unit/source/Tests_Protobuf.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fdae71f..05253d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,7 +25,8 @@ jobs: llvm_tag: "llvmorg-19.1.4", python_version: "3.10", os_version: "2022", - artifact_id: "RG3_Windows" + artifact_id: "RG3_Windows", + protobuf_tag: "v29.1" } - { name: "Ubuntu Linux", @@ -38,7 +39,8 @@ jobs: llvm_tag: "llvmorg-19.1.4", python_version: "3.10", os_version: "24.04", - artifact_id: "RG3_Linux" + artifact_id: "RG3_Linux", + protobuf_tag: "v29.1" } - { name: "macOS", @@ -51,7 +53,8 @@ jobs: llvm_tag: "llvmorg-19.1.4", python_version: "3.10", os_version: "13", - artifact_id: "RG3_macOS" + artifact_id: "RG3_macOS", + protobuf_tag: "v29.1" } steps: @@ -186,12 +189,36 @@ jobs: llvm_repo/llvm llvm_repo/clang + - name: Checkout Protobuf + uses: actions/checkout@v3 + with: + submodules: "recursive" + repository: "protocolbuffers/protobuf" + ref: ${{ matrix.config.protobuf_tag }} + path: "protobuf_repo" + + # Protobuf (will use cache later) + - name: Build Protobuf + working-directory: protobuf_repo + env: + CC: ${{ matrix.config.cc }} + CXX: ${{ matrix.config.cxx }} + run: | + mkdir build + mkdir build/install + cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -B build -S . -G "${{ matrix.config.cmake_generator }}" + cmake --build build --config MinSizeRel + cmake --install build + # Build our project - name: Build RG3 env: LLVM_DIR: ${{ github.workspace }}/llvm_repo/build/lib/cmake/llvm CLANG_DIR: ${{ github.workspace }}/llvm_repo/build/lib/cmake/clang Boost_ROOT: ${{ github.workspace }}/boost_1_81_0/stage/lib/cmake/Boost-1.81.0 + absl_DIR: ${{ github.workspace }}/protobuf_repo/build/install/lib/cmake/absl + utf8_range_DIR: ${{ github.workspace }}/protobuf_repo/build/install/lib/cmake/utf8_range_DIR + Protobuf_DIR: ${{ github.workspace }}/protobuf_repo/build/install/lib/cmake/protobuf Python3_USE_STATIC_LIBS: "TRUE" CC: ${{ matrix.config.cc }} CXX: ${{ matrix.config.cxx }} diff --git a/CMakeLists.txt b/CMakeLists.txt index f32a8f4..15a0d90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,10 @@ endif() add_subdirectory(ThirdParty/fmt) -add_subdirectory(Cpp) -add_subdirectory(LLVM) -add_subdirectory(PyBind) +add_subdirectory(Cpp) # Base entities & logic +add_subdirectory(LLVM) # LLVM driver & AST parsing +add_subdirectory(Protobuf) # Protobuf driver & analyzer +add_subdirectory(PyBind) # Python bindings # Unit tests add_subdirectory(ThirdParty/googletest) diff --git a/Protobuf/CMakeLists.txt b/Protobuf/CMakeLists.txt new file mode 100644 index 0000000..7de01b8 --- /dev/null +++ b/Protobuf/CMakeLists.txt @@ -0,0 +1,43 @@ +project(RG3_LLVM) + +# ------- Boost +set(Boost_USE_STATIC_LIBS ON) +find_package(Boost COMPONENTS filesystem REQUIRED HINTS $ENV{Boost_ROOT}) + +# ------- Protobuf +# Required to have Protobuf_DIR, absl_DIR and utf8_range_DIR + +find_package(absl REQUIRED CONFIG HINTS $ENV{absl_DIR}) +find_package(utf8_range REQUIRED CONFIG HINTS $ENV{utf8_range_DIR}) +find_package(Protobuf REQUIRED CONFIG HINTS $ENV{Protobuf_DIR}) + +message(STATUS "Found Protobuf ${Protobuf_VERSION} (${Protobuf_DIR})") + +# ------- RG3 Protobuf +file(GLOB_RECURSE RG3_PROTOBUF_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp") +add_library(RG3_Protobuf STATIC ${RG3_PROTOBUF_SOURCES}) +add_library(RG3::Protobuf ALIAS RG3_Protobuf) +target_include_directories(RG3_Protobuf PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") +target_include_directories(RG3_Protobuf PUBLIC ${Protobuf_INCLUDE_DIRS}) +target_include_directories(RG3_Protobuf PUBLIC ${absl_INCLUDE_DIRS}) +target_include_directories(RG3_Protobuf PUBLIC ${utf8_range_INCLUDE_DIRS}) + +if (MSVC) + # /bigobj support + target_compile_options(RG3_LLVM PUBLIC /bigobj) +endif() + +target_link_libraries(RG3_Protobuf PUBLIC + # Protobuf + protobuf::libprotobuf + protobuf::libprotoc + protobuf::libupb + utf8_range::utf8_range + absl::base + absl::strings + # Boost + ${Boost_LIBRARIES} # RG3 + RG3::Cpp + # FMT + fmt::fmt +) \ No newline at end of file diff --git a/Protobuf/include/RG3/Protobuf/Compiler.h b/Protobuf/include/RG3/Protobuf/Compiler.h new file mode 100644 index 0000000..139dfa1 --- /dev/null +++ b/Protobuf/include/RG3/Protobuf/Compiler.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include + + +namespace rg3::pb +{ + /** + * @brief In most cases used syntax from .proto file, but you able to specify it directly here (in C++/Python code) + */ + enum class ProtobufSyntax { PB_SYNTAX_2 = 2, PB_SYNTAX_3 = 3 }; + + /** + * @brief There are 2 issues in protoc: errors and warnings + */ + enum class IssueKind { IK_WARNING, IK_ERROR }; + + /** + * @brief Most useful parameters for protoc (in-memory version). Unlike LLVM CompilerConfig, that options useful only for protoc + */ + struct CompilerConfig { + ProtobufSyntax eSyntax { ProtobufSyntax::PB_SYNTAX_3 }; + std::vector vIncludeDirs {}; + bool bUseStrictMode { true }; + bool bEnableGRPC { false }; + bool bGenerateClientStubs { false }; + bool bUseLiteGenerator { false }; + }; + + /** + * @brief Describe issue in protoc + */ + struct CompilerIssue + { + IssueKind eKind { IssueKind::IK_WARNING }; + int iLine { 0 }; + int iColumn { 0 }; + std::string sMessage {}; + }; + + using CompilerIssuesVector = std::vector; +} \ No newline at end of file diff --git a/Protobuf/include/RG3/Protobuf/Protobuf.h b/Protobuf/include/RG3/Protobuf/Protobuf.h new file mode 100644 index 0000000..260812f --- /dev/null +++ b/Protobuf/include/RG3/Protobuf/Protobuf.h @@ -0,0 +1,4 @@ +#pragma once + +namespace rg3::pb +{} \ No newline at end of file diff --git a/Protobuf/include/RG3/Protobuf/ProtobufAnalyzer.h b/Protobuf/include/RG3/Protobuf/ProtobufAnalyzer.h new file mode 100644 index 0000000..d004772 --- /dev/null +++ b/Protobuf/include/RG3/Protobuf/ProtobufAnalyzer.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +#include + +#include +#include +#include + + +namespace rg3::pb +{ + /** + * @brief This class implements a single threaded analyzer of protobuf code. + */ + class ProtobufAnalyzer final : public boost::noncopyable + { + public: + using CodeSource = std::variant; // string is a code repr in memory (id0.proto), filesystem::path for FS path + + ProtobufAnalyzer(); + + void setCode(const std::string& sCode); + void setFile(const std::filesystem::path& sPath); + void setSource(const CodeSource& src); + + void setCompilerConfig(const CompilerConfig& sConfig); + const CompilerConfig& getCompilerConfig() const; + CompilerConfig& getCompilerConfig(); + + [[nodiscard]] const CompilerIssuesVector& getIssues() const; + + bool analyze(); + + private: + CodeSource m_sSource {}; + CompilerConfig m_sConfig {}; + CompilerIssuesVector m_aIssues {}; + }; +} \ No newline at end of file diff --git a/Protobuf/source/Protobuf.cpp b/Protobuf/source/Protobuf.cpp new file mode 100644 index 0000000..8b73bce --- /dev/null +++ b/Protobuf/source/Protobuf.cpp @@ -0,0 +1 @@ +void stub() {} \ No newline at end of file diff --git a/Protobuf/source/ProtobufAnalyzer.cpp b/Protobuf/source/ProtobufAnalyzer.cpp new file mode 100644 index 0000000..9e02082 --- /dev/null +++ b/Protobuf/source/ProtobufAnalyzer.cpp @@ -0,0 +1,143 @@ +#include + +#include +#include + +#include +#include +#include +#include + + +namespace rg3::pb +{ + ProtobufAnalyzer::ProtobufAnalyzer() = default; + + void ProtobufAnalyzer::setCode(const std::string& sCode) + { + m_sSource = sCode; + } + + void ProtobufAnalyzer::setFile(const std::filesystem::path& sPath) + { + m_sSource = sPath; + } + + void ProtobufAnalyzer::setSource(const CodeSource& src) + { + m_sSource = src; + } + + void ProtobufAnalyzer::setCompilerConfig(const CompilerConfig& sConfig) + { + m_sConfig = sConfig; + } + + const CompilerConfig& ProtobufAnalyzer::getCompilerConfig() const + { + return m_sConfig; + } + + CompilerConfig& ProtobufAnalyzer::getCompilerConfig() + { + return m_sConfig; + } + + const CompilerIssuesVector& ProtobufAnalyzer::getIssues() const + { + return m_aIssues; + } + + struct InMemoryErrorCollector final : google::protobuf::io::ErrorCollector + { + std::vector* paIssues {}; + + explicit InMemoryErrorCollector(std::vector* pOut) : google::protobuf::io::ErrorCollector(), paIssues(pOut) {} + + void RecordError(int line, google::protobuf::io::ColumnNumber column, absl::string_view message) override + { + CompilerIssue& sIssue = paIssues->emplace_back(); + sIssue.eKind = IssueKind::IK_ERROR; + sIssue.iLine = line; + sIssue.iColumn = column; + sIssue.sMessage = message.data(); + } + + void RecordWarning(int line, google::protobuf::io::ColumnNumber column, absl::string_view message) override + { + CompilerIssue& sIssue = paIssues->emplace_back(); + sIssue.eKind = IssueKind::IK_WARNING; + sIssue.iLine = line; + sIssue.iColumn = column; + sIssue.sMessage = message.data(); + } + }; + + template constexpr bool always_false_v = false; + + std::pair, std::string> getStream(const ProtobufAnalyzer::CodeSource& source) { + return std::visit([](const auto& value) -> std::pair, std::string> { + using T = std::decay_t; + + if constexpr (std::is_same_v) { + return { std::make_unique(value), "id0.proto" }; + } else if constexpr (std::is_same_v) { + auto stream = std::make_unique(value); + if (!stream->is_open()) + { + return { nullptr, "" }; + } + + return { std::move(stream), value.string() }; + } else { + static_assert(always_false_v, "Unhandled variant type"); + } + }, source); + } + + bool ProtobufAnalyzer::analyze() + { + m_aIssues.clear(); + + // 1. Parse + auto [pStreamMem, sStreamId] = getStream(m_sSource); + if (!pStreamMem) + { + CompilerIssue& sIssue = m_aIssues.emplace_back(); + sIssue.sMessage = "Failed to handle I/O (unable to open file IO)"; + sIssue.iColumn = sIssue.iLine = 0; + return false; + } + + InMemoryErrorCollector sErrorCollector { &m_aIssues }; + google::protobuf::compiler::Parser sProtobufParser {}; + google::protobuf::io::IstreamInputStream sStream { pStreamMem.get() }; + google::protobuf::io::Tokenizer sTokenizer { &sStream, &sErrorCollector }; + google::protobuf::FileDescriptorProto sDescriptor {}; + + sProtobufParser.RecordErrorsTo(&sErrorCollector); + sDescriptor.set_name(sStreamId); + + if (!sProtobufParser.Parse(&sTokenizer, &sDescriptor)) + { + return false; + } + + // Semantic analysis + google::protobuf::DescriptorPool sDescriptorPool; + + google::protobuf::DescriptorPool sBuiltinPool(google::protobuf::DescriptorPool::generated_pool()); + const google::protobuf::FileDescriptor* pFileDescriptor = sBuiltinPool.BuildFile(sDescriptor); + + if (!pFileDescriptor) + { + CompilerIssue& sIssue = m_aIssues.emplace_back(); + sIssue.sMessage = "Semantic error: Failed to resolve types in the file."; + sIssue.iColumn = sIssue.iLine = 0; + return false; + } + + // Done + return std::count_if(m_aIssues.begin(), m_aIssues.end(), [](const CompilerIssue& sIssue) -> bool { return sIssue.eKind == IssueKind::IK_ERROR; }) == 0; + } +} \ No newline at end of file diff --git a/PyBind/CMakeLists.txt b/PyBind/CMakeLists.txt index 5129338..037aeae 100644 --- a/PyBind/CMakeLists.txt +++ b/PyBind/CMakeLists.txt @@ -13,7 +13,7 @@ file(GLOB_RECURSE RG3_PYBIND_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp") add_library(RG3_PyBind SHARED ${RG3_PYBIND_SOURCES}) add_library(RG3::PyBind ALIAS RG3_PyBind) target_include_directories(RG3_PyBind PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") -target_link_libraries(RG3_PyBind PUBLIC RG3::Cpp RG3::LLVM) +target_link_libraries(RG3_PyBind PUBLIC RG3::Cpp RG3::LLVM RG3::Protobuf) target_link_libraries(RG3_PyBind PUBLIC ${Boost_LIBRARIES} ${Python3_LIBRARIES} Python3::Module) target_link_libraries(RG3_PyBind PRIVATE fmt::fmt) diff --git a/Tests/Unit/CMakeLists.txt b/Tests/Unit/CMakeLists.txt index 5104d6b..7cd2b22 100644 --- a/Tests/Unit/CMakeLists.txt +++ b/Tests/Unit/CMakeLists.txt @@ -9,4 +9,5 @@ add_executable(RG3_Unit ${RG3_UNIT_SOURCES}) target_link_libraries(RG3_Unit gtest RG3::LLVM - RG3::Cpp) \ No newline at end of file + RG3::Cpp + RG3::Protobuf) \ No newline at end of file diff --git a/Tests/Unit/source/Tests_Protobuf.cpp b/Tests/Unit/source/Tests_Protobuf.cpp new file mode 100644 index 0000000..36f781f --- /dev/null +++ b/Tests/Unit/source/Tests_Protobuf.cpp @@ -0,0 +1,66 @@ +#include + +#include +#include + + +class Tests_Protobuf : public ::testing::Test +{ + protected: + void SetUp() override + { + g_Analyzer = std::make_unique(); + } + + void TearDown() override + { + g_Analyzer = nullptr; + } + + protected: + std::unique_ptr g_Analyzer { nullptr }; +}; + +TEST_F(Tests_Protobuf, CheckErrorHandler) +{ + g_Analyzer->setCode(R"( +syntax = "proto3"; + +message WhatTheFuck { + string name = 1; + int32 id = 1; + mdma_pzdc field = 40; +} +)"); + + g_Analyzer->getCompilerConfig().eSyntax = rg3::pb::ProtobufSyntax::PB_SYNTAX_3; + g_Analyzer->getCompilerConfig().vIncludeDirs = {}; + ASSERT_FALSE(g_Analyzer->analyze()); +} + +TEST_F(Tests_Protobuf, SimpleUsage) +{ + g_Analyzer->setCode(R"( +syntax = "proto3"; + +import "google/protobuf/descriptor.proto"; + +// Custom entries (should be declared somehow) +extend google.protobuf.MessageOptions { + bool runtime = 707228; +} + +message User { + option (runtime) = true; + + string id = 1; + string first_name = 2; + string last_name = 3; + string avatar = 4; +} +)"); + + g_Analyzer->getCompilerConfig().eSyntax = rg3::pb::ProtobufSyntax::PB_SYNTAX_3; + g_Analyzer->getCompilerConfig().vIncludeDirs = {}; + ASSERT_TRUE(g_Analyzer->analyze()); +} \ No newline at end of file From 66f374821d289d847b2cec05f2b6100378f23f58 Mon Sep 17 00:00:00 2001 From: DronCode Date: Wed, 4 Dec 2024 21:37:59 +0300 Subject: [PATCH 02/14] [0.0.24] Fix bad path in CI --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 05253d8..8dcee26 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -217,7 +217,7 @@ jobs: CLANG_DIR: ${{ github.workspace }}/llvm_repo/build/lib/cmake/clang Boost_ROOT: ${{ github.workspace }}/boost_1_81_0/stage/lib/cmake/Boost-1.81.0 absl_DIR: ${{ github.workspace }}/protobuf_repo/build/install/lib/cmake/absl - utf8_range_DIR: ${{ github.workspace }}/protobuf_repo/build/install/lib/cmake/utf8_range_DIR + utf8_range_DIR: ${{ github.workspace }}/protobuf_repo/build/install/lib/cmake/utf8_range Protobuf_DIR: ${{ github.workspace }}/protobuf_repo/build/install/lib/cmake/protobuf Python3_USE_STATIC_LIBS: "TRUE" CC: ${{ matrix.config.cc }} From 6470c35c32c864ea5dbe3d0be9597582156f0788 Mon Sep 17 00:00:00 2001 From: DronCode Date: Thu, 5 Dec 2024 20:02:21 +0300 Subject: [PATCH 03/14] [0.0.24] Try switch to Release configuration for protobuf & absl --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8dcee26..9c5c003 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -206,8 +206,8 @@ jobs: run: | mkdir build mkdir build/install - cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -B build -S . -G "${{ matrix.config.cmake_generator }}" - cmake --build build --config MinSizeRel + cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -B build -S . -G "${{ matrix.config.cmake_generator }}" + cmake --build build --config Release cmake --install build # Build our project From 736d2c98e6427550fbda13b8c685c5e328e04677 Mon Sep 17 00:00:00 2001 From: DronCode Date: Thu, 5 Dec 2024 20:22:31 +0300 Subject: [PATCH 04/14] [0.0.24] Again and again trying to build this piece of code... --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9c5c003..09fa26e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -206,7 +206,7 @@ jobs: run: | mkdir build mkdir build/install - cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -B build -S . -G "${{ matrix.config.cmake_generator }}" + cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -S . -G "${{ matrix.config.cmake_generator }}" cmake --build build --config Release cmake --install build From 5783dd4d695c44ac702bee39294fcbf0e426ac9d Mon Sep 17 00:00:00 2001 From: DronCode Date: Thu, 5 Dec 2024 20:45:51 +0300 Subject: [PATCH 05/14] [0.0.24] Trying to fix fucked up windows build (I hate this shit) --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 09fa26e..ba99b60 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -206,7 +206,7 @@ jobs: run: | mkdir build mkdir build/install - cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -S . -G "${{ matrix.config.cmake_generator }}" + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -S . -G "${{ matrix.config.cmake_generator }}" cmake --build build --config Release cmake --install build From 18f9758118b1622892fb9af3b8b4c336fce28fdb Mon Sep 17 00:00:00 2001 From: DronCode Date: Thu, 5 Dec 2024 21:03:11 +0300 Subject: [PATCH 06/14] [0.0.24] Another one try to hit into MSVC Runtime Shit --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba99b60..d1e3bd3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -206,7 +206,7 @@ jobs: run: | mkdir build mkdir build/install - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -S . -G "${{ matrix.config.cmake_generator }}" + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -S . -G "${{ matrix.config.cmake_generator }}" cmake --build build --config Release cmake --install build From 3c04b077b3a2c9f5744796a5b9033f48a7d12913 Mon Sep 17 00:00:00 2001 From: DronCode Date: Thu, 5 Dec 2024 21:22:07 +0300 Subject: [PATCH 07/14] [0.0.24] Last try for today --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d1e3bd3..0ce8210 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -224,7 +224,7 @@ jobs: CXX: ${{ matrix.config.cxx }} run: | mkdir build - cmake -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -G "${{ matrix.config.cmake_generator }}" + cmake -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -G "${{ matrix.config.cmake_generator }}" cd build cmake --build . --config MinSizeRel From 5334d5dbf6e271903bc6c0f4ead06d6db4b59529 Mon Sep 17 00:00:00 2001 From: DronCode Date: Thu, 5 Dec 2024 21:40:30 +0300 Subject: [PATCH 08/14] [0.0.24] FUUUUUUUUUUUUUUUU --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ce8210..15f735d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -206,7 +206,7 @@ jobs: run: | mkdir build mkdir build/install - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -S . -G "${{ matrix.config.cmake_generator }}" + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -S . -G "${{ matrix.config.cmake_generator }}" cmake --build build --config Release cmake --install build @@ -224,7 +224,7 @@ jobs: CXX: ${{ matrix.config.cxx }} run: | mkdir build - cmake -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -G "${{ matrix.config.cmake_generator }}" + cmake -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -G "${{ matrix.config.cmake_generator }}" cd build cmake --build . --config MinSizeRel From 6b96c2c9bf3cffe46ac507dc1767d9167b7b4bad Mon Sep 17 00:00:00 2001 From: DronCode Date: Thu, 5 Dec 2024 22:01:08 +0300 Subject: [PATCH 09/14] [0.0.24] Full fucking rebuild of everything to support /MT correct work on whole project --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 15f735d..ad14c33 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -121,7 +121,7 @@ jobs: tar xzf boost_1_81_0.tar.gz cd boost_1_81_0 .\bootstrap.bat --with-libraries=system,filesystem,python - .\b2 link=static variant=release + .\b2 link=static runtime-link=static variant=release - name: Download and build Boost (macOS) if: steps.cache-boost-binaries.outputs.cache-hit != 'true' && matrix.config.os_id == 'macos' @@ -169,7 +169,7 @@ jobs: CXX: ${{ matrix.config.cxx }} run: | mkdir build - cmake -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_RTTI=ON -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_TOOLS=ON -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_BUILD_32_BITS=OFF -DLLVM_ENABLE_BINDINGS=OFF -DLLVM_BUILD_DOCS=OFF -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -S llvm -B build -G "${{ matrix.config.cmake_generator }}" + cmake -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_RTTI=ON -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_TOOLS=ON -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_BUILD_32_BITS=OFF -DLLVM_ENABLE_BINDINGS=OFF -DLLVM_BUILD_DOCS=OFF -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -S llvm -B build -G "${{ matrix.config.cmake_generator }}" cd build cmake --build . --config MinSizeRel From 3d398a39d0ebc93c2b6a8bc3bdbfed4f337dd2bf Mon Sep 17 00:00:00 2001 From: DronCode Date: Fri, 6 Dec 2024 08:49:05 +0300 Subject: [PATCH 10/14] [0.0.24] Another day, another fix --- LLVM/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/LLVM/CMakeLists.txt b/LLVM/CMakeLists.txt index e59466f..fe0b5e0 100644 --- a/LLVM/CMakeLists.txt +++ b/LLVM/CMakeLists.txt @@ -2,6 +2,11 @@ project(RG3_LLVM) # ------- Boost set(Boost_USE_STATIC_LIBS ON) +if (MSVC) + # Should use this on Windows to enable /MT for boost too + set(Boost_USE_STATIC_RUNTIME ON) +endif() + find_package(Boost COMPONENTS filesystem REQUIRED HINTS $ENV{Boost_ROOT}) # ------- LLVM BACKEND From e87c536278c806f7062dd2f223aeb20db3ec5b85 Mon Sep 17 00:00:00 2001 From: DronCode Date: Fri, 6 Dec 2024 09:18:47 +0300 Subject: [PATCH 11/14] [0.0.24] Ok, another try to build this madness --- .github/workflows/build.yml | 6 +++++- Protobuf/CMakeLists.txt | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ad14c33..b78ba02 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -224,7 +224,11 @@ jobs: CXX: ${{ matrix.config.cxx }} run: | mkdir build - cmake -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -G "${{ matrix.config.cmake_generator }}" + if [[ "${{ matrix.config.os_id }}" == "windows" ]]; then + cmake -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DBoost_USE_STATIC_RUNTIME=ON -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -G "${{ matrix.config.cmake_generator }}" + else + cmake -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -G "${{ matrix.config.cmake_generator }}" + fi cd build cmake --build . --config MinSizeRel diff --git a/Protobuf/CMakeLists.txt b/Protobuf/CMakeLists.txt index 7de01b8..b5c3dbe 100644 --- a/Protobuf/CMakeLists.txt +++ b/Protobuf/CMakeLists.txt @@ -2,6 +2,11 @@ project(RG3_LLVM) # ------- Boost set(Boost_USE_STATIC_LIBS ON) +if (MSVC) + # Should use this on Windows to enable /MT for boost too + set(Boost_USE_STATIC_RUNTIME ON) +endif() + find_package(Boost COMPONENTS filesystem REQUIRED HINTS $ENV{Boost_ROOT}) # ------- Protobuf From c235edb6cfd1547f616579f80e19dd789d427b81 Mon Sep 17 00:00:00 2001 From: DronCode <32241726+DronCode@users.noreply.github.com> Date: Fri, 6 Dec 2024 09:49:34 +0300 Subject: [PATCH 12/14] Update build.yml --- .github/workflows/build.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b78ba02..ad14c33 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -224,11 +224,7 @@ jobs: CXX: ${{ matrix.config.cxx }} run: | mkdir build - if [[ "${{ matrix.config.os_id }}" == "windows" ]]; then - cmake -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DBoost_USE_STATIC_RUNTIME=ON -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -G "${{ matrix.config.cmake_generator }}" - else - cmake -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -G "${{ matrix.config.cmake_generator }}" - fi + cmake -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -G "${{ matrix.config.cmake_generator }}" cd build cmake --build . --config MinSizeRel From 70bb46e1f4117436b07cfaa78a180cd3b40ec751 Mon Sep 17 00:00:00 2001 From: DronCode <32241726+DronCode@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:12:58 +0300 Subject: [PATCH 13/14] Update CMakeLists.txt --- PyBind/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PyBind/CMakeLists.txt b/PyBind/CMakeLists.txt index 037aeae..261b327 100644 --- a/PyBind/CMakeLists.txt +++ b/PyBind/CMakeLists.txt @@ -2,6 +2,11 @@ project(RG3_PyBind) set(Boost_USE_STATIC_LIBS ON) +if (MSVC) + # Should use this on Windows to enable /MT for boost too + set(Boost_USE_STATIC_RUNTIME ON) +endif() + # ------- LLVM BACKEND find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED) #./bootstrap.sh --with-libraries=python,system,filesystem --with-python=/Users/USERNAME/.pyenv/versions/3.10-dev/bin/python3 --with-python-version=3.10 --with-python-root=/Users/USERNAME/.pyenv/versions/3.10-dev/bin/python3 @@ -38,4 +43,4 @@ message(STATUS "[CI|POST_BUILD] Copy native extension to ${CMAKE_CURRENT_SOURCE_ add_custom_command( TARGET RG3_PyBind POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_SOURCE_DIR}/$) \ No newline at end of file + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_SOURCE_DIR}/$) From 42818d0c920f29cede5886a49144f8346d0dbbc7 Mon Sep 17 00:00:00 2001 From: DronCode Date: Sun, 9 Mar 2025 16:44:30 +0300 Subject: [PATCH 14/14] [NO CI] Temp changes --- LLVM/source/CompilerInstanceFactory.cpp | 4 ++ Protobuf/CMakeLists.txt | 6 +-- Protobuf/include/RG3/Protobuf/Enum.h | 38 ++++++++++++++ Protobuf/include/RG3/Protobuf/Location.h | 14 ++++++ Protobuf/include/RG3/Protobuf/Message.h | 36 +++++++++++++ Protobuf/include/RG3/Protobuf/Service.h | 28 +++++++++++ Protobuf/source/Enum.cpp | 7 +++ Protobuf/source/ProtobufAnalyzer.cpp | 64 ++++++++++++++++++++++++ Tests/Unit/source/Tests_Enum.cpp | 14 ++++++ 9 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 Protobuf/include/RG3/Protobuf/Enum.h create mode 100644 Protobuf/include/RG3/Protobuf/Location.h create mode 100644 Protobuf/include/RG3/Protobuf/Message.h create mode 100644 Protobuf/include/RG3/Protobuf/Service.h create mode 100644 Protobuf/source/Enum.cpp diff --git a/LLVM/source/CompilerInstanceFactory.cpp b/LLVM/source/CompilerInstanceFactory.cpp index e1f0989..42ab870 100644 --- a/LLVM/source/CompilerInstanceFactory.cpp +++ b/LLVM/source/CompilerInstanceFactory.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include #include @@ -214,6 +216,7 @@ namespace rg3::llvm #endif pOutInstance->setInvocation(invocation); + pOutInstance->createPreprocessor(clang::TranslationUnitKind::TU_Complete); // Set up FrontendOptions clang::FrontendOptions &opts = pOutInstance->getFrontendOpts(); @@ -285,5 +288,6 @@ namespace rg3::llvm assert(pOutInstance->hasDiagnostics() && "Diagnostics not set up!"); assert(pOutInstance->hasTarget() && "Target not set up!"); assert(pOutInstance->hasFileManager() && "FileManager not set up!"); + assert(pOutInstance->hasPreprocessor() && "Preprocessor not set up!"); } } \ No newline at end of file diff --git a/Protobuf/CMakeLists.txt b/Protobuf/CMakeLists.txt index b5c3dbe..65f706d 100644 --- a/Protobuf/CMakeLists.txt +++ b/Protobuf/CMakeLists.txt @@ -12,9 +12,9 @@ find_package(Boost COMPONENTS filesystem REQUIRED HINTS $ENV{Boost_ROOT}) # ------- Protobuf # Required to have Protobuf_DIR, absl_DIR and utf8_range_DIR -find_package(absl REQUIRED CONFIG HINTS $ENV{absl_DIR}) -find_package(utf8_range REQUIRED CONFIG HINTS $ENV{utf8_range_DIR}) -find_package(Protobuf REQUIRED CONFIG HINTS $ENV{Protobuf_DIR}) +find_package(absl REQUIRED HINTS $ENV{absl_DIR}) +find_package(utf8_range REQUIRED HINTS $ENV{utf8_range_DIR}) +find_package(Protobuf REQUIRED HINTS $ENV{Protobuf_DIR}) message(STATUS "Found Protobuf ${Protobuf_VERSION} (${Protobuf_DIR})") diff --git a/Protobuf/include/RG3/Protobuf/Enum.h b/Protobuf/include/RG3/Protobuf/Enum.h new file mode 100644 index 0000000..0a37c99 --- /dev/null +++ b/Protobuf/include/RG3/Protobuf/Enum.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include +#include +#include + + +namespace rg3::pb +{ + struct EnumEntry + { + std::string sName {}; + std::int64_t iValue { 0 }; + }; + + using EnumEntriesVector = std::vector; + + class Enum : public boost::noncopyable + { + public: + using Ptr = boost::shared_ptr; + + public: + Enum(); + Enum(const std::string& sName, const std::string& sPackage, const EnumEntriesVector& aEntries); + + [[nodiscard]] const std::string& getName() const; + [[nodiscard]] const std::string& getPackage() const; + [[nodiscard]] const EnumEntriesVector& getEntries() const; + + private: + std::string m_sName {}; + std::string m_sPackage {}; + EnumEntriesVector m_aEntries {}; + }; +} \ No newline at end of file diff --git a/Protobuf/include/RG3/Protobuf/Location.h b/Protobuf/include/RG3/Protobuf/Location.h new file mode 100644 index 0000000..4a794a4 --- /dev/null +++ b/Protobuf/include/RG3/Protobuf/Location.h @@ -0,0 +1,14 @@ +#pragma once + +#include + + +namespace rg3::pb +{ + struct Location + { + std::string sFile {}; + int iLine { 0 }; + int iColumn { 0 }; + }; +} \ No newline at end of file diff --git a/Protobuf/include/RG3/Protobuf/Message.h b/Protobuf/include/RG3/Protobuf/Message.h new file mode 100644 index 0000000..ab429f4 --- /dev/null +++ b/Protobuf/include/RG3/Protobuf/Message.h @@ -0,0 +1,36 @@ +#pragma once + +#include + +#include +#include +#include +#include + + +namespace rg3::pb +{ + struct MessageField + { + std::string sName {}; + int iIndex { 0 }; + /// TYPE + }; + + using MessageFieldVector = std::vector; + + class Message : public boost::noncopyable + { + public: + using Ptr = boost::shared_ptr; + + public: + Message(); + Message(const std::string& sName, const Location& sLocation, const MessageFieldVector& vFields); + + private: + std::string m_sName {}; + Location m_sLocation {}; + MessageFieldVector m_aFields {}; + }; +} \ No newline at end of file diff --git a/Protobuf/include/RG3/Protobuf/Service.h b/Protobuf/include/RG3/Protobuf/Service.h new file mode 100644 index 0000000..f90d3e7 --- /dev/null +++ b/Protobuf/include/RG3/Protobuf/Service.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include + + +namespace rg3::pb +{ + struct ServiceMethod + { + std::string sName {}; + bool bClientStreaming { false }; + bool bServerStreaming { false }; + + // INPUT TYPE + // OUTPUT TYPE + }; + + using ServiceMethodsVector = std::vector; + + class Service : public boost::noncopyable + { + public: + Service(); + Service(const std::string& sName, const std::string& sPackage, const ServiceMethodsVector& aMethods); + }; +} \ No newline at end of file diff --git a/Protobuf/source/Enum.cpp b/Protobuf/source/Enum.cpp new file mode 100644 index 0000000..3fbac1e --- /dev/null +++ b/Protobuf/source/Enum.cpp @@ -0,0 +1,7 @@ +#include + + +namespace rg3::pb +{ + +} \ No newline at end of file diff --git a/Protobuf/source/ProtobufAnalyzer.cpp b/Protobuf/source/ProtobufAnalyzer.cpp index 9e02082..6e63ba6 100644 --- a/Protobuf/source/ProtobufAnalyzer.cpp +++ b/Protobuf/source/ProtobufAnalyzer.cpp @@ -2,10 +2,17 @@ #include #include +#include +#include +#include +#include + +#include #include #include #include +#include #include @@ -73,6 +80,26 @@ namespace rg3::pb } }; + struct InMemoryOutputDirectory : google::protobuf::compiler::OutputDirectory + { + std::unordered_map mFiles; + + // Write a file + google::protobuf::io::ZeroCopyOutputStream* Open(const std::string& filename) override + { + auto& fileContent = mFiles[filename]; + fileContent.clear(); // Clear existing content + return new google::protobuf::io::StringOutputStream(&fileContent); + } + + // Write a file for appending (not used in this example) + google::protobuf::io::ZeroCopyOutputStream* OpenForAppend(const std::string& filename) override + { + auto& fileContent = mFiles[filename]; + return new google::protobuf::io::StringOutputStream(&fileContent); + } + }; + template constexpr bool always_false_v = false; std::pair, std::string> getStream(const ProtobufAnalyzer::CodeSource& source) { @@ -137,6 +164,43 @@ namespace rg3::pb return false; } + // Messages +// for (int i = 0; i < pFileDescriptor->message_type_count(); i++) +// { +// // Need to check for userspace options (there are tags in our interpertation) +// const auto* pMessageType = pFileDescriptor->message_type(i); +// const auto& sPackage = pFileDescriptor->package().c_str(); +// } +// +// // Enumerations +// for (int i = 0; i < pFileDescriptor->enum_type_count(); i++) +// { +// //pFileDescriptor->enum_type(i)->value(x) +// } +// +// // Services + for (int i = 0; i < pFileDescriptor->service_count(); i++) + { + //pFileDescriptor->service(0)->method(0)->input_type() + //pFileDescriptor->service(i)->name() + } + + // Run codegen (example, not final code) +// google::protobuf::compiler::cpp::CppGenerator sCppGenerator{}; +// InMemoryOutputDirectory sOutputDirectory{}; +// +// const std::string sCliCommand {}; +// +// // Generate C++ code +// std::string error; +// if (!sCppGenerator.Generate(pFileDescriptor, sCliCommand, &sOutputDirectory, &error)) { +// CompilerIssue& sIssue = m_aIssues.emplace_back(); +// sIssue.iLine = 0; +// sIssue.iColumn = 0; +// sIssue.sMessage = error; +// sIssue.eKind = IssueKind::IK_ERROR; +// } + // Done return std::count_if(m_aIssues.begin(), m_aIssues.end(), [](const CompilerIssue& sIssue) -> bool { return sIssue.eKind == IssueKind::IK_ERROR; }) == 0; } diff --git a/Tests/Unit/source/Tests_Enum.cpp b/Tests/Unit/source/Tests_Enum.cpp index 0140b6d..78e297d 100644 --- a/Tests/Unit/source/Tests_Enum.cpp +++ b/Tests/Unit/source/Tests_Enum.cpp @@ -282,4 +282,18 @@ namespace core ASSERT_EQ(asEnum1->getEntries().size(), 2); ASSERT_EQ(asEnum1->getEntries()[0].sName, "PT_ADMIN"); ASSERT_EQ(asEnum1->getEntries()[1].sName, "PT_USER"); +} + +TEST_F(Tests_Enum, CheckCustomProtoInclude) +{ + g_Analyzer->setSourceCode(R"( +#proto_include +)"); + + auto& compilerConfig = g_Analyzer->getCompilerConfig(); + compilerConfig.cppStandard = rg3::llvm::CxxStandard::CC_20; + + const auto analyzeResult = g_Analyzer->analyze(); + + //ASSERT_EQ(analyzeResult.vIssues.size(), 0); } \ No newline at end of file