Skip to content

Commit

Permalink
updated godot-cpp and patches
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriySalnikov committed Jul 20, 2023
1 parent 5435403 commit f7ba15f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 44 deletions.
1 change: 1 addition & 0 deletions .github/workflows/gdextension_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ concurrency:
env:
SCONS_CACHE: ${{github.workspace}}/.scons-cache/
OUTPUT_LIBS_PATH: bin
FORCE_DISABLE_UNITY: yes

jobs:
windows-gdextension:
Expand Down
12 changes: 6 additions & 6 deletions dev_build_godot_cpp.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ git apply --ignore-space-change --ignore-whitespace ../patches/unity_build.patch
git apply --ignore-space-change --ignore-whitespace ../patches/1165.patch
::git apply --ignore-space-change --ignore-whitespace ../patches/debug_string.patch

title win x64 editor dev
scons platform=windows target=editor arch=x86_64 dev_build=yes %api% generate_bindings=yes
if errorlevel 1 ( echo Failed to generate and compile debug godot-cpp source code. Code: %errorlevel% && exit /b %errorlevel% )
::title win x64 editor dev
::scons platform=windows target=editor arch=x86_64 dev_build=yes %api% generate_bindings=yes
::if errorlevel 1 ( echo Failed to generate and compile debug godot-cpp source code. Code: %errorlevel% && exit /b %errorlevel% )

title win x64 debug dev
scons platform=windows target=template_debug arch=x86_64 dev_build=yes %api% generate_bindings=yes
if errorlevel 1 ( echo Failed to generate and compile debug godot-cpp source code. Code: %errorlevel% && exit /b %errorlevel% )

title win x64 editor
scons platform=windows target=editor arch=x86_64 %api% generate_bindings=yes
if errorlevel 1 ( echo Failed to generate and compile debug godot-cpp source code. Code: %errorlevel% && exit /b %errorlevel% )
::title win x64 editor
::scons platform=windows target=editor arch=x86_64 %api% generate_bindings=yes
::if errorlevel 1 ( echo Failed to generate and compile debug godot-cpp source code. Code: %errorlevel% && exit /b %errorlevel% )

title win x64 debug
scons platform=windows target=template_debug arch=x86_64 %api%
Expand Down
2 changes: 1 addition & 1 deletion godot-cpp
7 changes: 6 additions & 1 deletion lib_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import json
from patches import unity_tools
from pathlib import Path

lib_name = "dd3d"
Expand Down Expand Up @@ -38,7 +39,10 @@ def gdnative_setup_defines_and_flags(env):


def gdnative_get_sources(src):
return [src_folder + "/" + file for file in src]
res = [src_folder + "/" + file for file in src]
res = unity_tools.generate_unity_build(res, "dd3d_")

return res


def gdnative_replace_flag(arr, flag, new_flag):
Expand All @@ -64,6 +68,7 @@ def gdnative_get_library_object(env, arguments=None, gen_help=None):
# store all obj's in a dedicated folder
env["SHOBJPREFIX"] = "#obj/"

# some additional tags
additional_tags = ""
if "release" in env["target"] and env["force_enabled_dd3d"]:
additional_tags += ".enabled"
Expand Down
11 changes: 6 additions & 5 deletions patches/godot_cpp_exclude_unused_classes.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
diff --git a/SConstruct b/SConstruct
index 42f8fc0..789434b 100644
index 11ec4cf..da86c93 100644
--- a/SConstruct
+++ b/SConstruct
@@ -124,6 +124,8 @@ opts.Add(BoolVariable("generate_template_get_node", "Generate a template version
@@ -151,6 +151,9 @@ opts.Add(
)
)

opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))
opts.Add(EnumVariable("precision", "Set the floating-point precision level", "single", ("single", "double")))
+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))
+
# Add platform options
tools = {}
for pl in platforms:
diff --git a/binding_generator.py b/binding_generator.py
index d04c698..fb1136d 100644
--- a/binding_generator.py
Expand Down
41 changes: 10 additions & 31 deletions patches/unity_build.patch
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
diff --git a/SConstruct b/SConstruct
index 27ee137..f145bf3 100644
index 27ee137..d46292c 100644
--- a/SConstruct
+++ b/SConstruct
@@ -10,6 +10,29 @@ from SCons.Errors import UserError
EnsureSConsVersion(4, 0)
@@ -6,6 +6,8 @@ import sys
import subprocess
from binding_generator import scons_generate_bindings, scons_emit_files
from SCons.Errors import UserError
+sys.path.insert(0, "../patches")
+import unity_tools

EnsureSConsVersion(4, 0)

+def generate_unity_build(bindings, env):
+ from pathlib import Path
+ import math
+
+ print("Generating source files for unity build:")
+ res = [Path(str(f)).absolute().as_posix()
+ for f in bindings if str(f).endswith(".cpp")]
+ unity_dir = Path("gen_unity")
+ unity_dir.mkdir(parents=True, exist_ok=True)
+ unity_files = []
+ for i in range(math.ceil(len(res) / 32)):
+ u_path = unity_dir / ("unity_%d.cpp" % i)
+ print(u_path)
+ unity_files.append(u_path.as_posix())
+ with u_path.open("w+") as unity_file:
+ unity_file.write("\n".join(
+ ["/* generated by Scons */\n"] + ["#include \"%s\"\n" % f for f in res[:32]]))
+ res = res[32:]
+
+ print()
+ return [f for f in bindings if not str(f).endswith(".cpp")] + [Path(f).absolute().as_posix() for f in unity_files]
+
+
def add_sources(sources, dir, extension):
for f in os.listdir(dir):
if f.endswith("." + extension):
@@ -215,6 +238,8 @@ bindings = env.GenerateBindings(
@@ -215,6 +217,8 @@ bindings = env.GenerateBindings(
[get_api_file(env), os.path.join(get_gdextension_dir(env), "gdextension_interface.h"), "binding_generator.py"],
)

+bindings = generate_unity_build(bindings, env)
+bindings = unity_tools.generate_unity_build(bindings, "godot-cpp_")
+
scons_cache_path = os.environ.get("SCONS_CACHE")
if scons_cache_path is not None:
Expand Down
33 changes: 33 additions & 0 deletions patches/unity_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python

import os
import re
from pathlib import Path

unity_batch_size = 32


def generate_unity_build(src, prefix="", gen_folder="obj", batch_size=unity_batch_size):
if os.environ.get("FORCE_DISABLE_UNITY", "").lower() not in ["", "no", "false", "n"]:
return src

from pathlib import Path
import math

print("Generating source files for unity build:")
res = [Path(str(f)).absolute().as_posix()
for f in src if str(f).endswith(".cpp")]
unity_dir = Path(gen_folder)
unity_dir.mkdir(parents=True, exist_ok=True)
unity_files = []
for i in range(math.ceil(len(res) / batch_size)):
u_path = unity_dir / (prefix + ("unity_%d.cpp" % i))
print(u_path)
unity_files.append(u_path.as_posix())
with u_path.open("w+") as unity_file:
unity_file.write("\n".join(
["/* generated by Scons */\n"] + ["#include \"%s\"\n" % f for f in res[:batch_size]]))
res = res[batch_size:]

print()
return [f for f in src if not str(f).endswith(".cpp")] + [Path(f).absolute().as_posix() for f in unity_files]

0 comments on commit f7ba15f

Please sign in to comment.