Skip to content

Feat: Kafka C++ #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 13, 2024
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
57 changes: 11 additions & 46 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,19 @@

*.sln.lnk

# Godot 4+ specific ignores
.godot/
# Locks
/*.lock

# Ignore library files but not the gdextension file
demo/client/bin/*
!demo/client/bin/android
demo/client/bin/android/*
!demo/client/bin/android/.gitkeep
!demo/client/bin/linux
demo/client/bin/linux/*
!demo/client/bin/linux/.gitkeep
!demo/client/bin/macos
demo/client/bin/macos/*
!demo/client/bin/macos/.gitkeep
!demo/client/bin/windows
demo/client/bin/windows/*
!demo/client/bin/windows/.gitkeep
!demo/client/bin/*.gdextension
# scons db
.sconsign*.dblite

# Ignore custom.py
custom.py
# Rust
/target/

# Ignore generated compile_commands.json
compile_commands.json
# Exports
export/*
!export/client/.gitkeep
!export/server/.gitkeep

# Binaries
*.o
*.os
*.so
*.obj
*.bc
*.pyc
*.dblite
*.pdb
*.lib
*.config
*.creator
*.creator.user
*.files
*.includes
*.idb
*.exp

# Other stuff
*.log

# VSCode
.vscode/*
!.vscode/extensions.json
.DS_Store
# C++
*.obj
78 changes: 78 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"preLaunchTask": "CMake: build",
"name": "Debug GodotKafka",
"program": "${workspaceFolder}/godot-editor/Godot_v4.3-stable_win64.exe",
"args": [
"--debug",
"--path",
"${workspaceFolder}/demo/client"
],
"cwd": "${workspaceFolder}",
},
// {
// "name": "Debug GodotKafka",
// "type": "godot",
// "request": "launch",
// "project": "${workspaceFolder}/demo/client",
// "scene": "main",
// "editor_path": "${workspaceFolder}/godot-editor/Godot_v4.3-stable_win64.exe",
// "profiling": false,
// "single_threaded_scene": false,
// "debug_avoidance": false,
// "debug_navigation": false,
// "debug_collisions": false,
// "debug_paths": false,
// "debug_stringnames": false,
// "frame_delay": 0,
// "time_scale": 1.0,
// "disable_vsync": false,
// "fixed_fps": 60,
// "additional_options": ""
// },
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'rust-example'",
"cargo": {
"args": [
"build",
"--bin=rust-example",
"--package=rust-example"
],
"filter": {
"name": "rust-example",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'rust-example'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=rust-example",
"--package=rust-example"
],
"filter": {
"name": "rust-example",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"godotTools.editorPath.godot4": "d:\\Workspace\\_Personal\\godot-kafka-multiplayer-peer\\godot-editor\\Godot_v4.3-stable_win64.exe"
}
22 changes: 22 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": "2.0.0",
"tasks": [
// {
// "label": "CMake: configure",
// "type": "shell",
// "command": "cmake -DCMAKE_BUILD_TYPE=Debug ../..",
// "options": {
// "cwd": "${workspaceFolder}/.sln/Debug"
// },
// },
{
// "dependsOn": "CMake: configure",
"label": "CMake: build",
"type": "shell",
"command": "cmake --build .",
"options": {
"cwd": "${workspaceFolder}/.sln/Debug"
},
}
]
}
69 changes: 61 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ project(
LANGUAGES CXX
)

option(BUILD_TESTS "Build the tests" ON)

# Generate the project files
# execute_process(
# COMMAND scons
Expand All @@ -23,30 +25,81 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "External/CMake")

# Output the binaries to the bin folder
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$<1:${PROJECT_SOURCE_DIR}/demo/client/bin/${CMAKE_SYSTEM_NAME}>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$<1:${PROJECT_SOURCE_DIR}/demo/server/bin/${CMAKE_SYSTEM_NAME}>")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$<1:${PROJECT_SOURCE_DIR}/demo/client/addons/gdkafka/bin/${CMAKE_SYSTEM_NAME}>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$<1:${PROJECT_SOURCE_DIR}/demo/server/addons/gdkafka/bin/${CMAKE_SYSTEM_NAME}>")

# Prefix all the binaries with "lib"
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")

# Glob all sources files.
file(GLOB_RECURSE SOURCES "src/*.cpp")
file(GLOB_RECURSE HEADERS "src/*.hpp" "src/*.h")
file(GLOB_RECURSE GODOT_SOURCES "src/godotkafka/*.cpp")
file(GLOB_RECURSE GODOT_HEADERS "src/godotkafka/*.hpp" "src/godotkafka/*.h")
file(GLOB_RECURSE TEST_SOURCES "src/test/*.cpp")
file(GLOB_RECURSE TEST_HEADERS "src/test/*.hpp" "src/test/*.h")
file(GLOB_RECURSE LIB_SOURCES "src/kafkalib/*.cpp")
file(GLOB_RECURSE LIB_HEADERS "src/kafkalib/*.hpp" "src/kafkalib/*.h" "include/kafkalib/*.hpp" "include/kafkalib/*.h")

# Include OpenSSL
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
set(system_library_extension "lib")
if (UNIX)
set(system_library_extension "a")
endif()
find_library(CRYPTO_LIB libcrypto.${system_library_extension} REQUIRED)
find_library(SSL_LIB libssl.${system_library_extension} REQUIRED)

if(OPENSSL_FOUND)
message(STATUS "Found OpenSSL: ${OPENSSL_VERSION}")
include_directories(${OPENSSL_INCLUDE_DIR})
link_libraries(OpenSSL::Crypto)
endif()

if (CRYPTO_LIB)
message(STATUS "Found libcrypto: ${CRYPTO_LIB}")
link_libraries(${CRYPTO_LIB})
endif()

if (SSL_LIB)
message(STATUS "Found libssl: ${SSL_LIB}")
link_libraries(${SSL_LIB})
endif()

add_library(KafkaLib STATIC
${LIB_SOURCES}
${LIB_HEADERS}
)
target_include_directories(KafkaLib PUBLIC include/kafkalib)

add_library(GodotKafka SHARED
${SOURCES}
${HEADERS}
${GODOT_SOURCES}
${GODOT_HEADERS}
)

# Include Godot::cpp
add_subdirectory(godot-cpp)
target_link_libraries(GodotKafka PRIVATE godot::cpp)
target_link_libraries(GodotKafka PRIVATE KafkaLib)
set_target_properties(godot-cpp PROPERTIES FOLDER "External/Godot")

# Include librdkafka
set(RDKAFKA_BUILD_EXAMPLES OFF)
set(RDKAFKA_BUILD_TESTS OFF)
set(RDKAFKA_BUILD_STATIC ON)
add_subdirectory(extern/librdkafka)
target_link_libraries(GodotKafka PRIVATE rdkafka)
target_link_libraries(KafkaLib PUBLIC rdkafka) # rdkafka is the C library and the core.
target_link_libraries(KafkaLib PUBLIC rdkafka++) # rdkafka++ is a C++ wrapper around librdkafka
set_target_properties(rdkafka PROPERTIES FOLDER "External/rdkafka")
set_target_properties(rdkafka++ PROPERTIES FOLDER "External/rdkafka")
set_target_properties(rdkafka++ PROPERTIES FOLDER "External/rdkafka")

if (BUILD_TESTS)
add_executable(TestKafkaLib
${TEST_SOURCES}
${TEST_HEADERS}
)

target_link_libraries(TestKafkaLib PRIVATE KafkaLib)

# Force Visual Studio to set this target as the startup project
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT TestKafkaLib)
endif()
72 changes: 72 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
version: '3.8'
networks:
redpanda_network:
driver: host
volumes:
redpanda-0: null
services:

redpanda-0:
command:
- redpanda
- start
- --kafka-addr internal://0.0.0.0:9092,external://0.0.0.0:19092
# Address the broker advertises to clients that connect to the Kafka API.
# Use the internal addresses to connect to the Redpanda brokers'
# from inside the same Docker network.
# Use the external addresses to connect to the Redpanda brokers'
# from outside the Docker network.
- --advertise-kafka-addr internal://redpanda-0:9092,external://localhost:19092
- --pandaproxy-addr internal://0.0.0.0:8082,external://0.0.0.0:18082
# Address the broker advertises to clients that connect to the HTTP Proxy.
- --advertise-pandaproxy-addr internal://redpanda-0:8082,external://localhost:18082
- --schema-registry-addr internal://0.0.0.0:8081,external://0.0.0.0:18081
# Redpanda brokers use the RPC API to communicate with each other internally.
- --rpc-addr redpanda-0:33145
- --advertise-rpc-addr redpanda-0:33145
# Mode dev-container uses well-known configuration properties for development in containers.
- --mode dev-container
# Tells Seastar (the framework Redpanda uses under the hood) to use 1 core on the system.
- --smp 1
- --default-log-level=info
image: docker.redpanda.com/redpandadata/redpanda:v24.2.4
container_name: redpanda-0
volumes:
- redpanda-0:/var/lib/redpanda/data
networks:
- redpanda_network
ports:
- 18081:18081
- 18082:18082
- 19092:19092
- 19644:9644
console:
container_name: redpanda-console
image: docker.redpanda.com/redpandadata/console:v2.7.1
networks:
- redpanda_network
entrypoint: /bin/sh
command: -c 'echo "$$CONSOLE_CONFIG_FILE" > /tmp/config.yml; /app/console'
environment:
CONFIG_FILEPATH: /tmp/config.yml
CONSOLE_CONFIG_FILE: |
kafka:
brokers: ["redpanda-0:9092"]
schemaRegistry:
enabled: true
urls: ["http://redpanda-0:8081"]
redpanda:
adminApi:
enabled: true
urls: ["http://redpanda-0:9644"]
ports:
- 8080:8080
depends_on:
- redpanda-0

# rust-example:
# build:
# context: ./demo/server/rust-example
# dockerfile: Dockerfile
# ports:
# - 8000:8000
Loading