How godotengine/godot-cpp works
Project type and purpose
• This is a C++ binding library (“godot-cpp”) for the Godot game engine’s GDExtension API.
• It generates and compiles static C++ code so that Godot projects can call C++ modules via .gdextension files.
File structure
• Top‐level build orchestrators: CMakeLists.txt, SConstruct, Makefile, cmake/ (platform toolchains), tools/*.py (platform build helpers), binding_generator.py, doc_source_generator.py, build_profile.py.
• Core API code: include/godot_cpp/ (headers and JSON‐based extension_api.json), src/ (C++ implementation organized into core, variant, classes).
• GDNative/GDExtension adapter: gdextension/ (README, interface definitions).
• Tests and examples: test/ (unit tests, example Godot project, build scripts).
• Documentation: doc/ (RST files), README.md.
• CI configuration: .github/workflows/*.yml, misc/scripts for CI helpers.
README for additional insights
• Explains versioning strategy (branches and tags).
• Describes build process: how a .gdextension file points at compiled libs, the entry_symbol initialization flow, and how modules register with ClassDB.
• References code‐generation steps and the template example.
Main components
a. Code-Generation & Configuration
• binding_generator.py & extension_api.json → generate C++ header stubs.
• doc_source_generator.py → generate documentation stubs.
b. Build System
• Build orchestration: CMake vs SCons vs Makefile wrappers.
• Platform toolchain modules (cmake/android.cmake, ios.toolchain.cmake, etc).
• tools/*.py per‐platform helper scripts.
• GitHub Actions workflows invoking these builds and caching.
c. Core Library
• Headers: include/godot_cpp/*.hpp
• Sources: src/core, src/variant, src/classes
• gdextension interface layer: gdextension/*.h
d. Tests & Examples
• test/ project: compiles example extension, runs inside a minimal Godot project.
e. Integration with Godot Engine
• .gdextension file → Godot Engine loads static lib → calls entry_symbol → registers classes.
• Uses GDExtensionBinding API at runtime.
Relationships & interactions
• Code-generation feeds into Core Library source.
• Build System compiles Core Library for each target platform.
• CI workflows invoke Build System and run Tests & Examples.
• Output artifacts (static libs, headers) are packaged and consumed by end‐user Godot projects.
• At runtime, Godot Engine loads the compiled library via the .gdextension file and invokes the initialization callbacks.
Architectural patterns & principles
• Modular separation: code-generation, build orchestrator, core API, platform‐specific toolchains, tests.
• Plugin/extension pattern: clean interface (gdextension_interface.h) separates host engine from C++ modules.
• Multi‐platform abstraction: cmake toolchains + Python helper scripts.
• CI as code: GitHub Actions + misc/scripts ensure reproducibility.
Elements
• binding_generator.py → Core Library headers
• Core Library + Toolchains → Build System → Artifacts
• CI/CD → triggers Build System & Tests
• Artifacts → Godot Engine at runtime
• Yellow for code-generation scripts
• Blue for build orchestration
• Green for library code
• Orange for CI/CD
• Purple for runtime integration