Skip to content

Commit b900f4f

Browse files
committed
chore: project setup.
1 parent 7924c6e commit b900f4f

File tree

6 files changed

+342
-7
lines changed

6 files changed

+342
-7
lines changed

CMakeLists.txt

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
cmake_minimum_required(VERSION 3.23)
2+
project(
3+
Godot-Kafka
4+
VERSION 0.1.0
5+
LANGUAGES CXX
6+
)
7+
8+
# Output System Information
9+
message(STATUS "CMake version: ${CMAKE_VERSION}")
10+
message(STATUS "CMake system name: ${CMAKE_SYSTEM_NAME}")
11+
message(STATUS "CMake system processor: ${CMAKE_SYSTEM_PROCESSOR}")
12+
13+
# Output Compiler Information for both C++ and C
14+
message(STATUS "C++ Compiler: ${CMAKE_CXX_COMPILER}")
15+
message(STATUS "C++ Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
16+
message(STATUS "C++ Compiler Version: ${CMAKE_CXX_COMPILER_VERSION}")
17+
18+
message(STATUS "C Compiler: ${CMAKE_C_COMPILER}")
19+
message(STATUS "C Compiler ID: ${CMAKE_C_COMPILER_ID}")
20+
message(STATUS "C Compiler Version: ${CMAKE_C_COMPILER_VERSION}")
21+
22+
23+
option(BUILD_TESTS "Build the tests" ON)
24+
25+
# Set the C++ standard to C++20
26+
set(CMAKE_CXX_STANDARD 20)
27+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
28+
set(CMAKE_CXX_EXTENSIONS OFF)
29+
30+
if (MSVC)
31+
add_compile_options(
32+
# Enable MTd (Multi-threaded Debug) for Debug builds
33+
$<$<CONFIG:Debug>:/MDd>
34+
# Enable MT (Multi-threaded) for Release builds
35+
$<$<NOT:$<CONFIG:Debug>>:/MDd>
36+
)
37+
endif()
38+
39+
# Use folders
40+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
41+
42+
# Set CMake Predefined Targets Folders
43+
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "External/CMake")
44+
45+
# Output the binaries to the bin folder
46+
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
47+
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER)
48+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} "${PROJECT_SOURCE_DIR}/.build/bin/${CMAKE_SYSTEM_NAME}/${OUTPUTCONFIG}")
49+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} "${PROJECT_SOURCE_DIR}/.build/bin/${CMAKE_SYSTEM_NAME}/${OUTPUTCONFIG}")
50+
endforeach()
51+
52+
# Prefix all the binaries with "lib"
53+
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
54+
if(WIN32)
55+
set(LIB_TYPE "dll")
56+
elseif(APPLE)
57+
set(LIB_TYPE "dylib")
58+
elseif(UNIX)
59+
set(LIB_TYPE "so")
60+
endif()
61+
set(CMAKE_SHARED_LIBRARY_SUFFIX ".${CMAKE_SYSTEM_NAME}.${CMAKE_HOST_SYSTEM_PROCESSOR}.${LIB_TYPE}") # Example: libGDKafka.Linux.x86_64.so for a Linux x86_64 system, or libGDKafka.Windows.AMD64.dll for a Windows AMD64 system.
62+
63+
# Glob all sources files.
64+
file(GLOB_RECURSE GODOT_SOURCES "project/src/*.cpp" "project/src/**/*.cpp")
65+
file(GLOB_RECURSE GODOT_HEADERS "project/includes/*.hpp" "project/includes/*.h" "project/includes/**/*.hpp" "project/includes/**/*.h")
66+
file(GLOB_RECURSE LIB_SOURCES "lib/src/*.cpp" "lib/src/**/*.cpp")
67+
file(GLOB_RECURSE LIB_HEADERS "lib/includes/*.hpp" "lib/includes/*.h" "lib/includes/**/*.hpp" "lib/includes/**/*.h")
68+
69+
# Set Preprocessor Definitions
70+
# Define preprocessor definitions based on build configuration using generator expressions
71+
add_compile_definitions(
72+
$<$<CONFIG:Debug>:_DEBUG>
73+
$<$<NOT:$<CONFIG:Debug>>:_NDEBUG>
74+
)
75+
76+
# Compiler -fPIC
77+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
78+
79+
# Include OpenSSL
80+
set(OPENSSL_USE_STATIC_LIBS TRUE CACHE BOOL "Use static OpenSSL libraries" FORCE)
81+
find_package(OpenSSL REQUIRED)
82+
set(system_library_extension "lib")
83+
84+
if(UNIX)
85+
set(system_library_extension "a")
86+
endif()
87+
88+
find_library(CRYPTO_LIB libcrypto.${system_library_extension} REQUIRED)
89+
find_library(SSL_LIB libssl.${system_library_extension} REQUIRED)
90+
91+
if(OPENSSL_FOUND)
92+
message(STATUS "Found OpenSSL: ${OPENSSL_VERSION}")
93+
include_directories(${OPENSSL_INCLUDE_DIR})
94+
link_libraries(OpenSSL::Crypto)
95+
endif()
96+
97+
if(CRYPTO_LIB)
98+
message(STATUS "Found libcrypto: ${CRYPTO_LIB}")
99+
link_libraries(${CRYPTO_LIB})
100+
endif()
101+
102+
if(SSL_LIB)
103+
message(STATUS "Found libssl: ${SSL_LIB}")
104+
link_libraries(${SSL_LIB})
105+
endif()
106+
107+
add_library(KafkaLib STATIC
108+
${LIB_SOURCES}
109+
${LIB_HEADERS}
110+
)
111+
target_include_directories(KafkaLib PUBLIC lib/includes)
112+
113+
add_library(GDKafka SHARED
114+
${GODOT_SOURCES}
115+
${GODOT_HEADERS}
116+
)
117+
target_include_directories(GDKafka PUBLIC
118+
project/includes
119+
)
120+
121+
# Include Godot::cpp
122+
set(GODOTCPP_DEBUG_CRT ON CACHE BOOL "Compile with MSVC's debug CRT (/MDd)" FORCE)
123+
add_subdirectory(extern/godot-cpp)
124+
target_link_libraries(GDKafka PRIVATE godot::cpp)
125+
target_link_libraries(GDKafka PRIVATE KafkaLib)
126+
set_target_properties(godot-cpp PROPERTIES FOLDER "External/Godot")
127+
128+
# Include librdkafka
129+
set(RDKAFKA_BUILD_EXAMPLES OFF CACHE BOOL "Disable building examples" FORCE)
130+
set(RDKAFKA_BUILD_TESTS OFF CACHE BOOL "Disable building examples" FORCE)
131+
set(RDKAFKA_BUILD_STATIC ON CACHE BOOL "Disable building examples" FORCE)
132+
add_subdirectory(extern/librdkafka)
133+
target_link_libraries(KafkaLib PUBLIC rdkafka) # rdkafka is the C library and the core.
134+
target_link_libraries(KafkaLib PUBLIC rdkafka++) # rdkafka++ is a C++ wrapper around librdkafka
135+
set_target_properties(rdkafka PROPERTIES FOLDER "External/rdkafka")
136+
set_target_properties(rdkafka++ PROPERTIES FOLDER "External/rdkafka")
137+
138+
139+
# Load Tests
140+
if(BUILD_TESTS)
141+
enable_testing()
142+
add_subdirectory(tests)
143+
message(STATUS "Tests are enabled")
144+
else()
145+
message(STATUS "Tests are disabled")
146+
endif()

