1
1
#!python
2
2
3
3
import os , sys , platform , json , subprocess
4
+ import SCons
4
5
5
6
6
7
def add_sources (sources , dirpath , extension ):
@@ -101,14 +102,6 @@ if env["godot_version"] == "3":
101
102
else :
102
103
result_path = os .path .join ("bin" , "extension" , "webrtc" )
103
104
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
-
112
105
# Our includes and sources
113
106
env .Append (CPPPATH = ["src/" ])
114
107
env .Append (CPPDEFINES = ["RTC_STATIC" ])
@@ -126,12 +119,48 @@ else:
126
119
sources .append ("src/init_gdnative.cpp" )
127
120
add_sources (sources , "src/net/" , "cpp" )
128
121
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 )
135
164
136
165
# GDNativeLibrary
137
166
if env ["godot_version" ] == "3" :
@@ -143,4 +172,5 @@ if env["godot_version"] == "3":
143
172
})
144
173
else :
145
174
extfile = env .InstallAs (os .path .join (result_path , "webrtc.gdextension" ), "misc/webrtc.gdextension" )
175
+
146
176
Default (extfile )
0 commit comments