Skip to content

Commit 6de604f

Browse files
authored
Merge pull request #94 from Faless/fix/macos_releases
[macOS] Add support for universal builds.
2 parents fbe4e06 + f0af5f9 commit 6de604f

File tree

4 files changed

+50
-37
lines changed

4 files changed

+50
-37
lines changed

.github/workflows/build_release.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,11 @@ jobs:
8484

8585
# macOS
8686
- platform: macos
87-
arch: 'x86_64'
88-
gdnative_flags: 'macos_arch=x86_64 bits=64'
89-
sconsflags: ''
90-
os: 'macos-11'
91-
cache-name: macos-x86_64
92-
- platform: macos
93-
gdnative_flags: 'macos_arch=arm64 bits=64'
94-
arch: 'arm64'
87+
arch: 'universal'
88+
gdnative_flags: 'macos_arch=universal bits=64'
9589
sconsflags: ''
9690
os: 'macos-11'
97-
cache-name: macos-arm64
91+
cache-name: macos-universal
9892

9993
# Windows
10094
- platform: windows

SConstruct

+44-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!python
22

33
import os, sys, platform, json, subprocess
4+
import SCons
45

56

67
def add_sources(sources, dirpath, extension):
@@ -101,14 +102,6 @@ if env["godot_version"] == "3":
101102
else:
102103
result_path = os.path.join("bin", "extension", "webrtc")
103104

104-
# Dependencies
105-
for tool in ["cmake", "common", "ssl", "rtc"]:
106-
env.Tool(tool, toolpath=["tools"])
107-
108-
ssl = env.BuildOpenSSL()
109-
env.NoCache(ssl) # Needs refactoring to properly cache generated headers.
110-
rtc = env.BuildLibDataChannel()
111-
112105
# Our includes and sources
113106
env.Append(CPPPATH=["src/"])
114107
env.Append(CPPDEFINES=["RTC_STATIC"])
@@ -126,12 +119,48 @@ else:
126119
sources.append("src/init_gdnative.cpp")
127120
add_sources(sources, "src/net/", "cpp")
128121

129-
env.Depends(sources, [ssl, rtc])
130-
131-
# Make the shared library
132-
result_name = "webrtc_native{}{}".format(env["suffix"], env["SHLIBSUFFIX"])
133-
library = env.SharedLibrary(target=os.path.join(result_path, "lib", result_name), source=sources)
134-
Default(library)
122+
# Since the OpenSSL build system does not support macOS universal binaries, we first need to build the two libraries
123+
# separately, then we join them together using lipo.
124+
mac_universal = env["platform"] == "macos" and env["arch"] == "universal"
125+
build_targets = []
126+
build_envs = [env]
127+
128+
# For macOS universal builds, setup one build environment per architecture.
129+
if mac_universal:
130+
build_envs = []
131+
for arch in ["x86_64", "arm64"]:
132+
benv = env.Clone()
133+
benv["arch"] = arch
134+
benv["CCFLAGS"] = SCons.Util.CLVar(str(benv["CCFLAGS"]).replace("-arch x86_64 -arch arm64", "-arch " + arch))
135+
benv["LINKFLAGS"] = SCons.Util.CLVar(str(benv["LINKFLAGS"]).replace("-arch x86_64 -arch arm64", "-arch " + arch))
136+
benv["suffix"] = benv["suffix"].replace("universal", arch)
137+
benv["SHOBJSUFFIX"] = benv["suffix"] + benv["SHOBJSUFFIX"]
138+
build_envs.append(benv)
139+
140+
# Build our library and its dependencies.
141+
for benv in build_envs:
142+
# Dependencies
143+
for tool in ["cmake", "common", "ssl", "rtc"]:
144+
benv.Tool(tool, toolpath=["tools"])
145+
146+
ssl = benv.BuildOpenSSL()
147+
benv.NoCache(ssl) # Needs refactoring to properly cache generated headers.
148+
rtc = benv.BuildLibDataChannel()
149+
150+
benv.Depends(sources, [ssl, rtc])
151+
152+
# Make the shared library
153+
result_name = "webrtc_native{}{}".format(benv["suffix"], benv["SHLIBSUFFIX"])
154+
library = benv.SharedLibrary(target=os.path.join(result_path, "lib", result_name), source=sources)
155+
build_targets.append(library)
156+
157+
Default(build_targets)
158+
159+
# For macOS universal builds, join the libraries using lipo.
160+
if mac_universal:
161+
result_name = "libwebrtc_native{}{}".format(env["suffix"], env["SHLIBSUFFIX"])
162+
universal_target = env.Command(os.path.join(result_path, "lib", result_name), build_targets, "lipo $SOURCES -output $TARGETS -create")
163+
Default(universal_target)
135164

