-
Notifications
You must be signed in to change notification settings - Fork 19
/
build.sh
executable file
·417 lines (377 loc) · 11.6 KB
/
build.sh
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#!/bin/bash
# Stop script on errors.
set -e
# Check build time dependencies.
if ! command -v python &> /dev/null
then
echo 'python could not be found'
echo 'try next steps:'
echo ' * run "brew install pyenv"'
echo ' * run "pyenv install --list" and choose a recent 3.x version say 3.11.2'
echo ' * run "pyenv install 3.11.2"'
echo ' * run "pyenv global 3.11.2"'
echo $' * run "echo \'eval "$(pyenv init --path)"\' >> ~/.zshrc"'
exit
fi
if ! command -v cmake &> /dev/null
then
echo 'cmake could not be found'
echo 'try next steps:'
echo ' * run "brew install cmake"'
exit
fi
# Define working directories.
export PROJECT_DIR=$(pwd)
echo "PROJECT_DIR = $PROJECT_DIR"
export WORK_DIR=$PROJECT_DIR/Mediasoup/dependencies
echo "WORK_DIR = $WORK_DIR"
export BUILD_DIR=$(pwd)/build
echo "BUILD_DIR = $BUILD_DIR"
export OUTPUT_DIR=$(pwd)/bin
echo "OUTPUT_DIR = $OUTPUT_DIR"
export PATCHES_DIR=$(pwd)/patches
echo "PATCHES_DIR = $PATCHES_DIR"
export WEBRTC_DIR=$PROJECT_DIR/Mediasoup/dependencies/webrtc/src
echo "WEBRTC_DIR = $WEBRTC_DIR"
function clearArtifacts() {
declare -a COMPONENTS=(
"$OUTPUT_DIR"
"$BUILD_DIR"
)
for COMPONENT in "${COMPONENTS[@]}"
do
if [ -d $COMPONENT ]
then
echo "Removing dir $COMPONENT"
rm -rf $COMPONENT
fi
done
mkdir -p $OUTPUT_DIR
echo 'OUTPUT_DIR created'
mkdir -p $BUILD_DIR
echo 'BUILD_DIR created'
}
while true
do
read -n 1 -p "Clear old build artifacts? (Y|n): " INPUT_STRING
# echo ""
case $INPUT_STRING in
n|N)
echo ""
break
;;
y|Y|"")
echo ""
clearArtifacts
break
;;
*)
echo -ne "\r\033[0K\r"
tput bel
;;
esac
done
function refetchLibmediasoupclient() {
echo 'Cloning libmediasoupclient'
cd $WORK_DIR
rm -rf libmediasoupclient
git clone -b vl-m120 --depth 1 https://github.com/VLprojects/libmediasoupclient.git
}
if [ -d $WORK_DIR/libmediasoupclient ]
then
echo "libmediasoupclient is already on disk"
while true
do
read -n 1 -p "Refetch libmediasoupclient (y|N): " INPUT_STRING
case $INPUT_STRING in
n|N|"")
echo ""
break
;;
y|Y)
echo ""
refetchLibmediasoupclient
break
;;
*)
echo -ne "\r\033[0K\r"
tput bel
;;
esac
done
else
refetchLibmediasoupclient
fi
# Depot tools are used to download, configure and build WebRTC and its dependencides.
function refetchDepotTools() {
echo 'Cloning depot_tools'
cd $WORK_DIR
rm -rf depot_tools
git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git
}
if [ -d $WORK_DIR/depot_tools ]
then
echo "depot_tools is already on disk"
while true
do
read -n 1 -p "Refetch depot_tools (y|N): " INPUT_STRING
echo ""
case $INPUT_STRING in
n|N|"")
break
;;
y|Y)
refetchDepotTools
break
;;
*)
tput bel
;;
esac
done
else
refetchDepotTools
fi
export PATH=$WORK_DIR/depot_tools:$PATH
# There are BUILD.gn files in each WebRTC directory. These files declare which modules are included
# for each target and may contain other target build options and rules.
# Each public symbol is also marked in source files as such. We need to redefine some symbols visibility
# to make WebRTC builable, usable and properly configurable for iOS platform.
function patchWebRTC() {
echo 'Patching WebRTC for iOS platform support'
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/builtin_audio_decoder_factory.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/builtin_audio_encoder_factory.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/sdp_video_format_utils.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/sdk_BUILD.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/abseil_optional.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/RTCPeerConnectionFactoryBuilder.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/audio_device_module_h.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/audio_device_module_mm.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/objc_video_decoder_factory_h.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/objc_video_encoder_factory_h.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/objc_video_encoder_factory_mm.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/video_decoder_factory_h.patch
patch -b -p0 -d $WORK_DIR < $PATCHES_DIR/video_encoder_factory_h.patch
}
# WebRTC sources are downloaded by git client from Depot tools.
# You should configure target OS and WebRTC version before cloning.
# WebRTC versions and their corresponding branch names can be found here: https://chromiumdash.appspot.com/branches.
function refetchWebRTC() {
echo 'Cloning WebRTC'
rm -rf $WORK_DIR/webrtc
mkdir -p $WORK_DIR/webrtc
cd $WORK_DIR/webrtc
export DEPOT_TOOLS_UPDATE=1
gclient root
gclient config --spec \
'solutions = [{
"name": "src",
"url": "https://webrtc.googlesource.com/src.git",
"deps_file": "DEPS",
"managed": False,
"custom_deps": {},
}]
target_os = ["ios"]'
# Fetch WebRTC m120 version.
gclient sync --no-history --revision src@branch-heads/6099
# Fetch all possible WebRTC versions so you can switch between them.
# Takes longer time and more disk space.
# gclient sync --nohooks --with_branch_heads --with_tags
# Checkout a new version for the first time
# cd $WORK_DIR/webrtc/src
# git reset --hard
# cd $WORK_DIR/webrtc/src/third_party
# git reset --hard
# cd $WORK_DIR/webrtc/src
# git checkout -b m112 refs/remotes/branch-heads/5615
# git checkout -b m120 refs/remotes/branch-heads/6099
# Switch to WebRTC version that already was checked out previously.
# git checkout m112
# git checkout m120
# Run hooks after switching between WebRTC versions.
# cd $WORK_DIR/webrtc/src
# gclient sync --no-history -D
}
function resetWebRTC() {
cd $WORK_DIR/webrtc/src
git reset --hard
cd $WORK_DIR/webrtc/src/third_party
git reset --hard
}
if [ -d $WORK_DIR/webrtc ]
then
echo "WebRTC is already on disk"
while true
do
read -n 1 -p "Refetch WebRTC? (f)ull clone | (r)eset local changes | (N)o: " INPUT_STRING
echo ""
case $INPUT_STRING in
n|N|"")
break
;;
f|F)
refetchWebRTC
patchWebRTC
break
;;
r|R)
resetWebRTC
patchWebRTC
break
;;
*)
tput bel
;;
esac
done
else
refetchWebRTC
patchWebRTC
fi
# This patch should be applied only after WebRTC is already built.
cd $WEBRTC_DIR
git restore rtc_base/byte_order.h
echo 'Building WebRTC'
cd $WEBRTC_DIR
# In root dir of WebRTC sources there is webrtc.gni file.
# It contains all available configuration flags with comprehensive comments for each.
gn_arguments=(
'target_os="ios"'
'ios_deployment_target="14.0"'
'ios_enable_code_signing=false'
'is_component_build=false'
#'is_debug=true'
'is_debug=false'
'rtc_libvpx_build_vp9=true'
'use_goma=false'
'rtc_enable_symbol_export=true'
'rtc_enable_objc_symbol_export=true'
'rtc_enable_protobuf=false'
'rtc_include_tests=false'
'rtc_include_builtin_audio_codecs=true'
'rtc_include_pulse_audio=false'
'use_rtti=true'
'use_custom_libcxx=false'
'enable_dsyms=true'
'enable_stripping=true'
'treat_warnings_as_errors=false'
)
for str in ${gn_arguments[@]}; do
gn_args+=" ${str}"
done
platform_args='target_environment="device" target_cpu="arm64"'
gn gen $BUILD_DIR/WebRTC/device/arm64 --ide=xcode --args="${platform_args}${gn_args}"
platform_args='target_environment="simulator" target_cpu="x64"'
gn gen $BUILD_DIR/WebRTC/simulator/x64 --ide=xcode --args="${platform_args}${gn_args}"
platform_args='target_environment="simulator" target_cpu="arm64"'
gn gen $BUILD_DIR/WebRTC/simulator/arm64 --ide=xcode --args="${platform_args}${gn_args}"
# This command can be used to check which symbols will be included
# in each target without waiting to perform actual build:
# ninja -t browse webrtc
cd $BUILD_DIR/WebRTC
ninja -C device/arm64 sdk
ninja -C simulator/x64 sdk
ninja -C simulator/arm64 sdk
cd $BUILD_DIR/WebRTC
rm -rf simulator/WebRTC.framework
cp -R simulator/arm64/WebRTC.framework simulator/WebRTC.framework
rm simulator/WebRTC.framework/WebRTC
lipo -create \
simulator/arm64/WebRTC.framework/WebRTC \
simulator/x64/WebRTC.framework/WebRTC \
-output simulator/WebRTC.framework/WebRTC
cd $BUILD_DIR/WebRTC
rm -rf $OUTPUT_DIR/WebRTC.xcframework
xcodebuild -create-xcframework \
-framework device/arm64/WebRTC.framework \
-framework simulator/WebRTC.framework \
-output $OUTPUT_DIR/WebRTC.xcframework
cd $WORK_DIR
function rebuildLMSC() {
echo "Building libmediasoupclient"
rm -rf $BUILD_DIR/libmediasoupclient
rm -rf $OUTPUT_DIR/sdptransform.xcframework
rm -rf $OUTPUT_DIR/mediasoupclient.xcframework
lmsc_cmake_arguments=(
"-DLIBWEBRTC_INCLUDE_PATH=$WEBRTC_DIR"
'-DMEDIASOUPCLIENT_LOG_TRACE=OFF'
'-DMEDIASOUPCLIENT_LOG_DEV=OFF'
'-DCMAKE_CXX_FLAGS="-fvisibility=hidden"'
'-DLIBSDPTRANSFORM_BUILD_TESTS=OFF'
'-DMEDIASOUPCLIENT_BUILD_TESTS=OFF'
'-DCMAKE_OSX_DEPLOYMENT_TARGET=14'
# '-DCMAKE_BUILD_TYPE=Debug'
)
for str in ${lmsc_cmake_arguments[@]}; do
lmsc_cmake_args+=" ${str}"
done
# Build mediasoup-client-ios
cmake . -B $BUILD_DIR/libmediasoupclient/device/arm64 \
${lmsc_cmake_args} \
-DLIBWEBRTC_BINARY_PATH=$BUILD_DIR/WebRTC/device/arm64/WebRTC.framework/WebRTC \
-DIOS_SDK=iphone \
-DIOS_ARCHS="arm64" \
-DPLATFORM=OS64 \
-DCMAKE_OSX_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
make -C $BUILD_DIR/libmediasoupclient/device/arm64
cmake . -B $BUILD_DIR/libmediasoupclient/simulator/x64 \
${lmsc_cmake_args} \
-DLIBWEBRTC_BINARY_PATH=$BUILD_DIR/WebRTC/simulator/x64/WebRTC.framework/WebRTC \
-DIOS_SDK=iphonesimulator \
-DIOS_ARCHS="x86_64" \
-DPLATFORM=SIMULATOR64 \
-DCMAKE_OSX_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
make -C $BUILD_DIR/libmediasoupclient/simulator/x64
cmake . -B $BUILD_DIR/libmediasoupclient/simulator/arm64 \
${lmsc_cmake_args} \
-DLIBWEBRTC_BINARY_PATH=$BUILD_DIR/WebRTC/simulator/arm64/WebRTC.framework/WebRTC \
-DIOS_SDK=iphonesimulator \
-DIOS_ARCHS="arm64"\
-DPLATFORM=SIMULATORARM64 \
-DCMAKE_OSX_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
make -C $BUILD_DIR/libmediasoupclient/simulator/arm64
# Create a FAT libmediasoup / libsdptransform library
mkdir -p $BUILD_DIR/libmediasoupclient/simulator/fat
lipo -create \
$BUILD_DIR/libmediasoupclient/simulator/x64/libmediasoupclient/libmediasoupclient.a \
$BUILD_DIR/libmediasoupclient/simulator/arm64/libmediasoupclient/libmediasoupclient.a \
-output $BUILD_DIR/libmediasoupclient/simulator/fat/libmediasoupclient.a
lipo -create \
$BUILD_DIR/libmediasoupclient/simulator/x64/_deps/libsdptransform-build/libsdptransform.a \
$BUILD_DIR/libmediasoupclient/simulator/arm64/_deps/libsdptransform-build/libsdptransform.a \
-output $BUILD_DIR/libmediasoupclient/simulator/fat/libsdptransform.a
xcodebuild -create-xcframework \
-library $BUILD_DIR/libmediasoupclient/device/arm64/libmediasoupclient/libmediasoupclient.a \
-library $BUILD_DIR/libmediasoupclient/simulator/fat/libmediasoupclient.a \
-output $OUTPUT_DIR/mediasoupclient.xcframework
xcodebuild -create-xcframework \
-library $BUILD_DIR/libmediasoupclient/device/arm64/_deps/libsdptransform-build/libsdptransform.a \
-library $BUILD_DIR/libmediasoupclient/simulator/fat/libsdptransform.a \
-output $OUTPUT_DIR/sdptransform.xcframework
}
if [ -d $BUILD_DIR/libmediasoupclient ]
then
echo "libmediasoupclient is already built"
while true
do
read -n 1 -p "Rebuild libmediasoupclient (y|N): " INPUT_STRING
case $INPUT_STRING in
n|N|"")
echo ""
break
;;
y|Y)
echo ""
rebuildLMSC
break
;;
*)
echo -ne "\r\033[0K\r"
tput bel
;;
esac
done
else
rebuildLMSC
fi
open $PROJECT_DIR/Mediasoup.xcodeproj