Skip to content

Commit

Permalink
the build system has been updated.
Browse files Browse the repository at this point in the history
fixed an error message in the c# generator.
fixed a crash in the release build.
  • Loading branch information
DmitriySalnikov committed Aug 5, 2024
1 parent f00d19b commit 19650f4
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 259 deletions.
20 changes: 7 additions & 13 deletions .github/actions/compile_gdextension/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,29 @@ runs:
shell: bash
run: |
echo "::group::🛠️ GDExtesion Compilation 🛠️"
cd godot-cpp
git apply --ignore-space-change --ignore-whitespace ../patches/godot_cpp_exclude_unused_classes.patch
git apply --ignore-space-change --ignore-whitespace ../patches/unity_build.patch
git apply --ignore-space-change --ignore-whitespace ../patches/web_threads.patch
cd ..
scons apply_patches
telemetry_args=""
if [ "${{env.PRODUCTION_BUILD}}" == "true" ] && [ "${{inputs.target}}" == "editor" ] && [ "${{steps.checkout_tele_repo.conclusion}}" == "success" ]; then
telemetry_args="telemetry_enabled=yes"
fi
scons_params="platform=${{inputs.platform}} arch=${{inputs.arch}} target=${{inputs.target}} addon_output_dir=${{inputs.output_libs_path}} ${{inputs.additional}}"
scons platform=${{inputs.platform}} arch=${{inputs.arch}} target=${{inputs.target}} addon_output_dir=${{inputs.output_libs_path}} ${{inputs.additional}} $telemetry_args
scons $scons_params $telemetry_args
if [ "${{inputs.target}}" == "template_release" ] && [ "${{inputs.additional_enabled_dd3d}}" == "true" ]; then
scons platform=${{inputs.platform}} arch=${{inputs.arch}} target=${{inputs.target}} addon_output_dir=${{inputs.output_libs_path}} force_enabled_dd3d=yes ${{inputs.additional}}
scons $scons_params force_enabled_dd3d=yes
fi
echo "::endgroup::"
- name: Prepare artifact Unix
if: runner.os != 'Windows' && inputs.platform != 'android' && inputs.platform != 'web'
shell: bash
run: |
if [ "${{inputs.platform}}" == 'macos' ]; then
found_files=$(find -L ${{inputs.output_libs_path}} -type f -exec file {} + | grep "Mach-O universal" | cut -d: -f1)
echo "Found files: $found_files"
strip -u $found_files
elif [ "${{inputs.platform}}" == 'ios' ]; then
found_files=$(find -L ${{inputs.output_libs_path}} -type f -exec file {} + | grep ".dylib" | cut -d: -f1)
if [ "${{inputs.platform}}" == 'ios' ] || [ "${{inputs.platform}}" == 'macos' ]; then
found_files=$(find -L ${{inputs.output_libs_path}} -type f -iname "*.dylib")
echo "Found files: $found_files"
while IFS= read -r file; do
echo "Strip '$file'"
strip -u "$file"
done <<< "$found_files"
else
Expand Down
159 changes: 155 additions & 4 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,6 +1,157 @@
#!/usr/bin/env python

import lib_utils
env = SConscript("godot-cpp/SConstruct")
new_env = lib_utils.get_library_object(env.Clone(), ARGUMENTS, lambda e, o: Help(o.GenerateHelpText(e)))
Return("new_env")
from SCons.Script import SConscript
from SCons.Script.SConscript import SConsEnvironment

import SCons, SCons.Script
import os, platform
import lib_utils, lib_utils_external

# Fixing the encoding of the console
if platform.system() == "Windows":
os.system("chcp 65001")

# Project config
project_name = "Debug Draw 3D"
lib_name = "dd3d"
default_output_dir = os.path.join("addons", "debug_draw_3d", "libs")
src_folder = "src"

# If necessary, add patches from the code
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.
]

print(
f"If you add new source files (e.g. .cpp, .c), do not forget to specify them in '{src_folder}/default_sources.json'.\n\tOr add them to 'setup_defines_and_flags' inside 'SConstruct'."
)
print("To apply git patches, use 'scons apply_patches'.")
# print("To build cmake libraries, use 'scons build_cmake'.")


# Additional console arguments
def setup_options(env: SConsEnvironment, arguments):
from SCons.Variables import Variables, BoolVariable, EnumVariable, PathVariable

