Merge pull request #1836 from dsnopek/4.4-cherrypicks-3

Cherry-picks for the godot-cpp 4.4 branch - 3rd batch
This commit is contained in:
David Snopek
2025-09-11 10:08:06 -05:00
committed by GitHub
9 changed files with 68 additions and 32 deletions

View File

@@ -1,6 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
import os import os
import sys
# Add godot-cpp folder to sys.path, so that we can import local modules.
sys.path.append(Dir(".").srcnode().abspath)
EnsureSConsVersion(4, 0) EnsureSConsVersion(4, 0)
EnsurePythonVersion(3, 8) EnsurePythonVersion(3, 8)
@@ -27,7 +32,7 @@ if profile:
elif os.path.isfile(profile + ".py"): elif os.path.isfile(profile + ".py"):
customs.append(profile + ".py") customs.append(profile + ".py")
opts = Variables(customs, ARGUMENTS) opts = Variables(customs, ARGUMENTS)
cpp_tool = Tool("godotcpp", toolpath=["tools"]) cpp_tool = Tool("godotcpp", toolpath=[Dir("tools").srcnode().abspath])
cpp_tool.options(opts, env) cpp_tool.options(opts, env)
opts.Update(env) opts.Update(env)

View File

@@ -319,11 +319,11 @@ function(godotcpp_generate)
set(DEBUG_FEATURES "$<NOT:$<STREQUAL:${GODOTCPP_TARGET},template_release>>") set(DEBUG_FEATURES "$<NOT:$<STREQUAL:${GODOTCPP_TARGET},template_release>>")
set(HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},${DEBUG_FEATURES},$<BOOL:${GODOTCPP_USE_HOT_RELOAD}>>") set(HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},${DEBUG_FEATURES},$<BOOL:${GODOTCPP_USE_HOT_RELOAD}>>")
# Suffix # Suffix Generator Expression
string( string(
CONCAT CONCAT
GODOTCPP_SUFFIX GODOTCPP_SUFFIX_GENEX
"$<1:.${SYSTEM_NAME}>" "$<1:${SYSTEM_NAME}>"
"$<1:.${GODOTCPP_TARGET}>" "$<1:.${GODOTCPP_TARGET}>"
"$<${IS_DEV_BUILD}:.dev>" "$<${IS_DEV_BUILD}:.dev>"
"$<$<STREQUAL:${GODOTCPP_PRECISION},double>:.double>" "$<$<STREQUAL:${GODOTCPP_PRECISION},double>:.double>"
@@ -331,6 +331,8 @@ function(godotcpp_generate)
# TODO IOS_SIMULATOR # TODO IOS_SIMULATOR
"$<$<NOT:${THREADS_ENABLED}>:.nothreads>" "$<$<NOT:${THREADS_ENABLED}>:.nothreads>"
) )
# The same as above, but with a leading '.' to maintain backwards compatibility.
set(GODOTCPP_SUFFIX ".${GODOTCPP_SUFFIX_GENEX}")
# the godot-cpp.* library targets # the godot-cpp.* library targets
add_library(godot-cpp STATIC) add_library(godot-cpp STATIC)
@@ -375,6 +377,7 @@ function(godotcpp_generate)
GODOTCPP_ARCH "${ARCH_NAME}" GODOTCPP_ARCH "${ARCH_NAME}"
GODOTCPP_PRECISION "${GODOTCPP_PRECISION}" GODOTCPP_PRECISION "${GODOTCPP_PRECISION}"
GODOTCPP_SUFFIX "${GODOTCPP_SUFFIX}" GODOTCPP_SUFFIX "${GODOTCPP_SUFFIX}"
GODOTCPP_SUFFIX_GENEX "${GODOTCPP_SUFFIX_GENEX}"
# Some IDE's respect this property to logically group targets # Some IDE's respect this property to logically group targets
FOLDER "godot-cpp" FOLDER "godot-cpp"

View File

