Skip to content

Commit cb2be87

Browse files
committed
Support building for Godot 4.1 (new default).
1 parent d278661 commit cb2be87

12 files changed

+73
-25
lines changed

.github/workflows/build_release.yml

+22-8
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,23 @@ jobs:
177177
scons --version
178178
cmake --version
179179
180-
- name: Compile Extension - template_debug - ${{ matrix.platform }} - ${{ matrix.arch }}
180+
- name: Compile Extension (4.1+) - template_debug - ${{ matrix.platform }} - ${{ matrix.arch }}
181181
run: |
182-
scons target=template_debug
182+
scons target=template_debug godot_version=4.1
183183
184-
- name: Compile Extension - template_release - ${{ matrix.platform }} - ${{ matrix.arch }}
184+
- name: Compile Extension (4.1+) - template_release - ${{ matrix.platform }} - ${{ matrix.arch }}
185185
run: |
186-
scons target=template_release
186+
scons target=template_release godot_version=4.1
187187
188-
- name: Compile GDNative - release ${{ matrix.platform }} - ${{ matrix.arch }}
188+
- name: Compile Extension (4.0) - template_debug - ${{ matrix.platform }} - ${{ matrix.arch }}
189+
run: |
190+
scons target=template_debug godot_version=4.0
191+
192+
- name: Compile Extension (4.0) - template_release - ${{ matrix.platform }} - ${{ matrix.arch }}
193+
run: |
194+
scons target=template_release godot_version=4.0
195+
196+
- name: Compile GDNative (3.5+) - release ${{ matrix.platform }} - ${{ matrix.arch }}
189197
run: |
190198
scons target=release generate_bindings=yes ${{ matrix.gdnative_flags }} godot_version=3
191199
@@ -226,15 +234,21 @@ jobs:
226234
run: |
227235
mkdir release
228236
229-
VERSION="extension" TYPE="webrtc" ./misc/scripts/package_release.sh
237+
VERSION="extension-4.1" TYPE="webrtc" ./misc/scripts/package_release.sh
238+
VERSION="extension-4.0" TYPE="webrtc" ./misc/scripts/package_release.sh
230239
VERSION="gdnative" TYPE="webrtc" ./misc/scripts/package_release.sh
231240
232241
ls -R release
233242
234243
- uses: actions/upload-artifact@v3
235244
with:
236-
name: godot-webrtc-extension
237-
path: release/*-extension-*.zip
245+
name: godot-webrtc-extension-4.1
246+
path: release/*-extension-4.1-*.zip
247+
248+
- uses: actions/upload-artifact@v3
249+
with:
250+
name: godot-webrtc-extension-4.0
251+
path: release/*-extension-4.0-*.zip
238252

239253
- uses: actions/upload-artifact@v3
240254
with:

.gitmodules

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
[submodule "godot-cpp-3.x"]
2-
path = godot-cpp-3.x
3-
url = https://github.com/godotengine/godot-cpp.git
41
[submodule "godot-cpp"]
52
path = godot-cpp
63
url = https://github.com/godotengine/godot-cpp.git
4+
[submodule "godot-cpp-4.0"]
5+
path = godot-cpp-4.0
6+
url = https://github.com/godotengine/godot-cpp.git
7+
[submodule "godot-cpp-3.x"]
8+
path = godot-cpp-3.x
9+
url = https://github.com/godotengine/godot-cpp.git
710
[submodule "libdatachannel"]
811
path = thirdparty/libdatachannel
912
url = https://github.com/paullouisageneau/libdatachannel.git

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ $ git submodule update --init --recursive
2121

2222
### Compiling the extension.
2323

24-
To build the GDExtension version of the plugin (Godot 4.0) run the following command from the `webrtc-native` folder:
24+
To build the GDExtension version of the plugin (Godot 4.1+) run the following command from the `webrtc-native` folder:
2525

2626
```
2727
$ scons platform=<your platform>
2828
```
2929

3030
This will build all the required dependencies into a single shared library.
3131

32+
To build the "legacy" GDExtension version of the plugin (Godot 4.0) run the following command instead:
33+
34+
```
35+
$ scons platform=<your platform> godot_version=4.0
36+
```
37+
3238
To build the GDNative version of the plugin (Godot 3.x) run the following command instead:
3339

3440
```

SConstruct

+16-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def replace_flags(flags, replaces):
1818

1919
env = Environment()
2020
opts = Variables(["customs.py"], ARGUMENTS)
21-
opts.Add(EnumVariable("godot_version", "The Godot target version", "4", ["3", "4"]))
21+
opts.Add(EnumVariable("godot_version", "The Godot target version", "4.1", ["3", "4.0", "4.1"]))
2222
opts.Update(env)
2323

2424
# Minimum target platform versions.
@@ -96,6 +96,8 @@ if env["godot_version"] == "3":
9696
elif not env["use_mingw"]:
9797
# Mark as MSVC build (would have failed to build the library otherwise).
9898
env["is_msvc"] = True
99+
elif env["godot_version"] == "4.0":
100+
env = SConscript("godot-cpp-4.0/SConstruct").Clone()
99101
else:
100102
env = SConscript("godot-cpp/SConstruct").Clone()
101103

@@ -135,8 +137,10 @@ opts.Update(env)
135137
target = env["target"]
136138
if env["godot_version"] == "3":
137139
result_path = os.path.join("bin", "gdnative", "webrtc" if env["target"] == "release" else "webrtc_debug")
140+
elif env["godot_version"] == "4.0":
141+
result_path = os.path.join("bin", "extension-4.0", "webrtc")
138142
else:
139-
result_path = os.path.join("bin", "extension", "webrtc")
143+
result_path = os.path.join("bin", "extension-4.1", "webrtc")
140144

141145
# Our includes and sources
142146
env.Append(CPPPATH=["src/"])
@@ -148,12 +152,14 @@ sources.append(
148152
"src/WebRTCLibPeerConnection.cpp",
149153
]
150154
)
151-
if env["godot_version"] == "4":
152-
sources.append("src/init_gdextension.cpp")
153-
else:
155+
if env["godot_version"] == "3":
154156
env.Append(CPPDEFINES=["GDNATIVE_WEBRTC"])
155157
sources.append("src/init_gdnative.cpp")
156158
add_sources(sources, "src/net/", "cpp")
159+
else:
160+
sources.append("src/init_gdextension.cpp")
161+
if env["godot_version"] == "4.0":
162+
env.Append(CPPDEFINES=["GDEXTENSION_WEBRTC_40"])
157163

158164
# Add our build tools
159165
for tool in ["openssl", "cmake", "rtc"]:
@@ -187,6 +193,10 @@ if env["godot_version"] == "3":
187193
},
188194
)
189195
else:
190-
extfile = env.InstallAs(os.path.join(result_path, "webrtc.gdextension"), "misc/webrtc.gdextension")
196+
extfile = env.Substfile(
197+
os.path.join(result_path, "webrtc.gdextension"),
198+
"misc/webrtc.gdextension",
199+
SUBST_DICT={"{GODOT_VERSION}": env["godot_version"]},
200+
)
191201

192202
Default(extfile)

godot-cpp

Submodule godot-cpp updated 49 files

godot-cpp-4.0

Submodule godot-cpp-4.0 added at 9d1c396

misc/patches/scons_path.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
diff --git a/godot-cpp/SConstruct b/godot-cpp/SConstruct
1+
diff --git a/godot-cpp-4.0/SConstruct b/godot-cpp-4.0/SConstruct
22
index 27ee137..32b425e 100644
3-
--- a/godot-cpp/SConstruct
4-
+++ b/godot-cpp/SConstruct
3+
--- a/godot-cpp-4.0/SConstruct
4+
+++ b/godot-cpp-4.0/SConstruct
55
@@ -54,6 +54,8 @@ else:
66
# Default tools with no platform defaults to gnu toolchain.
77
# We apply platform specific toolchains via our custom tools.

misc/scripts/package_release.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ TYPE=${TYPE:-"webrtc"}
1010

1111
mkdir -p ${DESTINATION}
1212
ls -R ${DESTINATION}
13+
ls -R ${ARTIFACTS}
1314

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

@@ -18,10 +19,10 @@ mkdir -p ${DESTDIR}/lib
1819
find "${ARTIFACTS}" -wholename "*/${VERSION}/${TYPE}/lib/*" | xargs cp -t "${DESTDIR}/lib/"
1920
find "${ARTIFACTS}" -wholename "*/LICENSE*" | xargs cp -t "${DESTDIR}/"
2021

