Skip to content

Commit

Permalink
Updated godot-cpp, patches and build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriySalnikov committed Jan 15, 2025
1 parent 29d4104 commit 74cb551
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 65 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/gdextension_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ jobs:

android-gdextension:
name: 🤖 Android
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

strategy:
fail-fast: false
Expand Down Expand Up @@ -242,7 +242,7 @@ jobs:

web-gdextension:
name: 🕸 Web
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

strategy:
fail-fast: false
Expand Down Expand Up @@ -349,7 +349,7 @@ jobs:

check-python-version:
name: 🐍 Check compatibility with python
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
strategy:
matrix:
PYTHON_VER: ["3.8"] # this is the minimum available version to install on ubuntu 22.04 and 24.04
Expand Down Expand Up @@ -388,7 +388,7 @@ jobs:
ios-gdextension,
]
name: 📦 Collect GDExtension binaries
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
outputs:
artifact_name: ${{steps.output_info.outputs.artifact_name}}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/util_cleanup_cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
cleanup:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Check out code
uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/util_upload_release_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:
jobs:
get_version:
name: Get the current version
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
outputs:
version: ${{steps.get_version.outputs.version}}
steps:
Expand All @@ -28,7 +28,7 @@ jobs:
create_release_artifact:
name: Create release artifact
needs: get_version
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
outputs:
zipname: ${{steps.zip.outputs.zipname}}

Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
needs:
- get_version
- create_release_artifact
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- name: Download Binaries
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/web_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ env:
jobs:
data_preparation:
name: ⛏ Data preparation
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
outputs:
head_sha: ${{steps.get_sha.outputs.head_sha}}
lib_version: ${{steps.get_version.outputs.version}}
Expand Down Expand Up @@ -374,7 +374,7 @@ jobs:
finalization:
name: 🏁 Finalization
needs: [data_preparation, export_demo_project]
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- name: Checkout
Expand Down Expand Up @@ -635,7 +635,7 @@ jobs:
deploy:
name: 🌐 Deploy
needs: [finalization]
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

environment:
name: github-pages
Expand Down Expand Up @@ -672,7 +672,7 @@ jobs:
deploy,
]
if: failure() || cancelled()
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- name: Checkout
Expand Down
1 change: 0 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ src_folder = "src"
patches_to_apply = [
"patches/godot_cpp_exclude_unused_classes.patch", # Removes unused godot-cpp classes from the build process
"patches/unity_build.patch", # Speeds up the build by merging the source files. It can increase the size of assemblies.
"patches/web_threads.patch", # Adds the build flag that appeared in Godot 4.3. Required for a web build compatible with Godot 4.3.
"patches/big_int_fix.patch", # Fixes runtime link errors
]

Expand Down
106 changes: 67 additions & 39 deletions lib_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,39 @@
import os, json, re


def get_sources(src: list, src_folder: str, lib_name: str = "unity_"):
res = [os.path.join(src_folder, file) for file in src]
def get_sources(src: list, src_folder: str = "", lib_name: str = "unity_"):
if len(src_folder):
res = [os.path.join(src_folder, file) for file in src]
else:
res = src.copy()
res = unity_tools.generate_unity_build(res, lib_name + "_")
return res


def get_library_object(env: SConsEnvironment, project_name: str, lib_name: str, extra_tags: str, output_path: str, src_folder: str, additional_src: list) -> str:
def get_library_object(
other_env: SConsEnvironment,
project_name: str,
lib_name: str,
extra_tags: str,
output_path: str,
src_folder: str,
additional_src: list,
) -> str:
env = other_env.Clone()
env.Append(CPPPATH=src_folder)

src = []
with open(src_folder + "/default_sources.json") as f:
src = json.load(f)

scons_cache_path = os.environ.get("SCONS_CACHE")
if scons_cache_path is None:
# store all obj's in a dedicated folder
env["SHOBJPREFIX"] = "#obj/"
else:
env.CacheDir(scons_cache_path)
env.Decider("MD5")
src = json.loads(read_all_text(src_folder + "/default_sources.json"))

# some additional tags if needed
additional_tags = ""

if env["platform"] == "web" and env.get("threads", True):
additional_tags = ".threads"

