diff --git a/.github/workflows/build_release.yml b/.github/workflows/build_release.yml index 1aa7d48..90903d7 100644 --- a/.github/workflows/build_release.yml +++ b/.github/workflows/build_release.yml @@ -199,7 +199,6 @@ jobs: - name: Patch godot-cpp to support build profile. run: | patch -p1 < misc/patches/build_profile.diff - patch -p1 < misc/patches/build_profile_4.0.diff patch -p1 < misc/patches/build_profile_3.x.diff - name: Print tools versions @@ -210,19 +209,11 @@ jobs: - name: Compile Extension (4.1+) - template_debug - ${{ matrix.platform }} - ${{ matrix.arch }} run: | - scons target=template_debug godot_version=4.1 + scons target=template_debug godot_version=4 - name: Compile Extension (4.1+) - template_release - ${{ matrix.platform }} - ${{ matrix.arch }} run: | - scons target=template_release godot_version=4.1 - - - name: Compile Extension (4.0) - template_debug - ${{ matrix.platform }} - ${{ matrix.arch }} - run: | - scons target=template_debug godot_version=4.0 - - - name: Compile Extension (4.0) - template_release - ${{ matrix.platform }} - ${{ matrix.arch }} - run: | - scons target=template_release godot_version=4.0 + scons target=template_release godot_version=4 - name: Compile GDNative (3.5+) - release ${{ matrix.platform }} - ${{ matrix.arch }} run: | @@ -265,21 +256,15 @@ jobs: run: | mkdir release - VERSION="extension-4.1" TYPE="webrtc" ./misc/scripts/package_release.sh - VERSION="extension-4.0" TYPE="webrtc" ./misc/scripts/package_release.sh + VERSION="extension" TYPE="webrtc" ./misc/scripts/package_release.sh VERSION="gdnative" TYPE="webrtc" ./misc/scripts/package_release.sh ls -R release - uses: actions/upload-artifact@v4 with: - name: godot-webrtc-extension-4.1 - path: release/*-extension-4.1-*.zip - - - uses: actions/upload-artifact@v4 - with: - name: godot-webrtc-extension-4.0 - path: release/*-extension-4.0-*.zip + name: godot-webrtc-extension + path: release/*-extension-*.zip - uses: actions/upload-artifact@v4 with: diff --git a/.gitmodules b/.gitmodules index 33c29a8..ed1bc99 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "godot-cpp"] path = godot-cpp url = https://github.com/godotengine/godot-cpp.git -[submodule "godot-cpp-4.0"] - path = godot-cpp-4.0 - url = https://github.com/godotengine/godot-cpp.git [submodule "godot-cpp-3.x"] path = godot-cpp-3.x url = https://github.com/godotengine/godot-cpp.git diff --git a/SConstruct b/SConstruct index 63b28b9..ac5de14 100644 --- a/SConstruct +++ b/SConstruct @@ -28,7 +28,7 @@ def validate_godotcpp_dir(key, val, env): env = Environment() opts = Variables(["customs.py"], ARGUMENTS) -opts.Add(EnumVariable("godot_version", "The Godot target version", "4.1", ["3", "4.0", "4.1"])) +opts.Add(EnumVariable("godot_version", "The Godot target version", "4", ["3", "4"], {"4.1+": "4", "4.1": "4"})) opts.Add( PathVariable( "godot_cpp", @@ -122,10 +122,6 @@ if env["godot_version"] == "3": if env["platform"] == "linux" and env["arch"] not in ("x86_32", "x86_64"): for flags in (env["CCFLAGS"], env["LINKFLAGS"], cpp_env["CCFLAGS"], cpp_env["LINKFLAGS"]): replace_flags(flags, {"-m32": None, "-m64": None}) -elif env["godot_version"] == "4.0": - sconstruct = env.get("godot_cpp", "godot-cpp-4.0") + "/SConstruct" - cpp_env = SConscript(sconstruct) - env = cpp_env.Clone() else: sconstruct = env.get("godot_cpp", "godot-cpp") + "/SConstruct" cpp_env = SConscript(sconstruct) @@ -160,10 +156,8 @@ opts.Update(env) target = env["target"] if env["godot_version"] == "3": result_path = os.path.join("bin", "gdnative", "webrtc" if env["target"] == "release" else "webrtc_debug") -elif env["godot_version"] == "4.0": - result_path = os.path.join("bin", "extension-4.0", "webrtc") else: - result_path = os.path.join("bin", "extension-4.1", "webrtc") + result_path = os.path.join("bin", "extension", "webrtc") # Our includes and sources env.Append(CPPPATH=["src/"]) @@ -181,8 +175,6 @@ if env["godot_version"] == "3": add_sources(sources, "src/net/", "cpp") else: sources.append("src/init_gdextension.cpp") - if env["godot_version"] == "4.0": - env.Append(CPPDEFINES=["GDEXTENSION_WEBRTC_40"]) # Add our build tools for tool in ["openssl", "cmake", "rtc"]: diff --git a/godot-cpp-4.0 b/godot-cpp-4.0 deleted file mode 160000 index 9d1c396..0000000 --- a/godot-cpp-4.0 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9d1c396c54fc3bdfcc7da4f3abcb52b14f6cce8f diff --git a/misc/patches/build_profile_4.0.diff b/misc/patches/build_profile_4.0.diff deleted file mode 100644 index ee44112..0000000 --- a/misc/patches/build_profile_4.0.diff +++ /dev/null @@ -1,180 +0,0 @@ -diff --git a/godot-cpp-4.0/SConstruct b/godot-cpp-4.0/SConstruct -index 27ee137..ec2af72 100644 ---- a/godot-cpp-4.0/SConstruct -+++ b/godot-cpp-4.0/SConstruct -@@ -119,6 +119,14 @@ opts.Add( - opts.Add( - BoolVariable("generate_bindings", "Force GDExtension API bindings generation. Auto-detected by default.", False) - ) -+opts.Add( -+ PathVariable( -+ "build_profile", -+ "Path to a file containing a feature build profile", -+ default=env.get("build_profile", None), -+ validator=lambda key, val, env: os.path.isfile(normalize_path(val)), -+ ) -+) - opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True)) - - opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True)) -diff --git a/godot-cpp-4.0/binding_generator.py b/godot-cpp-4.0/binding_generator.py -index 7634942..7ab51a5 100644 ---- a/godot-cpp-4.0/binding_generator.py -+++ b/godot-cpp-4.0/binding_generator.py -@@ -70,12 +70,14 @@ def generate_wrappers(target): - f.write(txt) - - --def get_file_list(api_filepath, output_dir, headers=False, sources=False): -+def get_file_list(api_filepath, output_dir, headers=False, sources=False, profile_filepath=""): - api = {} - files = [] - with open(api_filepath) as api_file: - api = json.load(api_file) - -+ build_profile = parse_build_profile(profile_filepath, api) -+ - core_gen_folder = Path(output_dir) / "gen" / "include" / "godot_cpp" / "core" - include_gen_folder = Path(output_dir) / "gen" / "include" / "godot_cpp" - source_gen_folder = Path(output_dir) / "gen" / "src" -@@ -104,7 +106,7 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False): - source_filename = source_gen_folder / "classes" / (camel_to_snake(engine_class["name"]) + ".cpp") - if headers: - files.append(str(header_filename.as_posix())) -- if sources: -+ if sources and is_class_included(engine_class["name"], build_profile): - files.append(str(source_filename.as_posix())) - - for native_struct in api["native_structures"]: -@@ -132,14 +134,107 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False): - return files - - --def print_file_list(api_filepath, output_dir, headers=False, sources=False): -+def print_file_list(api_filepath, output_dir, headers=False, sources=False, profile_filepath=""): - end = ";" -- for f in get_file_list(api_filepath, output_dir, headers, sources): -+ for f in get_file_list(api_filepath, output_dir, headers, sources, profile_filepath): - print(f, end=end) - - -+def parse_build_profile(profile_filepath, api): -+ if profile_filepath == "": -+ return {} -+ print("Using feature build profile: " + profile_filepath) -+ -+ with open(profile_filepath, encoding="utf-8") as profile_file: -+ profile = json.load(profile_file) -+ -+ api_dict = {} -+ parents = {} -+ children = {} -+ for engine_class in api["classes"]: -+ api_dict[engine_class["name"]] = engine_class -+ parent = engine_class.get("inherits", "") -+ child = engine_class["name"] -+ parents[child] = parent -+ if parent == "": -+ continue -+ children[parent] = children.get(parent, []) -+ children[parent].append(child) -+ -+ # Parse methods dependencies -+ deps = {} -+ reverse_deps = {} -+ for name, engine_class in api_dict.items(): -+ ref_cls = set() -+ for method in engine_class.get("methods", []): -+ rtype = method.get("return_value", {}).get("type", "") -+ args = [a["type"] for a in method.get("arguments", [])] -+ if rtype in api_dict: -+ ref_cls.add(rtype) -+ elif is_enum(rtype) and get_enum_class(rtype) in api_dict: -+ ref_cls.add(get_enum_class(rtype)) -+ for arg in args: -+ if arg in api_dict: -+ ref_cls.add(arg) -+ elif is_enum(arg) and get_enum_class(arg) in api_dict: -+ ref_cls.add(get_enum_class(arg)) -+ deps[engine_class["name"]] = set(filter(lambda x: x != name, ref_cls)) -+ for acls in ref_cls: -+ if acls == name: -+ continue -+ reverse_deps[acls] = reverse_deps.get(acls, set()) -+ reverse_deps[acls].add(name) -+ -+ included = [] -+ front = list(profile.get("enabled_classes", [])) -+ if front: -+ # These must always be included -+ front.append("WorkerThreadPool") -+ front.append("ClassDB") -+ front.append("ClassDBSingleton") -+ while front: -+ cls = front.pop() -+ if cls in included: -+ continue -+ included.append(cls) -+ parent = parents.get(cls, "") -+ if parent: -+ front.append(parent) -+ for rcls in deps.get(cls, set()): -+ if rcls in included or rcls in front: -+ continue -+ front.append(rcls) -+ -+ excluded = [] -+ front = list(profile.get("disabled_classes", [])) -+ while front: -+ cls = front.pop() -+ if cls in excluded: -+ continue -+ excluded.append(cls) -+ front += children.get(cls, []) -+ for rcls in reverse_deps.get(cls, set()): -+ if rcls in excluded or rcls in front: -+ continue -+ front.append(rcls) -+ -+ if included and excluded: -+ print( -+ "WARNING: Cannot specify both 'enabled_classes' and 'disabled_classes' in build profile. 'disabled_classes' will be ignored." -+ ) -+ -+ return { -+ "enabled_classes": included, -+ "disabled_classes": excluded, -+ } -+ -+ - def scons_emit_files(target, source, env): -- files = [env.File(f) for f in get_file_list(str(source[0]), target[0].abspath, True, True)] -+ profile_filepath = env.get("build_profile", "") -+ if profile_filepath and not Path(profile_filepath).is_absolute(): -+ profile_filepath = str((Path(env.Dir("#").abspath) / profile_filepath).as_posix()) -+ -+ files = [env.File(f) for f in get_file_list(str(source[0]), target[0].abspath, True, True, profile_filepath)] - env.Clean(target, files) - env["godot_cpp_gen_dir"] = target[0].abspath - return files, source -@@ -1997,6 +2092,20 @@ def is_pod_type(type_name): - ] - - -+def is_class_included(class_name, build_profile): -+ """ -+ Check if an engine class should be included. -+ This removes classes according to a build profile of enabled or disabled classes. -+ """ -+ included = build_profile.get("enabled_classes", []) -+ excluded = build_profile.get("disabled_classes", []) -+ if included: -+ return class_name in included -+ if excluded: -+ return class_name not in excluded -+ return True -+ -+ - def is_included_type(type_name): - # Types which we already have implemented. - return is_included_struct_type(type_name) or type_name in ["ObjectID"] diff --git a/misc/patches/scons_path.diff b/misc/patches/scons_path.diff index 0fab302..0dcd8c1 100644 --- a/misc/patches/scons_path.diff +++ b/misc/patches/scons_path.diff @@ -1,17 +1,3 @@ -diff --git a/godot-cpp-4.0/SConstruct b/godot-cpp-4.0/SConstruct -index 27ee137..32b425e 100644 ---- a/godot-cpp-4.0/SConstruct -+++ b/godot-cpp-4.0/SConstruct -@@ -54,6 +54,8 @@ else: - # Default tools with no platform defaults to gnu toolchain. - # We apply platform specific toolchains via our custom tools. - env = Environment(tools=["default"], PLATFORM="") -+# Allows us to use Godot buildroot toolchain -+env.PrependENVPath("PATH", os.getenv("PATH")) - - # Default num_jobs to local cpu count if not user specified. - # SCons has a peculiarity where user-specified options won't be overridden - diff --git a/godot-cpp-3.x/SConstruct b/godot-cpp-3.x/SConstruct index f653d54..6f40377 100644 --- a/godot-cpp-3.x/SConstruct diff --git a/src/WebRTCLibPeerConnection.cpp b/src/WebRTCLibPeerConnection.cpp index bc730a7..681fb6f 100644 --- a/src/WebRTCLibPeerConnection.cpp +++ b/src/WebRTCLibPeerConnection.cpp @@ -199,7 +199,7 @@ Error WebRTCLibPeerConnection::_initialize(const Dictionary &p_config) { return _create_pc(config); } -#if defined(GDNATIVE_WEBRTC) || defined(GDEXTENSION_WEBRTC_40) +#if defined(GDNATIVE_WEBRTC) Object *WebRTCLibPeerConnection::_create_data_channel(const String &p_channel, const Dictionary &p_channel_config) try { #else Ref WebRTCLibPeerConnection::_create_data_channel(const String &p_channel, const Dictionary &p_channel_config) try { diff --git a/src/WebRTCLibPeerConnection.hpp b/src/WebRTCLibPeerConnection.hpp index 1bcb29e..c2de7e9 100644 --- a/src/WebRTCLibPeerConnection.hpp +++ b/src/WebRTCLibPeerConnection.hpp @@ -83,7 +83,7 @@ class WebRTCLibPeerConnection : public godot::WebRTCPeerConnectionExtension { SignalingState _get_signaling_state() const override; godot::Error _initialize(const godot::Dictionary &p_config) override; -#if defined(GDNATIVE_WEBRTC) || defined(GDEXTENSION_WEBRTC_40) +#if defined(GDNATIVE_WEBRTC) godot::Object *_create_data_channel(const godot::String &p_channel, const godot::Dictionary &p_channel_config) override; #else godot::Ref _create_data_channel(const godot::String &p_channel, const godot::Dictionary &p_channel_config) override; diff --git a/src/init_gdextension.cpp b/src/init_gdextension.cpp index 47f8177..547236a 100644 --- a/src/init_gdextension.cpp +++ b/src/init_gdextension.cpp @@ -66,11 +66,7 @@ void unregister_webrtc_extension_types(ModuleInitializationLevel p_level) { } extern "C" { -#ifdef GDEXTENSION_WEBRTC_40 -GDExtensionBool GDE_EXPORT webrtc_extension_init(const GDExtensionInterface *p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) { -#else GDExtensionBool GDE_EXPORT webrtc_extension_init(const GDExtensionInterfaceGetProcAddress p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) { -#endif GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization); init_obj.register_initializer(register_webrtc_extension_types);