opts = Variables([], arguments)

# It must be here for lib_utils.py
opts.Add(
PathVariable(
"addon_output_dir", "Path to the output directory", default_output_dir, PathVariable.PathIsDirCreate
)
)

opts.Add(BoolVariable("telemetry_enabled", "Enable the telemetry module", False))
opts.Add(BoolVariable("tracy_enabled", "Enable tracy profiler", False))
opts.Add(BoolVariable("force_enabled_dd3d", "Keep the rendering code in the release build", False))
opts.Add(BoolVariable("lto", "Link-time optimization", False))

opts.Update(env)
env.Help(opts.GenerateHelpText(env))


# Additional compilation flags
def setup_defines_and_flags(env: SConsEnvironment, src_out):
# Add more sources to `src_out` if needed

if "release" in env["target"] and not env["force_enabled_dd3d"]:
env.Append(CPPDEFINES=["DISABLE_DEBUG_RENDERING"])

if env["telemetry_enabled"]:
tele_src = "src/editor/my_telemetry_modules/GDExtension/usage_time_reporter.cpp"
if os.path.exists(tele_src):
env.Append(CPPDEFINES=["TELEMETRY_ENABLED"])
src_out.append(tele_src)
print("Compiling with telemetry support!")
else:
print("No telemetry source file found. telemetry_enabled will be ignored!")

if env["lto"]:
if env.get("is_msvc", False):
env.AppendUnique(CCFLAGS=["/GL"])
env.AppendUnique(ARFLAGS=["/LTCG"])
env.AppendUnique(LINKFLAGS=["/LTCG"])
else:
env.AppendUnique(CCFLAGS=["-flto"])
env.AppendUnique(LINKFLAGS=["-flto"])

if env["tracy_enabled"]:
env.Append(CPPDEFINES=["TRACY_ENABLE", "TRACY_ON_DEMAND", "TRACY_DELAYED_INIT", "TRACY_MANUAL_LIFETIME"])
src_out.append("src/thirdparty/tracy/public/TracyClient.cpp")

if env.get("is_msvc", False):
env.Append(LINKFLAGS=["/WX:NO"])

if env["platform"] in ["linux"]: # , "android"?
env.Append(
LINKFLAGS=[
"-static-libgcc",
"-static-libstdc++",
]
)
if env["platform"] == "android":
env.Append(
LIBS=[
"log",
]
)
print()


def generate_sources_for_resources(env, src_out):
# Array of (path, is_text)
editor_files = [
("images/icon_3d_32.png", False),
]
lib_utils.generate_resources_cpp_h_files(
editor_files,
"DD3DEditorResources",
src_folder,
"editor_resources.gen",
src_out if "editor" in env["target"] else [],
)

shared_files = [
("src/resources/extendable_meshes.gdshader", True),
("src/resources/wireframe_unshaded.gdshader", True),
("src/resources/billboard_unshaded.gdshader", True),
("src/resources/plane_unshaded.gdshader", True),
]
lib_utils.generate_resources_cpp_h_files(shared_files, "DD3DResources", src_folder, "shared_resources.gen", src_out)

print("The generation of C++ sources with the contents of resources has been completed")
print()


def apply_patches(target, source, env: SConsEnvironment):
return lib_utils_external.apply_git_patches(env, patches_to_apply, "godot-cpp")


# Additional build of the projects via CMake
# def build_cmake(target, source, env: SConsEnvironment):
# extra_flags = []
# return lib_utils_external.cmake_build_project(env, "opus", extra_flags)

env: SConsEnvironment = SConscript("godot-cpp/SConstruct")
env = env.Clone()

args = ARGUMENTS
additional_src = []
setup_options(env, args)
setup_defines_and_flags(env, additional_src)
generate_sources_for_resources(env, additional_src)

extra_tags = ""
if "release" in env["target"] and env["force_enabled_dd3d"]:
extra_tags += ".enabled"

lib_utils.get_library_object(
env, project_name, lib_name, extra_tags, env["addon_output_dir"], src_folder, additional_src
)

# Register console commands
env.Command("apply_patches", [], apply_patches)
# env.Command("build_cmake", [], build_cmake)
7 changes: 7 additions & 0 deletions examples_dd3d/DebugDrawDemoScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,19 @@ func main_update(delta: float) -> void:
DebugDraw2D.set_text("Frames drawn", Engine.get_frames_drawn())
DebugDraw2D.set_text("FPS", Engine.get_frames_per_second())
DebugDraw2D.set_text("delta", delta)