lib_filename = "lib{}.{}.{}.{}{}".format(lib_name, env["platform"], env["target"], env["arch"], additional_tags + extra_tags) + env["SHLIBSUFFIX"]
lib_filename = (
"lib{}.{}.{}.{}{}".format(lib_name, env["platform"], env["target"], env["arch"], additional_tags + extra_tags)
+ env["SHLIBSUFFIX"]
)

if env["platform"] == "macos":
generate_framework_folder(env, project_name, lib_name, lib_filename, output_path)
Expand All @@ -43,10 +48,7 @@ def get_library_object(env: SConsEnvironment, project_name: str, lib_name: str,
lib_filename = os.path.join(output_path, lib_filename)

env.Default(
env.SharedLibrary(
target=env.File(lib_filename),
source=get_sources(additional_src + src, src_folder, lib_name)
)
env.SharedLibrary(target=env.File(lib_filename), source=get_sources(additional_src + src, src_folder, lib_name))
)

return lib_filename
Expand All @@ -67,7 +69,36 @@ def get_library_version():
return f"{major_value}.{minor_value}.{patch_value}"


def generate_framework_folder(env: SConsEnvironment, project_name: str, lib_name: str, lib_filename: str, output_path: str):
def read_all_text(file_path: str) -> str | None:
try:
with open(file_path, "r") as file:
text_data = file.read()
except UnicodeDecodeError:
try:
with open(file_path, "r", encoding="utf-8") as file:
text_data = file.read()
except UnicodeDecodeError as e:
print(
"Couldn't open file due to 'UnicodeDecodeError' exception: "
+ (file_path).resolve().as_posix()
+ "\nException: "
+ str(e)
)
return None
return text_data


def write_all_text(file_path: str, text: str) -> bool:
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with open(file_path, "w+", encoding="utf-8") as file:
file.write(text)
return True
return False


def generate_framework_folder(
env: SConsEnvironment, project_name: str, lib_name: str, lib_filename: str, output_path: str
):
min_version = env.get("macos_deployment_target", "10.15")
lib_version = get_library_version()
lib_filename_noext = os.path.splitext(lib_filename)[0]
Expand Down Expand Up @@ -113,10 +144,12 @@ def generate_framework_folder(env: SConsEnvironment, project_name: str, lib_name
info_plist_file.write(info_plist)


def generate_resources_cpp_h_files(input_files: list, namespace: str, src_folder: str, output_no_ext: str, src_out: list):
def generate_resources_cpp_h_files(
input_files: list, namespace: str, src_folder: str, output_no_ext: str, src_out: list
):
"""
input_files : list of tuples
(path: str, is_text: bool)
(path: str, is_text: bool, content: list)
namespace : str
source code namespace
src_folder : str
Expand Down Expand Up @@ -151,31 +184,26 @@ def generate_resources_cpp_h_files(input_files: list, namespace: str, src_folder
for input_file_touple in input_files:
is_text = input_file_touple[1]
input_file_path = input_file_touple[0]
file_content = None
if len(input_file_touple) >= 3:
file_content = input_file_touple[2]
file_name_escaped = input_file_path.replace(".", "_").replace("/", "_").replace("\\", "_").replace(":", "_")

if is_text:
try:
with open(input_file_path, "r") as file:
text_data = file.read()
except UnicodeDecodeError:
try:
with open(input_file_path, "r", encoding="utf-8") as file:
text_data = file.read()
except UnicodeDecodeError as e:
print(
"Skipping file due to 'UnicodeDecodeError' exception: "
+ (input_file_path).resolve().as_posix()
+ "\nException: "
+ str(e)
)
continue
if file_content == None:
text_data = read_all_text(input_file_path)
else:
text_data = file_content

cpp_file.write(f'\tconst char *{file_name_escaped} = R"({text_data})";\n\n')

h_file.write(f"\textern const char *{file_name_escaped};\n")
else:
with open(input_file_touple[0], "rb") as input_file:
binary_data = input_file.read()
if file_content == None:
with open(input_file_touple[0], "rb") as input_file:
binary_data = input_file.read()
else:
binary_data = file_content

cpp_array = ", ".join([f"{byte}" for byte in binary_data])
cpp_file.write(
Expand Down
14 changes: 7 additions & 7 deletions patches/big_int_fix.patch
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
diff --git a/tools/web.py b/tools/web.py
index 79b4b24..075936e 100644
index c8f07c5..010efac 100644
--- a/tools/web.py
+++ b/tools/web.py
@@ -41,6 +41,9 @@ def generate(env):
env.Append(CPPFLAGS=["-s", "SIDE_MODULE=1"])
env.Append(LINKFLAGS=["-s", "SIDE_MODULE=1"])

@@ -45,6 +45,9 @@ def generate(env):
# Force wasm longjmp mode.
env.Append(CCFLAGS=["-sSUPPORT_LONGJMP='wasm'"])
env.Append(LINKFLAGS=["-sSUPPORT_LONGJMP='wasm'"])
+
+ # Use big int
+ env.Append(LINKFLAGS=["-sWASM_BIGINT"])
+
env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED"])

common_compiler_flags.generate(env)
16 changes: 13 additions & 3 deletions patches/godot_cpp_exclude_unused_classes.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/binding_generator.py b/binding_generator.py
index 7911a7e..58188f7 100644
index 4825765..4505988 100644
--- a/binding_generator.py
+++ b/binding_generator.py
@@ -5,6 +5,11 @@ import re
Expand Down Expand Up @@ -40,16 +40,26 @@ index 7911a7e..58188f7 100644
if profile_filepath and not Path(profile_filepath).is_absolute():
profile_filepath = str((Path(env.Dir("#").abspath) / profile_filepath).as_posix())
diff --git a/tools/godotcpp.py b/tools/godotcpp.py
index cc2b02f..d138052 100644
index e16b17d..69a81c5 100644
--- a/tools/godotcpp.py
+++ b/tools/godotcpp.py
@@ -322,6 +322,9 @@ def options(opts, env):
@@ -324,6 +324,10 @@ def options(opts, env):
opts.Add(BoolVariable("dev_build", "Developer build with dev-only debugging code (DEV_ENABLED)", False))
opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False))

+ opts.Add(BoolVariable("exclude_unused_classes", "Disable generation of unused classes.", True))
+ opts.Add(PathVariable("folder_to_include_classes", "Path to the directory containing extension sources", "../src", PathVariable.PathIsDir))
+ opts.Add(PathVariable("custom_godotcpp_suffix", "Additional custom library suffix", "", PathVariable.PathAccept))
+
# Add platform options (custom tools can override platforms)
for pl in sorted(set(platforms + custom_platforms)):
tool = Tool(pl, toolpath=get_platform_tools_paths(env))
@@ -444,7 +448,7 @@ def generate(env):
if not env["threads"]:
suffix += ".nothreads"

- env["suffix"] = suffix # Exposed when included from another project
+ env["suffix"] = suffix + env["custom_godotcpp_suffix"] # Exposed when included from another project
env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"]

# compile_commands.json
4 changes: 2 additions & 2 deletions patches/unity_build.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/tools/godotcpp.py b/tools/godotcpp.py
index cc2b02f..b0d3017 100644
index e16b17d..6873fb2 100644
--- a/tools/godotcpp.py
+++ b/tools/godotcpp.py
@@ -12,6 +12,9 @@ from SCons.Variables.BoolVariable import _text2bool
Expand All @@ -12,7 +12,7 @@ index cc2b02f..b0d3017 100644

def add_sources(sources, dir, extension):
for f in os.listdir(dir):
@@ -468,6 +471,9 @@ def _godot_cpp(env):
@@ -475,6 +478,9 @@ def _godot_cpp(env):
"binding_generator.py",
],
)
Expand Down
1 change: 1 addition & 0 deletions src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void initialize_debug_draw_3d_module(ModuleInitializationLevel p_level) {
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
#if defined(TRACY_DELAYED_INIT) && defined(TRACY_MANUAL_LIFETIME)
tracy::StartupProfiler();
tracy::GetProfiler().SetProgramName("libdd3d");
#endif

#ifndef DISABLE_DEBUG_RENDERING
Expand Down
5 changes: 5 additions & 0 deletions src/utils/TracyClientCustom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#include "../thirdparty/tracy/public/TracyClient.cpp"

// Undefine `poll` as it may override godot::HTTPClient::poll
#undef poll
2 changes: 2 additions & 0 deletions src/utils/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
#else

#include "thirdparty/tracy/public/tracy/Tracy.hpp"
// Undefine `poll` as it may override godot::HTTPClient::poll
#undef poll

#define ProfiledMutex(type, varname, desc) TracyLockableN(type, varname, desc)

Expand Down

0 comments on commit 74cb551

Please sign in to comment.