Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

21 changes: 19 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,31 @@
*.dwo

*.env
*.log

# IDE
.vscode/
.idea/
*.swp
*.swo

# CMake build folder
/build/
*.o
*.obj
*.exe
*.dll
*.so
*.log
build/
cmake-build-*/

# Conan
.conan2/
conan.lock

# CMake user presets
CMakeUserPresets.json

external/
external/tsl-hat-trie/

.proto
131 changes: 116 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,149 @@
cmake_minimum_required(VERSION 3.20)
project(moderation-service)
set(CMAKE_CXX_STANDARD 17)

find_package(Protobuf REQUIRED)
find_package(gRPC REQUIRED)
#find_package(utf8_range REQUIRED)
if(MSVC)
add_compile_options(/utf-8)
endif()

# set necessary variables for genproto lib target
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)

if(WIN32)
add_definitions(-D_WIN32_WINNT=0x0A00)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_compile_definitions(U_STATIC_IMPLEMENTATION)
endif()

include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake OPTIONAL)

find_package(Protobuf REQUIRED CONFIG)
find_package(gRPC REQUIRED CONFIG)
find_package(ICU REQUIRED COMPONENTS uc i18n data)
find_package(Threads REQUIRED)

set(CPM_DOWNLOAD_VERSION 0.40.2)
if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endif()

include(${CPM_DOWNLOAD_LOCATION})

CPMAddPackage(
NAME tsl-hat-trie
GITHUB_REPOSITORY Tessil/hat-trie
VERSION 0.6.0
)

# Set necessary variables for genproto lib target
set(GENPROTO_LIB "genproto_lib")
set(GENPROTO_DIR "${PROJECT_SOURCE_DIR}/src/moderationservice/grpc")
set(GENPROTO_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated/grpc")
set(PROTO_FILE "${CMAKE_CURRENT_SOURCE_DIR}/.proto/moderation.proto")

# loop through genproto dir
file(GLOB_RECURSE PROTO_SRC "${GENPROTO_DIR}/*.pb.cc")
file(GLOB_RECURSE PROTO_HDR "${GENPROTO_DIR}/*.pb.h")
# Create output directory for generated files
file(MAKE_DIRECTORY ${GENPROTO_DIR})

add_library(${GENPROTO_LIB} ${PROTO_SRC} ${PROTO_HDR})
# Define generated file paths
set(PROTO_SRCS "${GENPROTO_DIR}/moderation.pb.cc")
set(PROTO_HDRS "${GENPROTO_DIR}/moderation.pb.h")
set(GRPC_SRCS "${GENPROTO_DIR}/moderation.grpc.pb.cc")
set(GRPC_HDRS "${GENPROTO_DIR}/moderation.grpc.pb.h")

target_link_libraries(${GENPROTO_LIB}
PUBLIC
gRPC::grpc++
protobuf::libprotobuf
#utf8_range::utf8_range
#utf8_range::utf8_validity
# Generate protobuf files using custom command
add_custom_command(
OUTPUT ${PROTO_SRCS} ${PROTO_HDRS}
COMMAND $<TARGET_FILE:protobuf::protoc>
ARGS --proto_path=${CMAKE_CURRENT_SOURCE_DIR}/.proto
--cpp_out=${GENPROTO_DIR}
${PROTO_FILE}
DEPENDS ${PROTO_FILE}
COMMENT "Generating protobuf files"
)

# Generate gRPC files using custom command
add_custom_command(
OUTPUT ${GRPC_SRCS} ${GRPC_HDRS}
COMMAND $<TARGET_FILE:protobuf::protoc>
ARGS --proto_path=${CMAKE_CURRENT_SOURCE_DIR}/.proto
--grpc_out=${GENPROTO_DIR}
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
${PROTO_FILE}
DEPENDS ${PROTO_FILE} ${PROTO_HDRS}
COMMENT "Generating gRPC files"
)

# Create library from generated sources
add_library(${GENPROTO_LIB}
${PROTO_SRCS}
${PROTO_HDRS}
${GRPC_SRCS}
${GRPC_HDRS}
)

target_include_directories(${GENPROTO_LIB}
PUBLIC
${GENPROTO_DIR}
${protobuf_INCLUDE_DIRS_RELEASE}
${abseil_INCLUDE_DIRS_RELEASE}
${grpc_INCLUDE_DIRS_RELEASE}
${icu_INCLUDE_DIRS_RELEASE}
)

target_link_libraries(${GENPROTO_LIB}
PUBLIC
protobuf::libprotobuf
gRPC::grpc++
)

#link source files
add_executable(${PROJECT_NAME}
src/moderationservice/main.cpp
src/moderationservice/server/server.cpp
src/moderationservice/service/service.cpp
src/moderationservice/service/text_normalization.cpp
src/moderationservice/service/leetspeak_normalization.cpp
src/moderationservice/service/word_checker.cpp
src/moderationservice/service/text_processor.cpp
src/moderationservice/model/constants.cpp
)

target_link_libraries(${PROJECT_NAME}
PRIVATE
${GENPROTO_LIB}
gRPC::grpc++
protobuf::libprotobuf
gRPC::grpc++_reflection
ICU::uc
ICU::i18n
ICU::data
tsl::hat_trie
Threads::Threads
)

if(WIN32)
target_compile_definitions(${PROJECT_NAME} PRIVATE U_STATIC_IMPLEMENTATION)
endif()

#link header files
target_include_directories(${PROJECT_NAME}
PUBLIC
${PROJECT_SOURCE_DIR}/include
PRIVATE
${PROJECT_SOURCE_DIR}/src/moderationservice/service
${PROJECT_SOURCE_DIR}/src/moderationservice/model
${GENPROTO_DIR}
)
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@


<img width="5573" height="6341" alt="Unbenannt-2025-10-16-0020(1)" src="https://github.com/user-attachments/assets/d9891188-500e-43e7-a8a3-6d11cbbd1d0e" />



To build and run you need the following installed:

-CMake
-Just
-Conan
-C++ compiler (gcc/clang/MSVC) (gcc recommended)
-curl
-sh/bash (Windows only)
-Internet connection
20 changes: 20 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[requires]
grpc/1.72.0
protobuf/5.27.0
icu/77.1

[generators]
CMakeDeps
CMakeToolchain

[options]
grpc/*:codegen=True
grpc/*:cpp_plugin=True
grpc/*:csharp_ext=False
grpc/*:csharp_plugin=False
grpc/*:node_plugin=False
grpc/*:objective_c_plugin=False
grpc/*:php_plugin=False
grpc/*:python_plugin=False
grpc/*:ruby_plugin=False
grpc/*:shared=False
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ LOAD_ENVS_URL := 'https://raw.githubusercontent.com/esclient/tools/refs/heads/ma
PROTO_TAG := 'v0.1.3'
PROTO_NAME := 'moderation.proto'
TMP_DIR := '.proto'
OUT_DIR := 'src/moderationservice/grpc'
SERVICE_NAME := 'moderation'

MKDIR_TOOLS := 'mkdir -p tools'
Expand Down
Empty file removed sonar-project.properties
Empty file.
86 changes: 0 additions & 86 deletions src/moderationservice/grpc/moderation.grpc.pb.cc

This file was deleted.

Loading