@@ -111,7 +111,7 @@ protected:
void _postinitialize(); void _postinitialize();
Wrapped(const StringName p_godot_class); Wrapped(const StringName &p_godot_class);
Wrapped(GodotObject *p_godot_object); Wrapped(GodotObject *p_godot_object);
virtual ~Wrapped() {} virtual ~Wrapped() {}

View File

@@ -32,6 +32,7 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <type_traits>
#include <utility> #include <utility>
namespace godot { namespace godot {

View File

@@ -44,6 +44,8 @@ namespace godot {
#define Math_TAU 6.2831853071795864769252867666 #define Math_TAU 6.2831853071795864769252867666
#define Math_PI 3.1415926535897932384626433833 #define Math_PI 3.1415926535897932384626433833
#define Math_E 2.7182818284590452353602874714 #define Math_E 2.7182818284590452353602874714
#define Math_INF INFINITY
#define Math_NAN NAN
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
#define MATH_CHECKS #define MATH_CHECKS

View File

@@ -66,7 +66,7 @@ void Wrapped::_postinitialize() {
} }
} }
Wrapped::Wrapped(const StringName p_godot_class) { Wrapped::Wrapped(const StringName &p_godot_class) {
#ifdef HOT_RELOAD_ENABLED #ifdef HOT_RELOAD_ENABLED
if (unlikely(Wrapped::_constructing_recreate_owner)) { if (unlikely(Wrapped::_constructing_recreate_owner)) {
_owner = Wrapped::_constructing_recreate_owner; _owner = Wrapped::_constructing_recreate_owner;

View File

@@ -286,7 +286,7 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge
// Make sure we weren't passed the legacy struct. // Make sure we weren't passed the legacy struct.
uint32_t *raw_interface = (uint32_t *)(void *)p_get_proc_address; uint32_t *raw_interface = (uint32_t *)(void *)p_get_proc_address;
if (raw_interface[0] == 4 && raw_interface[1] == 0) { if (uintptr_t(p_get_proc_address) % alignof(LegacyGDExtensionInterface) == 0 && raw_interface[0] == 4 && raw_interface[1] == 0) {
// Use the legacy interface only to give a nice error. // Use the legacy interface only to give a nice error.
LegacyGDExtensionInterface *legacy_interface = (LegacyGDExtensionInterface *)p_get_proc_address; LegacyGDExtensionInterface *legacy_interface = (LegacyGDExtensionInterface *)p_get_proc_address;
internal::gdextension_interface_print_error = (GDExtensionInterfacePrintError)legacy_interface->print_error; internal::gdextension_interface_print_error = (GDExtensionInterfacePrintError)legacy_interface->print_error;

View File

@@ -2,6 +2,10 @@ import os
import subprocess import subprocess
def using_emcc(env):
return "emcc" in os.path.basename(env["CC"])
def using_clang(env): def using_clang(env):
return "clang" in os.path.basename(env["CC"]) return "clang" in os.path.basename(env["CC"])
@@ -89,7 +93,13 @@ def generate(env):
# Adding dwarf-4 explicitly makes stacktraces work with clang builds, # Adding dwarf-4 explicitly makes stacktraces work with clang builds,
# otherwise addr2line doesn't understand them. # otherwise addr2line doesn't understand them.
env.Append(CCFLAGS=["-gdwarf-4"]) env.Append(CCFLAGS=["-gdwarf-4"])
if env.dev_build: if using_emcc(env):
# Emscripten only produces dwarf symbols when using "-g3".
env.AppendUnique(CCFLAGS=["-g3"])
# Emscripten linker needs debug symbols options too.
env.AppendUnique(LINKFLAGS=["-gdwarf-4"])
env.AppendUnique(LINKFLAGS=["-g3"])
elif env.dev_build:
env.Append(CCFLAGS=["-g3"]) env.Append(CCFLAGS=["-g3"])
else: else:
env.Append(CCFLAGS=["-g2"]) env.Append(CCFLAGS=["-g2"])

View File

@@ -16,12 +16,6 @@ from build_profile import generate_trimmed_api
from doc_source_generator import scons_generate_doc_source from doc_source_generator import scons_generate_doc_source
def add_sources(sources, dir, extension):
for f in os.listdir(dir):
if f.endswith("." + extension):
sources.append(dir + "/" + f)
def get_cmdline_bool(option, default): def get_cmdline_bool(option, default):
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line, """We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings. and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
@@ -34,7 +28,12 @@ def get_cmdline_bool(option, default):
def normalize_path(val, env): def normalize_path(val, env):
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val) """Normalize a path that was provided by the user on the command line
and is thus either an absolute path, or relative to the top level directory (#)
where the command was run.
"""
# If val is an absolute path, it will not be joined.
return os.path.join(env.Dir("#").abspath, val)
def validate_file(key, val, env): def validate_file(key, val, env):
@@ -54,9 +53,10 @@ def validate_parent_dir(key, val, env):
def get_platform_tools_paths(env): def get_platform_tools_paths(env):
path = env.get("custom_tools", None) path = env.get("custom_tools", None)
tools_path = env.Dir("tools").srcnode().abspath
if path is None: if path is None:
return ["tools"] return [tools_path]
return [normalize_path(path, env), "tools"] return [normalize_path(path, env), tools_path]
def get_custom_platforms(env): def get_custom_platforms(env):
@@ -141,7 +141,12 @@ def scons_emit_files(target, source, env):
env.Clean(target, [env.File(f) for f in get_file_list(str(source[0]), target[0].abspath, True, True)]) env.Clean(target, [env.File(f) for f in get_file_list(str(source[0]), target[0].abspath, True, True)])
api = generate_trimmed_api(str(source[0]), profile_filepath) api = generate_trimmed_api(str(source[0]), profile_filepath)
files = [env.File(f) for f in _get_file_list(api, target[0].abspath, True, True)] files = []
for f in _get_file_list(api, target[0].abspath, True, True):
file = env.File(f)
if profile_filepath:
env.Depends(file, profile_filepath)
files.append(file)
env["godot_cpp_gen_dir"] = target[0].abspath env["godot_cpp_gen_dir"] = target[0].abspath
return files, source return files, source
@@ -530,8 +535,11 @@ def generate(env):
def _godot_cpp(env): def _godot_cpp(env):
extension_dir = normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath), env) extension_dir = normalize_path(env.get("gdextension_dir", default=env.Dir("gdextension").srcnode().abspath), env)
api_file = normalize_path(env.get("custom_api_file", env.File(extension_dir + "/extension_api.json").abspath), env) api_file = normalize_path(
env.get("custom_api_file", default=os.path.join(extension_dir, "extension_api.json")), env
)
bindings = env.GodotCPPBindings( bindings = env.GodotCPPBindings(
env.Dir("."), env.Dir("."),
[ [
@@ -546,15 +554,22 @@ def _godot_cpp(env):
env.NoCache(bindings) env.NoCache(bindings)
# Sources to compile # Sources to compile
sources = [] sources = [
add_sources(sources, "src", "cpp") *env.Glob("src/*.cpp"),
add_sources(sources, "src/classes", "cpp") *env.Glob("src/classes/*.cpp"),
add_sources(sources, "src/core", "cpp") *env.Glob("src/core/*.cpp"),
add_sources(sources, "src/variant", "cpp") *env.Glob("src/variant/*.cpp"),
sources.extend([f for f in bindings if str(f).endswith(".cpp")]) *tuple(f for f in bindings if str(f).endswith(".cpp")),
]
# Includes # Includes
env.AppendUnique(CPPPATH=[env.Dir(d) for d in [extension_dir, "include", "gen/include"]]) env.AppendUnique(
CPPPATH=[
env.Dir(extension_dir),
env.Dir("include").srcnode(),
env.Dir("gen/include"),
]
)
library = None library = None
library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"] library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]