From 58c3594cd7d25b1f8e686e6a187b1fb5a83ccb96 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Wed, 18 Jun 2025 14:43:12 -0500 Subject: [PATCH 1/9] Files generated by SCons should depend on the `build_profile` (if given) (cherry picked from commit 646ccdf4701c9efde96712c4695e55be4065ea57) --- tools/godotcpp.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/godotcpp.py b/tools/godotcpp.py index 63df0ad5..fa78ecd1 100644 --- a/tools/godotcpp.py +++ b/tools/godotcpp.py @@ -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)]) 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 return files, source From 9b6a44cb046e6de088d23d7050e361a918dd9ea0 Mon Sep 17 00:00:00 2001 From: Cedric Shock Date: Wed, 10 Apr 2024 19:49:21 -0600 Subject: [PATCH 2/9] Add SCons variant_dir support, which allows specifying a target build directory. (cherry picked from commit 1345c466508c41cec8dad8e0f51c18866fe63d30) --- SConstruct | 7 ++++++- tools/godotcpp.py | 50 ++++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/SConstruct b/SConstruct index 64d335b5..3ebdff94 100644 --- a/SConstruct +++ b/SConstruct @@ -1,6 +1,11 @@ #!/usr/bin/env python 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) EnsurePythonVersion(3, 8) @@ -27,7 +32,7 @@ if profile: elif os.path.isfile(profile + ".py"): customs.append(profile + ".py") opts = Variables(customs, ARGUMENTS) -cpp_tool = Tool("godotcpp", toolpath=["tools"]) +cpp_tool = Tool("godotcpp", toolpath=[Dir("tools").srcnode().abspath]) cpp_tool.options(opts, env) opts.Update(env) diff --git a/tools/godotcpp.py b/tools/godotcpp.py index fa78ecd1..f0a5cf20 100644 --- a/tools/godotcpp.py +++ b/tools/godotcpp.py @@ -16,12 +16,6 @@ from build_profile import generate_trimmed_api 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): """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. @@ -34,7 +28,12 @@ def get_cmdline_bool(option, default): 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): @@ -54,9 +53,10 @@ def validate_parent_dir(key, val, env): def get_platform_tools_paths(env): path = env.get("custom_tools", None) + tools_path = env.Dir("tools").srcnode().abspath if path is None: - return ["tools"] - return [normalize_path(path, env), "tools"] + return [tools_path] + return [normalize_path(path, env), tools_path] def get_custom_platforms(env): @@ -258,7 +258,8 @@ def options(opts, env): help="Path to a custom directory containing GDExtension interface header and API JSON file", default=env.get("gdextension_dir", None), validator=validate_dir, - ) + ), + converter=normalize_path, ) opts.Add( PathVariable( @@ -266,7 +267,8 @@ def options(opts, env): help="Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)", default=env.get("custom_api_file", None), validator=validate_file, - ) + ), + converter=normalize_path, ) opts.Add( BoolVariable( @@ -535,8 +537,9 @@ def generate(env): def _godot_cpp(env): - extension_dir = normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath), env) - api_file = normalize_path(env.get("custom_api_file", env.File(extension_dir + "/extension_api.json").abspath), env) + extension_dir = env.get("gdextension_dir", default=env.Dir("gdextension").srcnode().abspath) + api_file = env.get("custom_api_file", default=os.path.join(extension_dir, "extension_api.json")) + bindings = env.GodotCPPBindings( env.Dir("."), [ @@ -551,15 +554,22 @@ def _godot_cpp(env): env.NoCache(bindings) # Sources to compile - sources = [] - add_sources(sources, "src", "cpp") - add_sources(sources, "src/classes", "cpp") - add_sources(sources, "src/core", "cpp") - add_sources(sources, "src/variant", "cpp") - sources.extend([f for f in bindings if str(f).endswith(".cpp")]) + sources = [ + *env.Glob("src/*.cpp"), + *env.Glob("src/classes/*.cpp"), + *env.Glob("src/core/*.cpp"), + *env.Glob("src/variant/*.cpp"), + *tuple(f for f in bindings if str(f).endswith(".cpp")), + ] # 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_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"] From d7bdc62a9160e4e20cb57494034bb8877f5d32d9 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Thu, 17 Jul 2025 09:03:11 -0500 Subject: [PATCH 3/9] Fix `custom_api_file` with SCons 4.0.1 (cherry picked from commit 8e7dfbc71aad709c78d403dd954802e76a4337fa) --- tools/godotcpp.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/godotcpp.py b/tools/godotcpp.py index f0a5cf20..7be96247 100644 --- a/tools/godotcpp.py +++ b/tools/godotcpp.py @@ -258,8 +258,7 @@ def options(opts, env): help="Path to a custom directory containing GDExtension interface header and API JSON file", default=env.get("gdextension_dir", None), validator=validate_dir, - ), - converter=normalize_path, + ) ) opts.Add( PathVariable( @@ -267,8 +266,7 @@ def options(opts, env): help="Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)", default=env.get("custom_api_file", None), validator=validate_file, - ), - converter=normalize_path, + ) ) opts.Add( BoolVariable( @@ -537,8 +535,10 @@ def generate(env): def _godot_cpp(env): - extension_dir = env.get("gdextension_dir", default=env.Dir("gdextension").srcnode().abspath) - api_file = env.get("custom_api_file", default=os.path.join(extension_dir, "extension_api.json")) + extension_dir = normalize_path(env.get("gdextension_dir", default=env.Dir("gdextension").srcnode().abspath), env) + api_file = normalize_path( + env.get("custom_api_file", default=os.path.join(extension_dir, "extension_api.json")), env + ) bindings = env.GodotCPPBindings( env.Dir("."), From a8faa36fd2d75962b2aa3a7a0120a630a0f965f2 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Sun, 13 Jul 2025 00:08:50 -0400 Subject: [PATCH 4/9] Reintroduce Math_INF and Math_NAN defines (cherry picked from commit 6a21f76c4dda8cc63510d77f34c8067e40944974) --- include/godot_cpp/core/math_defs.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/godot_cpp/core/math_defs.hpp b/include/godot_cpp/core/math_defs.hpp index 73d86148..89b383c7 100644 --- a/include/godot_cpp/core/math_defs.hpp +++ b/include/godot_cpp/core/math_defs.hpp @@ -44,6 +44,8 @@ namespace godot { #define Math_TAU 6.2831853071795864769252867666 #define Math_PI 3.1415926535897932384626433833 #define Math_E 2.7182818284590452353602874714 +#define Math_INF INFINITY +#define Math_NAN NAN #ifdef DEBUG_ENABLED #define MATH_CHECKS From 9d8c520bb9e99f4f36f085700dea9bf2df039e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Fri, 1 Aug 2025 16:00:44 +0200 Subject: [PATCH 5/9] fix: missing `type_traits` include Usage of `std::is_trivially_constructible` in `defs.hpp` requires including `type_traits`. This missing include leads to errors about that type not being found when building with clang++-22 with libc++-22. (cherry picked from commit fbe5262d7b90f307893e347beb00766fbd71ac86) --- include/godot_cpp/core/defs.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/godot_cpp/core/defs.hpp b/include/godot_cpp/core/defs.hpp index 9395f201..fddfa51d 100644 --- a/include/godot_cpp/core/defs.hpp +++ b/include/godot_cpp/core/defs.hpp @@ -32,6 +32,7 @@ #include #include +#include #include namespace godot { From 0eeb43c4beb1212315b4eb789431d4a36ecb5a73 Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Sat, 9 Aug 2025 17:36:34 -0500 Subject: [PATCH 6/9] Fix debug symbols logic on platform=web to match Godot core. (cherry picked from commit 9ea9b4797c447b231800694e3b11f21bc365fc48) --- tools/common_compiler_flags.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/common_compiler_flags.py b/tools/common_compiler_flags.py index e645f390..05f95d7a 100644 --- a/tools/common_compiler_flags.py +++ b/tools/common_compiler_flags.py @@ -2,6 +2,10 @@ import os import subprocess +def using_emcc(env): + return "emcc" in os.path.basename(env["CC"]) + + def using_clang(env): 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, # otherwise addr2line doesn't understand them. 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"]) else: env.Append(CCFLAGS=["-g2"]) From cf79eb39da66a78d0d29641db4bcee555f7f1c4e Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Sat, 9 Aug 2025 12:19:21 -0500 Subject: [PATCH 7/9] Only check for Godot 4.0 if the pointer is aligned how it would be for the legacy interface. (cherry picked from commit 05d2ce300624e73a96f5e73bd4fbc69e429a5f0a) --- src/godot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/godot.cpp b/src/godot.cpp index 31a64c46..e73554b9 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -286,7 +286,7 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge // Make sure we weren't passed the legacy struct. 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. LegacyGDExtensionInterface *legacy_interface = (LegacyGDExtensionInterface *)p_get_proc_address; internal::gdextension_interface_print_error = (GDExtensionInterfacePrintError)legacy_interface->print_error; From b842dc969654aa2ab7dafb132bf6999440a0aaf4 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Wed, 20 Aug 2025 11:13:28 -0500 Subject: [PATCH 8/9] Take reference in `Wrapped(const StringName &)` (cherry picked from commit b192b880d37f4cb038186e89d6df2d0711136be7) --- include/godot_cpp/classes/wrapped.hpp | 2 +- src/classes/wrapped.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index f54544bc..f1edf66a 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -111,7 +111,7 @@ protected: void _postinitialize(); - Wrapped(const StringName p_godot_class); + Wrapped(const StringName &p_godot_class); Wrapped(GodotObject *p_godot_object); virtual ~Wrapped() {} diff --git a/src/classes/wrapped.cpp b/src/classes/wrapped.cpp index e729ba02..c5a8cc9f 100644 --- a/src/classes/wrapped.cpp +++ b/src/classes/wrapped.cpp @@ -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 if (unlikely(Wrapped::_constructing_recreate_owner)) { _owner = Wrapped::_constructing_recreate_owner; From ad484bcdbb62f87c8f4e935ef5f796df0106ac4d Mon Sep 17 00:00:00 2001 From: Samuel Nicholas Date: Tue, 8 Jul 2025 15:28:33 +0930 Subject: [PATCH 9/9] CMake: Add GODOTCPP_SUFFIX_GENEX variable This is the same as GODOTCPP_SUFFIX but without the leading '.' GODOTCPP_SUFFIX is then based on the above. (cherry picked from commit b64b941adf63b22d9040aab4f1fa9502079f3ad9) --- cmake/godotcpp.cmake | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cmake/godotcpp.cmake b/cmake/godotcpp.cmake index a0c544fc..7c4ea686 100644 --- a/cmake/godotcpp.cmake +++ b/cmake/godotcpp.cmake @@ -319,11 +319,11 @@ function(godotcpp_generate) set(DEBUG_FEATURES "$>") set(HOT_RELOAD "$>") - # Suffix + # Suffix Generator Expression string( CONCAT - GODOTCPP_SUFFIX - "$<1:.${SYSTEM_NAME}>" + GODOTCPP_SUFFIX_GENEX + "$<1:${SYSTEM_NAME}>" "$<1:.${GODOTCPP_TARGET}>" "$<${IS_DEV_BUILD}:.dev>" "$<$:.double>" @@ -331,6 +331,8 @@ function(godotcpp_generate) # TODO IOS_SIMULATOR "$<$:.nothreads>" ) + # The same as above, but with a leading '.' to maintain backwards compatibility. + set(GODOTCPP_SUFFIX ".${GODOTCPP_SUFFIX_GENEX}") # the godot-cpp.* library targets add_library(godot-cpp STATIC) @@ -370,11 +372,12 @@ function(godotcpp_generate) ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>" # Things that are handy to know for dependent targets - GODOTCPP_PLATFORM "${SYSTEM_NAME}" - GODOTCPP_TARGET "${GODOTCPP_TARGET}" - GODOTCPP_ARCH "${ARCH_NAME}" - GODOTCPP_PRECISION "${GODOTCPP_PRECISION}" - GODOTCPP_SUFFIX "${GODOTCPP_SUFFIX}" + GODOTCPP_PLATFORM "${SYSTEM_NAME}" + GODOTCPP_TARGET "${GODOTCPP_TARGET}" + GODOTCPP_ARCH "${ARCH_NAME}" + GODOTCPP_PRECISION "${GODOTCPP_PRECISION}" + GODOTCPP_SUFFIX "${GODOTCPP_SUFFIX}" + GODOTCPP_SUFFIX_GENEX "${GODOTCPP_SUFFIX_GENEX}" # Some IDE's respect this property to logically group targets FOLDER "godot-cpp"