Skip to content

Commit

Permalink
Added a GDExtension module for Thrive for future use (#5464)
Browse files Browse the repository at this point in the history
* Added godot-cpp as a submodule

* First setup of build scripts with the godot-cpp module

* Basic setup for the GDExtension code

* Building and bringing back installing for native libraries

* Correct native lib paths

* Improve the build a tiny bit

* Try to bind some methods

* Updated Jolt version

* Wrote the interop and setup calling code for the extension

* Updated build scripts a bit

* Tried some TaskSystem.hpp changes but they didn't help

* Add CI native libs install step which is necessary

now for GDExtension copying to work

* Fixed undefined symbol coming from Jolt due to no RTTI

turns out this was just a new option

* Bump the updated LLVM version

* Implemented intercommunication passing

* Made extension shutdown work and cleaned up the code a bit

* Fixed the extension build for Windows

* Updated native script to work on both debug and non-debug at once

to simplify the process now that debug variants are basically always needed

* Switched to using the final library name in editor

this was done to make sure there isn't future work needed to make debug symbol matching work

* Improved local library install

* Load GDExtension into C# through already loaded info

to avoid any path resolving issues that may cause the data to be inconsistent between what Godot loads and what we load

* Updated packaging script for the new requirements

* Add safety check about library load failure

* Fixed upload native libs script

* Clarify one method and improve build a bit

* Try to get Extension API to export symbols for Windows

* Actually got the previous thing working with a correct windows check

* Made extension version check method catch errors

* Make distributable debug warning print just once
  • Loading branch information
hhyyrylainen authored Sep 6, 2024
1 parent 389b796 commit ddc7025
Show file tree
Hide file tree
Showing 40 changed files with 1,281 additions and 164 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeCategories:
- Regex: "(<|\")(Jolt|boost)\/.*"
- Regex: "(<|\")(Jolt|boost|godot_cpp)\/.*"
Priority: 2
- Regex: "<.*>"
Priority: 1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export.cfg
/src/main.cpp
/src/generated
/src/server/main.cpp
Scripts/GodotAPIData

# asset symlinks
/Fonts
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
[submodule "third_party/concurrentqueue"]
path = third_party/concurrentqueue
url = https://github.com/cameron314/concurrentqueue.git
[submodule "third_party/godot-cpp"]
path = third_party/godot-cpp
url = https://github.com/godotengine/godot-cpp.git
branch = 4.3
3 changes: 2 additions & 1 deletion CIConfiguration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ jobs:
command: dotnet run --project Scripts -- check compile
- run:
name: Download native libraries
command: dotnet run --project Scripts -- native Fetch
# This doesn't fetch or install debug variants as they aren't strictly necessary for packaging
command: dotnet run --project Scripts -- native Fetch --debug false
- run:
name: Create builds
command: dotnet run --project Scripts -- package --dehydrated
Expand Down
30 changes: 28 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ option(NULL_HAS_UNUSUAL_REPRESENTATION

# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/CMake")

option(THRIVE_GODOT_API_FILE "Set to override folder Godot API file is looked for in" "")

# Also use a lib prefix on windows for consistency
if(WIN32)
set(CMAKE_SHARED_LIBRARY_PREFIX_CXX "lib")
Expand Down Expand Up @@ -88,7 +90,7 @@ else()
endif()

# Standard library and other linking flags
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

set(CLANG_DEFAULT_CXX_STDLIB libc++)
set(CLANG_DEFAULT_RTLIB compiler-rt)
Expand Down Expand Up @@ -142,18 +144,42 @@ if(NOT EARLY_CHECK_LIBRARY_VERSION)
message(FATAL_ERROR "Failed to parse native (early check) library version")
endif()

string(REGEX MATCH "ExtensionVersion = ([0-9]+);" _ "${versionFile}")
set(THRIVE_EXTENSION_VERSION ${CMAKE_MATCH_1})

if(NOT THRIVE_EXTENSION_VERSION)
message(FATAL_ERROR "Failed to parse Thrive GDExtensions library version")
endif()

message(STATUS "Configured native library version ${NATIVE_LIBRARY_VERSION}")

# Configure include file
configure_file("src/native/Include.h.in" "${PROJECT_BINARY_DIR}/Include.h")
include_directories(${PROJECT_BINARY_DIR})

# Configure gdextension stuff
if(THRIVE_GODOT_API_FILE)
set(GODOT_GDEXTENSION_DIR "${THRIVE_GODOT_API_FILE}")
include_directories("${THRIVE_GODOT_API_FILE}")
message(STATUS "Using custom location of Godot API file")
else()
set(GODOT_GDEXTENSION_DIR "${CMAKE_BINARY_DIR}/api")
include_directories("${CMAKE_BINARY_DIR}/api")
endif()

set(FLOAT_PRECISION "single")

# GODOT_CPP_SYSTEM_HEADERS
# GODOT_CPP_WARNING_AS_ERROR

# Add the subfolders that define the actual things to build
add_subdirectory(third_party)

if(THRIVE_AVX)
if(THRIVE_AVX AND THRIVE_DISTRIBUTION)
# Early checks is not compiled in non-avx mode
add_subdirectory(src/native/early_checks)
endif()

add_subdirectory(src/native)
add_subdirectory(src/extension)

Loading

0 comments on commit ddc7025

Please sign in to comment.