diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2023-06-30 11:44:33 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2023-06-30 16:52:36 +0200 |
commit | cb2be8723a16f9fdb13582562cb630c945dcd0a7 (patch) | |
tree | 20c0c99c5217792e054f876712a54ae8b4f1eec8 | |
parent | d278661d767f5e1f8f68af2d0a706f5f044aa5d3 (diff) | |
download | fork-godot-webrtc-native-cb2be8723a16f9fdb13582562cb630c945dcd0a7.tar.gz fork-godot-webrtc-native-cb2be8723a16f9fdb13582562cb630c945dcd0a7.tar.bz2 fork-godot-webrtc-native-cb2be8723a16f9fdb13582562cb630c945dcd0a7.zip |
Support building for Godot 4.1 (new default).
-rw-r--r-- | .github/workflows/build_release.yml | 30 | ||||
-rw-r--r-- | .gitmodules | 9 | ||||
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | SConstruct | 22 | ||||
m--------- | godot-cpp | 0 | ||||
m--------- | godot-cpp-4.0 | 0 | ||||
-rw-r--r-- | misc/patches/scons_path.diff | 6 | ||||
-rwxr-xr-x | misc/scripts/package_release.sh | 7 | ||||
-rw-r--r-- | misc/webrtc.gdextension | 1 | ||||
-rw-r--r-- | src/WebRTCLibPeerConnection.cpp | 4 | ||||
-rw-r--r-- | src/WebRTCLibPeerConnection.hpp | 4 | ||||
-rw-r--r-- | src/init_gdextension.cpp | 4 |
12 files changed, 71 insertions, 24 deletions
diff --git a/.github/workflows/build_release.yml b/.github/workflows/build_release.yml index 03e6a08..edfb418 100644 --- a/.github/workflows/build_release.yml +++ b/.github/workflows/build_release.yml @@ -177,15 +177,23 @@ jobs: scons --version cmake --version - - name: Compile Extension - template_debug - ${{ matrix.platform }} - ${{ matrix.arch }} + - name: Compile Extension (4.1+) - template_debug - ${{ matrix.platform }} - ${{ matrix.arch }} run: | - scons target=template_debug + scons target=template_debug godot_version=4.1 - - name: Compile Extension - template_release - ${{ matrix.platform }} - ${{ matrix.arch }} + - name: Compile Extension (4.1+) - template_release - ${{ matrix.platform }} - ${{ matrix.arch }} run: | - scons target=template_release + scons target=template_release godot_version=4.1 - - name: Compile GDNative - release ${{ matrix.platform }} - ${{ matrix.arch }} + - 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 + + - name: Compile GDNative (3.5+) - release ${{ matrix.platform }} - ${{ matrix.arch }} run: | scons target=release generate_bindings=yes ${{ matrix.gdnative_flags }} godot_version=3 @@ -226,15 +234,21 @@ jobs: run: | mkdir release - VERSION="extension" TYPE="webrtc" ./misc/scripts/package_release.sh + VERSION="extension-4.1" TYPE="webrtc" ./misc/scripts/package_release.sh + VERSION="extension-4.0" TYPE="webrtc" ./misc/scripts/package_release.sh VERSION="gdnative" TYPE="webrtc" ./misc/scripts/package_release.sh ls -R release - uses: actions/upload-artifact@v3 with: - name: godot-webrtc-extension - path: release/*-extension-*.zip + name: godot-webrtc-extension-4.1 + path: release/*-extension-4.1-*.zip + + - uses: actions/upload-artifact@v3 + with: + name: godot-webrtc-extension-4.0 + path: release/*-extension-4.0-*.zip - uses: actions/upload-artifact@v3 with: diff --git a/.gitmodules b/.gitmodules index cc07501..33c29a8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,12 @@ -[submodule "godot-cpp-3.x"] - path = godot-cpp-3.x - url = https://github.com/godotengine/godot-cpp.git [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 [submodule "libdatachannel"] path = thirdparty/libdatachannel url = https://github.com/paullouisageneau/libdatachannel.git @@ -21,7 +21,7 @@ $ git submodule update --init --recursive ### Compiling the extension. -To build the GDExtension version of the plugin (Godot 4.0) run the following command from the `webrtc-native` folder: +To build the GDExtension version of the plugin (Godot 4.1+) run the following command from the `webrtc-native` folder: ``` $ scons platform=<your platform> @@ -29,6 +29,12 @@ $ scons platform=<your platform> This will build all the required dependencies into a single shared library. +To build the "legacy" GDExtension version of the plugin (Godot 4.0) run the following command instead: + +``` +$ scons platform=<your platform> godot_version=4.0 +``` + To build the GDNative version of the plugin (Godot 3.x) run the following command instead: ``` @@ -18,7 +18,7 @@ def replace_flags(flags, replaces): env = Environment() opts = Variables(["customs.py"], ARGUMENTS) -opts.Add(EnumVariable("godot_version", "The Godot target version", "4", ["3", "4"])) +opts.Add(EnumVariable("godot_version", "The Godot target version", "4.1", ["3", "4.0", "4.1"])) opts.Update(env) # Minimum target platform versions. @@ -96,6 +96,8 @@ if env["godot_version"] == "3": elif not env["use_mingw"]: # Mark as MSVC build (would have failed to build the library otherwise). env["is_msvc"] = True +elif env["godot_version"] == "4.0": + env = SConscript("godot-cpp-4.0/SConstruct").Clone() else: env = SConscript("godot-cpp/SConstruct").Clone() @@ -135,8 +137,10 @@ 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", "webrtc") + result_path = os.path.join("bin", "extension-4.1", "webrtc") # Our includes and sources env.Append(CPPPATH=["src/"]) @@ -148,12 +152,14 @@ sources.append( "src/WebRTCLibPeerConnection.cpp", ] ) -if env["godot_version"] == "4": - sources.append("src/init_gdextension.cpp") -else: +if env["godot_version"] == "3": env.Append(CPPDEFINES=["GDNATIVE_WEBRTC"]) sources.append("src/init_gdnative.cpp") 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"]: @@ -187,6 +193,10 @@ if env["godot_version"] == "3": }, ) else: - extfile = env.InstallAs(os.path.join(result_path, "webrtc.gdextension"), "misc/webrtc.gdextension") + extfile = env.Substfile( + os.path.join(result_path, "webrtc.gdextension"), + "misc/webrtc.gdextension", + SUBST_DICT={"{GODOT_VERSION}": env["godot_version"]}, + ) Default(extfile) diff --git a/godot-cpp b/godot-cpp -Subproject 9d1c396c54fc3bdfcc7da4f3abcb52b14f6cce8 +Subproject 80986f8497b7bec307e0987d01412360d39cbb3 diff --git a/godot-cpp-4.0 b/godot-cpp-4.0 new file mode 160000 +Subproject 9d1c396c54fc3bdfcc7da4f3abcb52b14f6cce8 diff --git a/misc/patches/scons_path.diff b/misc/patches/scons_path.diff index d7273ea..0fab302 100644 --- a/misc/patches/scons_path.diff +++ b/misc/patches/scons_path.diff @@ -1,7 +1,7 @@ -diff --git a/godot-cpp/SConstruct b/godot-cpp/SConstruct +diff --git a/godot-cpp-4.0/SConstruct b/godot-cpp-4.0/SConstruct index 27ee137..32b425e 100644 ---- a/godot-cpp/SConstruct -+++ b/godot-cpp/SConstruct +--- 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. diff --git a/misc/scripts/package_release.sh b/misc/scripts/package_release.sh index a08f441..3ca5a2b 100755 --- a/misc/scripts/package_release.sh +++ b/misc/scripts/package_release.sh @@ -10,6 +10,7 @@ TYPE=${TYPE:-"webrtc"} mkdir -p ${DESTINATION} ls -R ${DESTINATION} +ls -R ${ARTIFACTS} DESTDIR="${DESTINATION}/${VERSION}/${TYPE}" @@ -18,10 +19,10 @@ mkdir -p ${DESTDIR}/lib find "${ARTIFACTS}" -wholename "*/${VERSION}/${TYPE}/lib/*" | xargs cp -t "${DESTDIR}/lib/" find "${ARTIFACTS}" -wholename "*/LICENSE*" | xargs cp -t "${DESTDIR}/" -if [ $VERSION = "extension" ]; then - find "${ARTIFACTS}" -wholename "*/${VERSION}/${TYPE}/${TYPE}.gdextension" | head -n 1 | xargs cp -t "${DESTDIR}/" -else +if [ $VERSION = "gdnative" ]; then find "${ARTIFACTS}" -wholename "*/${VERSION}/${TYPE}/${TYPE}.tres" | head -n 1 | xargs cp -t "${DESTDIR}/" +else + find "${ARTIFACTS}" -wholename "*/${VERSION}/${TYPE}/${TYPE}.gdextension" | head -n 1 | xargs cp -t "${DESTDIR}/" fi CURDIR=$(pwd) diff --git a/misc/webrtc.gdextension b/misc/webrtc.gdextension index 9fe979a..8f930bf 100644 --- a/misc/webrtc.gdextension +++ b/misc/webrtc.gdextension @@ -1,6 +1,7 @@ [configuration] entry_symbol = "webrtc_extension_init" +compatibility_minimum = {GODOT_VERSION} [libraries] diff --git a/src/WebRTCLibPeerConnection.cpp b/src/WebRTCLibPeerConnection.cpp index a372644..effc1d7 100644 --- a/src/WebRTCLibPeerConnection.cpp +++ b/src/WebRTCLibPeerConnection.cpp @@ -180,7 +180,11 @@ Error WebRTCLibPeerConnection::_initialize(const Dictionary &p_config) { return _create_pc(config); } +#if defined(GDNATIVE_WEBRTC) || defined(GDEXTENSION_WEBRTC_40) Object *WebRTCLibPeerConnection::_create_data_channel(const String &p_channel, const Dictionary &p_channel_config) try { +#else +Ref<WebRTCDataChannel> WebRTCLibPeerConnection::_create_data_channel(const String &p_channel, const Dictionary &p_channel_config) try { +#endif ERR_FAIL_COND_V(!peer_connection, nullptr); // Read config from dictionary diff --git a/src/WebRTCLibPeerConnection.hpp b/src/WebRTCLibPeerConnection.hpp index c4f8111..6608735 100644 --- a/src/WebRTCLibPeerConnection.hpp +++ b/src/WebRTCLibPeerConnection.hpp @@ -79,7 +79,11 @@ public: SignalingState _get_signaling_state() const override; godot::Error _initialize(const godot::Dictionary &p_config) override; +#if defined(GDNATIVE_WEBRTC) || defined(GDEXTENSION_WEBRTC_40) godot::Object *_create_data_channel(const godot::String &p_channel, const godot::Dictionary &p_channel_config) override; +#else + godot::Ref<godot::WebRTCDataChannel> _create_data_channel(const godot::String &p_channel, const godot::Dictionary &p_channel_config) override; +#endif godot::Error _create_offer() override; godot::Error _set_remote_description(const godot::String &type, const godot::String &sdp) override; godot::Error _set_local_description(const godot::String &type, const godot::String &sdp) override; diff --git a/src/init_gdextension.cpp b/src/init_gdextension.cpp index 85aed1d..47f8177 100644 --- a/src/init_gdextension.cpp +++ b/src/init_gdextension.cpp @@ -66,7 +66,11 @@ 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); |