1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
import os
from SCons.Script import Environment
def get_android_api(env):
return env["android_api_level"] if int(env["android_api_level"]) > 28 else "28"
def get_deps_dir(env):
return env.Dir("#deps").abspath
def get_deps_build_dir(env):
return get_deps_dir(env) + "/build/{}.{}.{}.dir".format(env["platform"], env["target"], env["arch_suffix"])
def get_rtc_source_dir(env):
return get_deps_dir(env) + "/libdatachannel"
def get_rtc_build_dir(env):
return get_deps_build_dir(env) + "/libdatachannel"
def get_rtc_include_dir(env):
return get_rtc_source_dir(env) + "/include"
def get_ssl_source_dir(env):
return get_deps_dir(env) + "/openssl"
def get_ssl_build_dir(env):
return get_deps_build_dir(env) + "/openssl"
def get_ssl_install_dir(env):
return get_ssl_build_dir(env) + "/dest"
def get_ssl_include_dir(env):
return get_ssl_install_dir(env) + "/include"
def ssl_emitter(target, source, env):
build_dir = get_ssl_build_dir(env)
libs = ["libssl.a", "libcrypto.a"]
install_dir = get_ssl_install_dir(env)
ssl_include = os.path.join(source[0].abspath, "include")
return [env.File(build_dir + "/" + l) for l in libs], source
def ssl_action(target, source, env):
build_dir = get_ssl_build_dir(env)
source_dir = source[0].abspath
ssl_env = Environment()
install_dir = get_ssl_install_dir(env)
args = [
"no-ssl3",
"no-weak-ssl-ciphers",
"no-legacy",
"--prefix=%s" % install_dir,
"--openssldir=%s" % install_dir,
]
if env["target"] == "debug":
args.append("-d")
if env["platform"] != "windows":
args.append("no-shared") # Windows "app" doesn't like static-only builds.
if env["platform"] == "linux":
if env["arch"] == "x86_32":
args.extend(["linux-x86"])
else:
args.extend(["linux-x86_64"])
elif env["platform"] == "android":
args.extend([
{
"arm64": "android-arm64",
"arm32": "android-arm",
"x86_32": "android-x86",
"x86_64": "android-x86_64",
}[env["arch"]],
"-D__ANDROID_API__=%s" % get_android_api(env),
])
# Setup toolchain path.
ssl_env.PrependENVPath("PATH", os.path.dirname(env["CC"]))
ssl_env["ENV"]["ANDROID_NDK_ROOT"] = os.environ.get("ANDROID_NDK_ROOT", "")
elif env["platform"] == "macos":
if env["arch"] == "x86_64":
args.extend(["darwin64-x86_64"])
elif env["arch"] == "arm64":
args.extend(["darwin64-arm64"])
else:
raise ValueError("macOS architecture not supported: %s" % env["arch"])
elif env["platform"] == "ios":
if env["ios_simulator"]:
args.extend(["iossimulator-xcrun"])
elif env["arch"] == "arm32":
args.extend(["ios-xcrun"])
elif env["arch"] == "arm64":
args.extend(["ios64-xcrun"])
else:
raise ValueError("iOS architecture not supported: %s" % env["arch"])
elif env["platform"] == "windows":
if env["arch"] == "x86_32":
if env["use_mingw"]:
args.extend([
"mingw",
"--cross-compile-prefix=i686-w64-mingw32-",
])
else:
args.extend(["VC-WIN32"])
else:
if env["use_mingw"]:
args.extend([
"mingw64",
"--cross-compile-prefix=x86_64-w64-mingw32-",
])
else:
args.extend(["VC-WIN64A"])
jobs = env.GetOption("num_jobs")
ssl_env.Execute([
"mkdir -p " + build_dir, # TODO python?
("cd %s && %s/Configure " % (build_dir, source_dir)) + " ".join(args),
"make -C %s -j%s" % (build_dir, jobs),
"make -C %s install_sw install_ssldirs -j%s" % (build_dir, jobs),
]
)
return None
def rtc_emitter(target, source, env):
build_dir = get_rtc_build_dir(env)
libs = ["libdatachannel-static.a", "libjuice-static.a", "libsrtp2.a", "libusrsctp.a"]
lib_paths = [
build_dir,
os.path.join(build_dir, "deps/libjuice"),
os.path.join(build_dir, "deps/libsrtp"),
os.path.join(build_dir, "deps/usrsctp/usrsctplib"),
]
return [env.File(lib_paths[i] + "/" + libs[i]) for i in range(len(libs))], source
def rtc_action(target, source, env):
build_dir = get_rtc_build_dir(env)
source_dir = source[0].abspath
args = [
"-B",
build_dir,
"-DUSE_NICE=0",
"-DNO_WEBSOCKET=1",
#"-DNO_MEDIA=1", # Windows builds fail without it.
"-DNO_EXAMPLES=1",
"-DNO_WEBSOCKET=1",
"-DNO_TESTS=1",
"-DOPENSSL_USE_STATIC_LIBS=1",
"-DOPENSSL_INCLUDE_DIR=%s" % get_ssl_include_dir(env),
"-DOPENSSL_SSL_LIBRARY=%s/libssl.a" % get_ssl_build_dir(env),
"-DOPENSSL_CRYPTO_LIBRARY=%s/libcrypto.a" % get_ssl_build_dir(env),
"-DCMAKE_BUILD_TYPE=%s" % ("Release" if env["target"] == "release" else "Debug"),
]
if env["platform"] == "android":
abi = {
"arm64": "arm64-v8a",
"arm32": "armeabi-v7a",
"x86_32": "x86",
"x86_64": "x86_64",
}[env["arch"]]
args.extend([
"-DCMAKE_SYSTEM_NAME=Android",
"-DCMAKE_SYSTEM_VERSION=%s" % get_android_api(env),
"-DCMAKE_ANDROID_ARCH_ABI=%s" % abi,
"-DANDROID_ABI=%s" % abi,
"-DCMAKE_TOOLCHAIN_FILE=%s/build/cmake/android.toolchain.cmake" % os.environ.get("ANDROID_NDK_ROOT", ""),
"-DCMAKE_ANDROID_STL_TYPE=c++_static",
])
elif env["platform"] == "linux":
if env["arch"] == "x86_32":
args.extend([
"-DCMAKE_C_FLAGS=-m32",
"-DCMAKE_CXX_FLAGS=-m32"
])
else:
args.extend([
"-DCMAKE_C_FLAGS=-m64",
"-DCMAKE_CXX_FLAGS=-m64"
])
elif env["platform"] == "macos":
if env["macos_deployment_target"] != "default":
args.extend(["-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % env["macos_deployment_target"]])
if env["arch"] == "x86_64":
args.extend(["-DCMAKE_OSX_ARCHITECTURES=x86_64"])
elif env["arch"] == "arm64":
args.extend(["-DCMAKE_OSX_ARCHITECTURES=arm64"])
else:
raise ValueError("OSX architecture not supported: %s" % env["arch"])
elif env["platform"] == "ios":
if env["arch"] == "universal":
raise ValueError("iOS architecture not supported: %s" % env["arch"])
args.extend([
"-DCMAKE_SYSTEM_NAME=iOS",
"-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0",
"-DCMAKE_OSX_ARCHITECTURES=%s" % env["arch"],
])
if env["ios_simulator"]:
args.extend(["-DCMAKE_OSX_SYSROOT=iphonesimulator"])
elif env["platform"] == "windows":
args.extend(["-DOPENSSL_ROOT_DIR=%s" % get_ssl_build_dir(env)])
if env["arch"] == "x86_32":
if env["use_mingw"]:
args.extend([
"-G 'Unix Makefiles'",
"-DCMAKE_C_COMPILER=i686-w64-mingw32-gcc",
"-DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++",
"-DCMAKE_SYSTEM_NAME=Windows",
])
else:
if env["use_mingw"]:
args.extend([
"-G 'Unix Makefiles'",
"-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc",
"-DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++",
"-DCMAKE_SYSTEM_NAME=Windows"
])
args.append(source_dir)
jobs = env.GetOption("num_jobs")
rtc_env = Environment()
rtc_env.Execute([
"cmake " + " ".join(args),
"cmake --build %s -t datachannel-static -j%s" % (build_dir, jobs),
]
)
return None
|