SConstruct

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
import os
3+
4+
5+
def normalize_path(val, env):
6+
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
7+
8+
9+
def validate_parent_dir(key, val, env):
10+
if not os.path.isdir(normalize_path(os.path.dirname(val), env)):
11+
raise UserError("'%s' is not a directory: %s" % (key, os.path.dirname(val)))
12+
13+
14+
libname = "godot-kafka"
15+
projectdir = "demo/client"
16+
17+
localEnv = Environment(tools=["default"], PLATFORM="")
18+
19+
customs = ["custom.py"]
20+
customs = [os.path.abspath(path) for path in customs]
21+
22+
opts = Variables(customs, ARGUMENTS)
23+
opts.Add(
24+
BoolVariable(
25+
key="compiledb",
26+
help="Generate compilation DB (`compile_commands.json`) for external tools",
27+
default=localEnv.get("compiledb", False),
28+
)
29+
)
30+
opts.Add(
31+
PathVariable(
32+
key="compiledb_file",
33+
help="Path to a custom `compile_commands.json` file",
34+
default=localEnv.get("compiledb_file", "compile_commands.json"),
35+
validator=validate_parent_dir,
36+
)
37+
)
38+
opts.Update(localEnv)
39+
40+
Help(opts.GenerateHelpText(localEnv))
41+
42+
env = localEnv.Clone()
43+
env["compiledb"] = False
44+
45+
env.Tool("compilation_db")
46+
compilation_db = env.CompilationDatabase(
47+
normalize_path(localEnv["compiledb_file"], localEnv)
48+
)
49+
env.Alias("compiledb", compilation_db)
50+
51+
env = SConscript("extern/godot-cpp/SConstruct", {"env": env, "customs": customs})
52+
53+
env.Append(CPPPATH=["src/"])
54+
sources = Glob("src/*.cpp")
55+
56+
if env["target"] in ["editor", "template_debug"]:
57+
try:
58+
doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
59+
sources.append(doc_data)
60+
except AttributeError:
61+
print("Not including class reference as we're targeting a pre-4.3 baseline.")
62+
63+
file = "{}{}{}".format(libname, env["suffix"], env["SHLIBSUFFIX"])
64+
65+
if env["platform"] == "macos" or env["platform"] == "ios":
66+
platlibname = "{}.{}.{}".format(libname, env["platform"], env["target"])
67+
file = "{}.framework/{}".format(env["platform"], platlibname, platlibname)
68+
69+
libraryfile = "bin/{}/{}".format(env["platform"], file)
70+
library = env.SharedLibrary(
71+
libraryfile,
72+
source=sources,
73+
)
74+
75+
copy = env.InstallAs("{}/bin/{}/lib{}".format(projectdir, env["platform"], file), library)
76+
77+
default_args = [library, copy]
78+
if localEnv.get("compiledb", False):
79+
default_args += [compilation_db]
80+
Default(*default_args)

