Skip to content

Commit

Permalink
Merge pull request #113 from Faless/spike/4.1
Browse files Browse the repository at this point in the history
Support building for Godot 4.1 (new default).
  • Loading branch information
Faless authored Jul 1, 2023
2 parents d278661 + cb2be87 commit 6e2262b
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 25 deletions.
30 changes: 22 additions & 8 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ $ 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>
```

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:

```
Expand Down
22 changes: 16 additions & 6 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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/"])
Expand All @@ -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"]:
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion godot-cpp
Submodule godot-cpp updated 49 files
+71 −0 .github/ISSUE_TEMPLATE/bug_report.yml
+14 −0 .github/ISSUE_TEMPLATE/config.yml
+32 −0 .github/workflows/ci.yml
+1 −1 CMakeLists.txt
+8 −4 README.md
+1 −0 SConstruct
+130 −61 binding_generator.py
+7,997 −841 gdextension/extension_api.json
+1,877 −216 gdextension/gdextension_interface.h
+10 −21 include/godot_cpp/classes/ref.hpp
+81 −81 include/godot_cpp/classes/wrapped.hpp
+3 −3 include/godot_cpp/core/binder_common.hpp
+24 −10 include/godot_cpp/core/class_db.hpp
+5 −5 include/godot_cpp/core/engine_ptrcall.hpp
+1 −1 include/godot_cpp/core/memory.hpp
+2 −2 include/godot_cpp/core/method_bind.hpp
+3 −2 include/godot_cpp/core/method_ptrcall.hpp
+12 −6 include/godot_cpp/core/object.hpp
+2 −2 include/godot_cpp/core/type_info.hpp
+147 −7 include/godot_cpp/godot.hpp
+61 −0 src/classes/editor_plugin.cpp
+5 −5 src/classes/low_level.cpp
+3 −3 src/classes/wrapped.cpp
+19 −9 src/core/class_db.cpp
+4 −4 src/core/error_macros.cpp
+4 −4 src/core/memory.cpp
+1 −1 src/core/method_bind.cpp
+30 −0 src/core/object.cpp
+328 −4 src/godot.cpp
+25 −25 src/variant/char_string.cpp
+42 −42 src/variant/packed_arrays.cpp
+38 −37 src/variant/variant.cpp
+1 −4 test/README.md
+2 −2 test/SConstruct
+0 −80 test/demo/main.gd
+0 −0 test/project/bin/libgdexample.osx.template_debug.framework/Resources/Info.plist
+0 −0 test/project/bin/libgdexample.osx.template_release.framework/Resources/Info.plist
+1 −1 test/project/default_env.tres
+1 −0 test/project/example.gdextension
+ test/project/icon.png
+1 −1 test/project/icon.png.import
+114 −0 test/project/main.gd
+2 −2 test/project/main.tscn
+1 −1 test/project/project.godot
+59 −0 test/project/test_base.gd
+24 −0 test/run-tests.sh
+56 −31 test/src/example.cpp
+11 −1 test/src/example.h
+2 −2 test/src/register_types.cpp
1 change: 1 addition & 0 deletions godot-cpp-4.0
Submodule godot-cpp-4.0 added at 9d1c39
6 changes: 3 additions & 3 deletions misc/patches/scons_path.diff
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 4 additions & 3 deletions misc/scripts/package_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TYPE=${TYPE:-"webrtc"}

mkdir -p ${DESTINATION}
ls -R ${DESTINATION}
ls -R ${ARTIFACTS}

DESTDIR="${DESTINATION}/${VERSION}/${TYPE}"

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions misc/webrtc.gdextension
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[configuration]

entry_symbol = "webrtc_extension_init"
compatibility_minimum = {GODOT_VERSION}

[libraries]

Expand Down
4 changes: 4 additions & 0 deletions src/WebRTCLibPeerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/WebRTCLibPeerConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ 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)
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;
Expand Down
4 changes: 4 additions & 0 deletions src/init_gdextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6e2262b

Please sign in to comment.