21-
if [ $VERSION = "extension" ]; then
22-
find "${ARTIFACTS}" -wholename "*/${VERSION}/${TYPE}/${TYPE}.gdextension" | head -n 1 | xargs cp -t "${DESTDIR}/"
23-
else
22+
if [ $VERSION = "gdnative" ]; then
2423
find "${ARTIFACTS}" -wholename "*/${VERSION}/${TYPE}/${TYPE}.tres" | head -n 1 | xargs cp -t "${DESTDIR}/"
24+
else
25+
find "${ARTIFACTS}" -wholename "*/${VERSION}/${TYPE}/${TYPE}.gdextension" | head -n 1 | xargs cp -t "${DESTDIR}/"
2526
fi
2627

2728
CURDIR=$(pwd)

misc/webrtc.gdextension

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[configuration]
22

33
entry_symbol = "webrtc_extension_init"
4+
compatibility_minimum = {GODOT_VERSION}
45

56
[libraries]
67

src/WebRTCLibPeerConnection.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ Error WebRTCLibPeerConnection::_initialize(const Dictionary &p_config) {
180180
return _create_pc(config);
181181
}
182182

183+
#if defined(GDNATIVE_WEBRTC) || defined(GDEXTENSION_WEBRTC_40)
183184
Object *WebRTCLibPeerConnection::_create_data_channel(const String &p_channel, const Dictionary &p_channel_config) try {
185+
#else
186+
Ref<WebRTCDataChannel> WebRTCLibPeerConnection::_create_data_channel(const String &p_channel, const Dictionary &p_channel_config) try {
187+
#endif
184188
ERR_FAIL_COND_V(!peer_connection, nullptr);
185189

186190
// Read config from dictionary

src/WebRTCLibPeerConnection.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ class WebRTCLibPeerConnection : public godot::WebRTCPeerConnectionExtension {
7979
SignalingState _get_signaling_state() const override;
8080

8181
godot::Error _initialize(const godot::Dictionary &p_config) override;
82+
#if defined(GDNATIVE_WEBRTC) || defined(GDEXTENSION_WEBRTC_40)
8283
godot::Object *_create_data_channel(const godot::String &p_channel, const godot::Dictionary &p_channel_config) override;
84+
#else
85+
godot::Ref<godot::WebRTCDataChannel> _create_data_channel(const godot::String &p_channel, const godot::Dictionary &p_channel_config) override;
86+
#endif
8387
godot::Error _create_offer() override;
8488
godot::Error _set_remote_description(const godot::String &type, const godot::String &sdp) override;
8589
godot::Error _set_local_description(const godot::String &type, const godot::String &sdp) override;

src/init_gdextension.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ void unregister_webrtc_extension_types(ModuleInitializationLevel p_level) {
6666
}
6767

6868
extern "C" {
69+
#ifdef GDEXTENSION_WEBRTC_40
6970
GDExtensionBool GDE_EXPORT webrtc_extension_init(const GDExtensionInterface *p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
71+
#else
72+
GDExtensionBool GDE_EXPORT webrtc_extension_init(const GDExtensionInterfaceGetProcAddress p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
73+
#endif
7074
GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
7175

7276
init_obj.register_initializer(register_webrtc_extension_types);

0 commit comments

Comments
 (0)