136165
# GDNativeLibrary
137166
if env["godot_version"] == "3":
@@ -143,4 +172,5 @@ if env["godot_version"] == "3":
143172
})
144173
else:
145174
extfile = env.InstallAs(os.path.join(result_path, "webrtc.gdextension"), "misc/webrtc.gdextension")
175+
146176
Default(extfile)

misc/webrtc.gdextension

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ entry_symbol = "webrtc_extension_init"
66

77
linux.debug.x86_64 = "res://webrtc/lib/libwebrtc_native.linux.template_debug.x86_64.so"
88
linux.debug.x86_32 = "res://webrtc/lib/libwebrtc_native.linux.template_debug.x86_32.so"
9-
macos.debug.x86_64 = "res://webrtc/lib/libwebrtc_native.macos.template_debug.x86_64.dylib"
10-
macos.debug.arm64 = "res://webrtc/lib/libwebrtc_native.macos.template_debug.arm64.dylib"
9+
macos.debug = "res://webrtc/lib/libwebrtc_native.macos.template_debug.universal.dylib"
1110
windows.debug.x86_64 = "res://webrtc/lib/libwebrtc_native.windows.template_debug.x86_64.dll"
1211
windows.debug.x86_32 = "res://webrtc/lib/libwebrtc_native.windows.template_debug.x86_32.dll"
1312
android.debug.arm64 = "res://webrtc/lib/libwebrtc_native.android.template_debug.arm64.so"
@@ -17,8 +16,7 @@ ios.debug.x86_64 = "res://webrtc/lib/libwebrtc_native.ios.template_debug.x86_64.
1716

1817
linux.release.x86_64 = "res://webrtc/lib/libwebrtc_native.linux.template_release.x86_64.so"
1918
linux.release.x86_32 = "res://webrtc/lib/libwebrtc_native.linux.template_release.x86_32.so"
20-
macos.release.x86_64 = "res://webrtc/lib/libwebrtc_native.macos.template_release.x86_64.dylib"
21-
macos.release.arm64 = "res://webrtc/lib/libwebrtc_native.macos.template_release.arm64.dylib"
19+
macos.release = "res://webrtc/lib/libwebrtc_native.macos.template_release.universal.dylib"
2220
windows.release.x86_64 = "res://webrtc/lib/libwebrtc_native.windows.template_release.x86_64.dll"
2321
windows.release.x86_32 = "res://webrtc/lib/libwebrtc_native.windows.template_release.x86_32.dll"
2422
android.release.arm64 = "res://webrtc/lib/libwebrtc_native.android.template_release.arm64.so"

misc/webrtc.tres

+1-10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
[resource]
44
singleton = true
55
reloadable = false
6-
entry/OSX.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.osx.{TARGET}.x86_64.dylib"
7-
entry/OSX.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.osx.{TARGET}.arm64.dylib"
6+
entry/OSX.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.macos.{TARGET}.universal.dylib"
87
entry/Windows.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.windows.{TARGET}.x86_64.dll"
98
entry/Windows.32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.windows.{TARGET}.x86_32.dll"
109
entry/X11.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_64.so"
@@ -16,11 +15,3 @@ entry/Android.x64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}
1615
entry/iOS.armv7 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.armv32.dylib"
1716
entry/iOS.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.arm64.dylib"
1817
entry/iOS.x86_64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.x86_64.simulator.dylib"
19-
dependency/Windows.64 = [ ]
20-
dependency/Windows.32 = [ ]
21-
dependency/X11.64 = [ ]
22-
dependency/X11.32 = [ ]
23-
dependency/Server.64 = [ ]
24-
dependency/Server.32 = [ ]
25-
dependency/Android.armeabi-v7a = [ ]
26-
dependency/Android.arm64-v8a = [ ]

0 commit comments

Comments
 (0)