_build.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:: Setup Clang
2+
set CC=clang
3+
set CXX=clang++
4+
set buildType=Release
5+
6+
:: Run this script to build the project
7+
cmake -DCMAKE_BUILD_TYPE=%buildType% -B .sln -S . && cmake --build .sln --config %buildType%

_vs.bat

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@echo off
2+
3+
setlocal
4+
5+
:: Shutdown any Visual Studio instances that have Godot-Kafka in their MainWindowTitle
6+
for /f "tokens=2 delims=," %%i in ('tasklist /FI "IMAGENAME eq devenv.exe" /FO CSV /NH') do (
7+
powershell -Command "$process = Get-Process -Id %%i; if ($process.MainWindowTitle -like '*Godot-Kafka*') { $process.Kill(); Write-Host 'Killed process %%i with MainWindowTitle containing Godot-Kafka.' }"
8+
)
9+
10+
:: if exist .sln (
11+
:: @REM Delete the .sln folder
12+
:: rmdir /s /q .sln
13+
:: )
14+
:: if exist .build (
15+
:: @REM Delete the .build folder
16+
:: rmdir /s /q .build
17+
:: )
18+
19+
mkdir .sln
20+
mkdir ".sln"
21+
pushd ".sln"
22+
23+
cmake -G "Visual Studio 17 2022" ../
24+
if %ERRORLEVEL% neq 0 (
25+
echo CMake failed.
26+
pause
27+
exit /b %ERRORLEVEL%
28+
)
29+
30+
REM Create a shortcut to the .sln file
31+
set "shortcutName=Project.sln"
32+
set "targetPath=%~dp0.sln\Godot-Kafka.sln"
33+
set "shortcutPath=%~dp0%shortcutName%.lnk"
34+
35+
:: Delete the shortcut if it already exists
36+
if exist "%shortcutPath%" (
37+
del "%shortcutPath%"
38+
)
39+
40+
REM Check if the shortcut already exists
41+
if exist "%shortcutPath%" (
42+
echo Shortcut already exists.
43+
) else (
44+
echo Creating shortcut...
45+
powershell -Command "$WshShell = New-Object -ComObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut('%shortcutPath%'); $Shortcut.TargetPath = '%targetPath%'; $Shortcut.Save()"
46+
)
47+
48+
start %shortcutPath%
49+
50+
endlocal
51+
52+
exit /b

asset-description.md

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,58 @@
1-
This Godot Add-on makes exporting your game easier by providing necessary features into your export pipeline.
1+
Godot Kafka (GDKafka) Plugin
2+
=======================================
23

3-
Features:
4-
==============================
5-
* Asset Bundling
6-
Simplifies the process of bundling assets without the need for complex scripts or manual work. Simply the user will place files within the designated bundle directory under the bundles directory.
4+
This plugin provides a Godot interface to Kafka, allowing you to produce and consume messages in a Kafka cluster directly from your Godot projects.
75