$HitTest.visible = false
$LagTest.visible = false
$PlaneOrigin.visible = false
$OtherWorld.visible = false
%ZDepthTestCube.visible = false
return

$HitTest.visible = true
$LagTest.visible = true
$PlaneOrigin.visible = true
$OtherWorld.visible = true
%ZDepthTestCube.visible = true

# Testing the rendering layers by showing the image from the second camera inside the 2D panel
DebugDraw3D.config.geometry_render_layers = 1 if !Input.is_key_pressed(KEY_ALT) else 0b10010
Expand Down
3 changes: 2 additions & 1 deletion examples_dd3d/DebugDrawDemoScene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ transform = Transform3D(1.51514, 0.589536, 1.00858, -1.34875, 0.662262, 1.133, 0
[node name="GizmoNormal" type="Node3D" parent="Misc"]
transform = Transform3D(0.965926, 0, -0.258819, 0, 1, 0, 0.258819, 0, 0.965926, 0.890203, -0.306246, 0.356159)

[node name="MeshInstance3D" type="MeshInstance3D" parent="Misc/GizmoNormal"]
[node name="ZDepthTestCube" type="MeshInstance3D" parent="Misc/GizmoNormal"]
unique_name_in_owner = true
transform = Transform3D(0.591801, 0, 4.47035e-08, 0, 0.591801, 0, -4.47035e-08, 0, 0.591801, 0, 0, 0)
mesh = SubResource("BoxMesh_b14rm")

Expand Down
13 changes: 13 additions & 0 deletions examples_dd3d/DebugDrawDemoSceneCS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public partial class DebugDrawDemoSceneCS : Node3D
Node3D dCylinder3a;
Node3D dCylinder3b;

MeshInstance3D dPlaneOrigin;
MeshInstance3D pZDepthTestCube;

MeshInstance3D dOtherWorld;
SubViewport dOtherWorldViewport;
Node3D dOtherWorldBox;
Expand Down Expand Up @@ -154,6 +157,9 @@ public override async void _Ready()
dCylinder3a = GetNode<Node3D>("Cylinders/Cylinder3/1");
dCylinder3b = GetNode<Node3D>("Cylinders/Cylinder3/2");

dPlaneOrigin = GetNode<MeshInstance3D>("PlaneOrigin");
pZDepthTestCube = GetNode<MeshInstance3D>("%ZDepthTestCube");

dOtherWorld = GetNode<MeshInstance3D>("OtherWorld");
dOtherWorldViewport = GetNode<SubViewport>("OtherWorld/SubViewport");
dOtherWorldBox = GetNode<Node3D>("OtherWorld/SubViewport/OtherWorldBox");
Expand Down Expand Up @@ -295,13 +301,20 @@ void MainUpdate(double delta)
DebugDraw2D.SetText("Frames drawn", Engine.GetFramesDrawn());
DebugDraw2D.SetText("FPS", Engine.GetFramesPerSecond());
DebugDraw2D.SetText("delta", delta);

dHitTest.Visible = false;
dLagTest.Visible = false;
dPlaneOrigin.Visible = false;
pZDepthTestCube.Visible = false;
dOtherWorld.Visible = false;
return;
}

dHitTest.Visible = true;
dLagTest.Visible = true;
dPlaneOrigin.Visible = true;
pZDepthTestCube.Visible = true;
dOtherWorld.Visible = true;

// Testing the rendering layers by showing the image from the second camera inside the 2D panel
DebugDraw3D.Config.GeometryRenderLayers = !Input.IsKeyPressed(Key.Alt) ? 1 : 0b10010;
Expand Down
2 changes: 1 addition & 1 deletion examples_dd3d/DebugDrawDemoSceneCS.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[node name="DebugDrawDemoSceneCS" instance=ExtResource("2")]
script = ExtResource("2_ipqea")

[node name="Settings" parent="." index="21"]
[node name="Settings" parent="." index="22"]
switch_to_scene = "res://examples_dd3d/DebugDrawDemoScene.tscn"

[node name="Label" parent="Settings/HBox/VBoxContainer" index="1"]
Expand Down
Loading

0 comments on commit 19650f4

Please sign in to comment.