Skip to content

Commit 943fd42

Browse files
Feat: Kafka C++ (#1)
* feat: Kafka Cpp * chore: moved the binaries around to an addon setup. * chore: implementation. * chore: separated kafka wrapper api into library, made a test app and exposed the wrapper to the godot library. * fix: consumer thread lifetime. * feat: implemented kafka multiplayer peer. * chore: delete dead files. * chore: logging.
1 parent 0f49e5c commit 943fd42

30 files changed

+2452
-111
lines changed

.gitignore

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,19 @@
33

44
*.sln.lnk
55

6-
# Godot 4+ specific ignores
7-
.godot/
6+
# Locks
7+
/*.lock
88

9-
# Ignore library files but not the gdextension file
10-
demo/client/bin/*
11-
!demo/client/bin/android
12-
demo/client/bin/android/*
13-
!demo/client/bin/android/.gitkeep
14-
!demo/client/bin/linux
15-
demo/client/bin/linux/*
16-
!demo/client/bin/linux/.gitkeep
17-
!demo/client/bin/macos
18-
demo/client/bin/macos/*
19-
!demo/client/bin/macos/.gitkeep
20-
!demo/client/bin/windows
21-
demo/client/bin/windows/*
22-
!demo/client/bin/windows/.gitkeep
23-
!demo/client/bin/*.gdextension
9+
# scons db
2410
.sconsign*.dblite
2511

26-
# Ignore custom.py
27-
custom.py
12+
# Rust
13+
/target/
2814

29-
# Ignore generated compile_commands.json
30-
compile_commands.json
15+
# Exports
16+
export/*
17+
!export/client/.gitkeep
18+
!export/server/.gitkeep
3119

32-
# Binaries
33-
*.o
34-
*.os
35-
*.so
36-
*.obj
37-
*.bc
38-
*.pyc
39-
*.dblite
40-
*.pdb
41-
*.lib
42-
*.config
43-
*.creator
44-
*.creator.user
45-
*.files
46-
*.includes
47-
*.idb
48-
*.exp
49-
50-
# Other stuff
51-
*.log
52-
53-
# VSCode
54-
.vscode/*
55-
!.vscode/extensions.json
56-
.DS_Store
20+
# C++
21+
*.obj

.vscode/launch.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"preLaunchTask": "CMake: build",
11+
"name": "Debug GodotKafka",
12+
"program": "${workspaceFolder}/godot-editor/Godot_v4.3-stable_win64.exe",
13+
"args": [
14+
"--debug",
15+
"--path",
16+
"${workspaceFolder}/demo/client"
17+
],
18+
"cwd": "${workspaceFolder}",
19+
},
20+
// {
21+
// "name": "Debug GodotKafka",
22+
// "type": "godot",
23+
// "request": "launch",
24+
// "project": "${workspaceFolder}/demo/client",
25+
// "scene": "main",
26+
// "editor_path": "${workspaceFolder}/godot-editor/Godot_v4.3-stable_win64.exe",
27+
// "profiling": false,
28+
// "single_threaded_scene": false,
29+
// "debug_avoidance": false,
30+
// "debug_navigation": false,
31+
// "debug_collisions": false,
32+
// "debug_paths": false,
33+
// "debug_stringnames": false,
34+
// "frame_delay": 0,
35+
// "time_scale": 1.0,
36+
// "disable_vsync": false,
37+
// "fixed_fps": 60,
38+
// "additional_options": ""
39+
// },
40+
{
41+
"type": "lldb",
42+
"request": "launch",
43+
"name": "Debug executable 'rust-example'",
44+
"cargo": {
45+
"args": [
46+
"build",
47+
"--bin=rust-example",
48+
"--package=rust-example"
49+
],
50+
"filter": {
51+
"name": "rust-example",
52+
"kind": "bin"
53+
}
54+
},
55+
"args": [],
56+
"cwd": "${workspaceFolder}"
57+
},
58+
{
59+
"type": "lldb",
60+
"request": "launch",
61+
"name": "Debug unit tests in executable 'rust-example'",
62+
"cargo": {
63+
"args": [
64+
"test",
65+
"--no-run",
66+
"--bin=rust-example",
67+
"--package=rust-example"
68+
],
69+
"filter": {
70+
"name": "rust-example",
71+
"kind": "bin"
72+
}
73+
},
74+
"args": [],
75+
"cwd": "${workspaceFolder}"
76+
}
77+
]
78+
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"godotTools.editorPath.godot4": "d:\\Workspace\\_Personal\\godot-kafka-multiplayer-peer\\godot-editor\\Godot_v4.3-stable_win64.exe"
3+
}

.vscode/tasks.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
// {
5+
// "label": "CMake: configure",
6+
// "type": "shell",
7+
// "command": "cmake -DCMAKE_BUILD_TYPE=Debug ../..",
8+
// "options": {
9+
// "cwd": "${workspaceFolder}/.sln/Debug"
10+
// },
11+
// },
12+
{
13+
// "dependsOn": "CMake: configure",
14+
"label": "CMake: build",
15+
"type": "shell",
16+
"command": "cmake --build .",
17+
"options": {
18+
"cwd": "${workspaceFolder}/.sln/Debug"
19+
},
20+
}
21+
]
22+
}

CMakeLists.txt

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ project(
55
LANGUAGES CXX
66
)
77

8+
option(BUILD_TESTS "Build the tests" ON)
9+
810
# Generate the project files
911
# execute_process(
1012
# COMMAND scons
@@ -23,30 +25,81 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
2325
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "External/CMake")
2426

2527
# Output the binaries to the bin folder
26-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$<1:${PROJECT_SOURCE_DIR}/demo/client/bin/${CMAKE_SYSTEM_NAME}>")
27-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$<1:${PROJECT_SOURCE_DIR}/demo/server/bin/${CMAKE_SYSTEM_NAME}>")
28+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$<1:${PROJECT_SOURCE_DIR}/demo/client/addons/gdkafka/bin/${CMAKE_SYSTEM_NAME}>")
29+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$<1:${PROJECT_SOURCE_DIR}/demo/server/addons/gdkafka/bin/${CMAKE_SYSTEM_NAME}>")
2830

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

3234
# Glob all sources files.
33-
file(GLOB_RECURSE SOURCES "src/*.cpp")
34-
file(GLOB_RECURSE HEADERS "src/*.hpp" "src/*.h")
35+
file(GLOB_RECURSE GODOT_SOURCES "src/godotkafka/*.cpp")
36+
file(GLOB_RECURSE GODOT_HEADERS "src/godotkafka/*.hpp" "src/godotkafka/*.h")
37+
file(GLOB_RECURSE TEST_SOURCES "src/test/*.cpp")
38+
file(GLOB_RECURSE TEST_HEADERS "src/test/*.hpp" "src/test/*.h")
39+
file(GLOB_RECURSE LIB_SOURCES "src/kafkalib/*.cpp")
40+
file(GLOB_RECURSE LIB_HEADERS "src/kafkalib/*.hpp" "src/kafkalib/*.h" "include/kafkalib/*.hpp" "include/kafkalib/*.h")
41+
42+
# Include OpenSSL
43+
set(OPENSSL_USE_STATIC_LIBS TRUE)
44+
find_package(OpenSSL REQUIRED)
45+
set(system_library_extension "lib")
46+
if (UNIX)
47+
set(system_library_extension "a")
48+
endif()
49+
find_library(CRYPTO_LIB libcrypto.${system_library_extension} REQUIRED)
50+
find_library(SSL_LIB libssl.${system_library_extension} REQUIRED)
51+
52+
if(OPENSSL_FOUND)
53+
message(STATUS "Found OpenSSL: ${OPENSSL_VERSION}")
54+
include_directories(${OPENSSL_INCLUDE_DIR})
55+
link_libraries(OpenSSL::Crypto)
56+
endif()
57+
58+
if (CRYPTO_LIB)
59+
message(STATUS "Found libcrypto: ${CRYPTO_LIB}")
60+
link_libraries(${CRYPTO_LIB})
61+
endif()
62+
63+
if (SSL_LIB)
64+
message(STATUS "Found libssl: ${SSL_LIB}")
65+
link_libraries(${SSL_LIB})
66+
endif()
67+
68+
add_library(KafkaLib STATIC
69+
${LIB_SOURCES}
70+
${LIB_HEADERS}
71+
)
72+
target_include_directories(KafkaLib PUBLIC include/kafkalib)
3573

3674
add_library(GodotKafka SHARED
37-
${SOURCES}
38-
${HEADERS}
75+
${GODOT_SOURCES}
76+
${GODOT_HEADERS}
3977
)
4078

4179
# Include Godot::cpp
4280
add_subdirectory(godot-cpp)
4381
target_link_libraries(GodotKafka PRIVATE godot::cpp)
82+
target_link_libraries(GodotKafka PRIVATE KafkaLib)
4483
set_target_properties(godot-cpp PROPERTIES FOLDER "External/Godot")
4584

4685
# Include librdkafka
4786
set(RDKAFKA_BUILD_EXAMPLES OFF)
4887
set(RDKAFKA_BUILD_TESTS OFF)
88+
set(RDKAFKA_BUILD_STATIC ON)
4989
add_subdirectory(extern/librdkafka)
50-
target_link_libraries(GodotKafka PRIVATE rdkafka)
90+
target_link_libraries(KafkaLib PUBLIC rdkafka) # rdkafka is the C library and the core.
91+
target_link_libraries(KafkaLib PUBLIC rdkafka++) # rdkafka++ is a C++ wrapper around librdkafka
5192
set_target_properties(rdkafka PROPERTIES FOLDER "External/rdkafka")
52-
set_target_properties(rdkafka++ PROPERTIES FOLDER "External/rdkafka")
93+
set_target_properties(rdkafka++ PROPERTIES FOLDER "External/rdkafka")
94+
95+
if (BUILD_TESTS)
96+
add_executable(TestKafkaLib
97+
${TEST_SOURCES}
98+
${TEST_HEADERS}
99+
)
100+
101+
target_link_libraries(TestKafkaLib PRIVATE KafkaLib)
102+
103+
# Force Visual Studio to set this target as the startup project
104+
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT TestKafkaLib)
105+
endif()

compose.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
version: '3.8'
2+
networks:
3+
redpanda_network:
4+
driver: host
5+
volumes:
6+
redpanda-0: null
7+
services:
8+
9+
redpanda-0:
10+
command:
11+
- redpanda
12+
- start
13+
- --kafka-addr internal://0.0.0.0:9092,external://0.0.0.0:19092
14+
# Address the broker advertises to clients that connect to the Kafka API.
15+
# Use the internal addresses to connect to the Redpanda brokers'
16+
# from inside the same Docker network.
17+
# Use the external addresses to connect to the Redpanda brokers'
18+
# from outside the Docker network.
19+
- --advertise-kafka-addr internal://redpanda-0:9092,external://localhost:19092
20+
- --pandaproxy-addr internal://0.0.0.0:8082,external://0.0.0.0:18082
21+
# Address the broker advertises to clients that connect to the HTTP Proxy.
22+
- --advertise-pandaproxy-addr internal://redpanda-0:8082,external://localhost:18082
23+
- --schema-registry-addr internal://0.0.0.0:8081,external://0.0.0.0:18081
24+
# Redpanda brokers use the RPC API to communicate with each other internally.
25+
- --rpc-addr redpanda-0:33145
26+
- --advertise-rpc-addr redpanda-0:33145
27+
# Mode dev-container uses well-known configuration properties for development in containers.
28+
- --mode dev-container
29+
# Tells Seastar (the framework Redpanda uses under the hood) to use 1 core on the system.
30+
- --smp 1
31+
- --default-log-level=info
32+
image: docker.redpanda.com/redpandadata/redpanda:v24.2.4
33+
container_name: redpanda-0
34+
volumes:
35+
- redpanda-0:/var/lib/redpanda/data
36+
networks:
37+
- redpanda_network
38+
ports:
39+
- 18081:18081
40+
- 18082:18082
41+
- 19092:19092
42+
- 19644:9644
43+
console:
44+
container_name: redpanda-console
45+
image: docker.redpanda.com/redpandadata/console:v2.7.1
46+
networks:
47+
- redpanda_network
48+
entrypoint: /bin/sh
49+
command: -c 'echo "$$CONSOLE_CONFIG_FILE" > /tmp/config.yml; /app/console'
50+
environment:
51+
CONFIG_FILEPATH: /tmp/config.yml
52+
CONSOLE_CONFIG_FILE: |
53+
kafka:
54+
brokers: ["redpanda-0:9092"]
55+
schemaRegistry:
56+
enabled: true
57+
urls: ["http://redpanda-0:8081"]
58+
redpanda:
59+
adminApi:
60+
enabled: true
61+
urls: ["http://redpanda-0:9644"]
62+
ports:
63+
- 8080:8080
64+
depends_on:
65+
- redpanda-0
66+
67+
# rust-example:
68+
# build:
69+
# context: ./demo/server/rust-example
70+
# dockerfile: Dockerfile
71+
# ports:
72+
# - 8000:8000

0 commit comments

Comments
 (0)