8-
(More soon to come...)
6+
It is designed to be easy to use and integrate into your Godot applications, enabling real-time data processing and communication.
7+
8+
# Available Platforms
9+
✅ Windows
10+
✅ Linux
11+
❌ MacOSX - (Author doesn't have a macOS machine to test on, but it should work)
12+
❌ Android - Not planned
13+
❌ iOS - Not planned
14+
❌ HTML5 (WebAssembly) - Not planned
15+
16+
# Supported Godot Versions
17+
✅ Godot 4.4
18+
⚙ Godot 4.4 (Mono) - (Planned, but not yet implemented)
19+
❌ Godot <4.3 - (Not supported)
20+
❌ Godot 3.x - (Not supported)
21+
22+
## Usages
23+
* Producing messages to Kafka topics.
24+
* Consuming messages from Kafka topics.
25+
* Handling Kafka message serialization and deserialization.
26+
27+
## Target Audience
28+
This plugin is intended for Godot developers who need to integrate Kafka messaging capabilities into their games or applications. Projects like making a Massive Multiplayer Online Game (MMO) or any application that requires real-time data exchange can benefit from this plugin.
29+
30+
## Best Practices
31+
* Ideally this plugin should be used in a dedicated server/service - not in the game client. ( It can be used in the client, but it is not recommended. )
32+
* Deploy your Kafka brokers ideally on separate bare-metal machines for maximum performance.
33+
* Ensure that your Kafka cluster is properly configured and secured.
34+
35+
## Not Recommended For
36+
* This plugin is not recommended for use in the Godot editor itself, as it is designed for runtime use in games or applications.
37+
* It is not recommended to use this plugin for small-scale projects or applications that do not require real-time messaging capabilities.
38+
* Avoid using this plugin in scenarios where low latency is critical, as network latency can affect message delivery times.
39+
* When using this plugin in a client application, be aware of the potential security implications of exposing Kafka brokers directly to the client - consider using a HTTPS REST API or WebSocket connection to interact with a backend service that may handle Kafka interactions instead.
40+
41+
## Known Services
42+
* [Redpanda](https://redpanda.com/) - A Kafka-compatible streaming platform that can be used as a drop-in replacement for Kafka; re-written in C++ for high performance and low latency.
43+
* [Apache Kafka](https://kafka.apache.org/) - The original Kafka service, widely used for real-time data streaming and messaging.
44+
* [AWS MSK (Managed Streaming for Kafka)](https://aws.amazon.com/msk/) - A fully managed service that makes it easy to build and run applications that use Apache Kafka.
45+
* [Azure Event Hubs](https://azure.microsoft.com/en-us/services/event-hubs/) - A fully managed, real-time data ingestion service that can be used as a Kafka-compatible service.
46+
* [Google Cloud Pub/Sub](https://cloud.google.com/pubsub) - A messaging service that can be used for real-time messaging and data streaming, with Kafka compatibility.
47+
* [Confluent Cloud](https://www.confluent.io/confluent-cloud/) - A fully managed Kafka service that provides a cloud-native experience for building real-time applications.
48+
* [Aiven Kafka](https://aiven.io/kafka) - A fully managed Apache Kafka service that provides a cloud-native experience for building real-time applications.
49+
* [Instaclustr Managed Kafka](https://www.instaclustr.com/platform/managed-apache-kafka/) - A fully managed Apache Kafka service that provides a cloud-native experience for building real-time applications.
50+
* [Bitnami Kafka](https://bitnami.com/stack/kafka) - A fully managed Apache Kafka service that provides a cloud-native experience for building real-time applications.
51+
* [IBM Event Streams](https://www.ibm.com/cloud/event-streams) - A fully managed Apache Kafka service that provides a cloud-native experience for building real-time applications.
52+
* [StreamNative Cloud](https://streamnative.io/cloud) - A fully managed Apache Pulsar service that provides a cloud-native experience for building real-time applications, with Kafka compatibility.
53+
54+
## Contributing
55+
Contributions to the GDKafka plugin are welcome! If you have suggestions, bug reports, or feature requests, please open an issue on the [GitHub repository](https://github.com/Godot-Streaming-Networks/GDKafka-Addon)
56+
57+
## License
58+
This plugin is licensed under the MIT License, which allows for free use, modification, and distribution of the code. For more details, please refer to the [LICENSE](LICENSE) file in the repository.

asset-package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"title": "Godot Build System",
2+
"title": "GDKafka",
33
"godot_version": "4.4",
44
"category_id": "5",
55
"cost": "MIT"

0 commit comments

Comments
 (0)