Skip to content

Commit fee49d5

Browse files
authored
chore: Build libwebrtc for mobile platform experimentally (#190)
* chore: Add objc modules to libwebrtc for mac (#179) * add objc modules to libwebrtc for mac * [skip ci] Update plugins * [skip ci] add build script for ios/android (cherry picked from commit 603a029) * [skip ci] wip * [skip ci] chmod build scripts * [skip ci] fixed build error * [skip ci] add x64 folder into zip file * [skip ci] update cmd script to support other arch * [skip ci] wip * [skip ci] fix build script bug * [skip ci] fixed yaml to publish zip files for ios and android * fixed gn arguments * Revert "chore: Add objc modules to libwebrtc for mac (#179)" This reverts commit c2568ac.
1 parent 22160f3 commit fee49d5

8 files changed

+227
-58
lines changed

Diff for: .yamato/upm-ci-libwebrtc.yml

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ platforms:
1616
image: cds-ops/ubuntu-18.04-base:stable
1717
flavor: b1.xlarge
1818
build_command: BuildScripts~/build_libwebrtc_linux.sh
19+
- name: android
20+
type: Unity::VM
21+
image: cds-ops/ubuntu-18.04-base:stable
22+
flavor: b1.xlarge
23+
build_command: BuildScripts~/build_libwebrtc_android.sh
24+
- name: ios
25+
type: Unity::VM::osx
26+
image: slough-ops/macos-10.14-xcode:stable
27+
flavor: m1.mac
28+
build_command: BuildScripts~/build_libwebrtc_ios.sh
1929
projects:
2030
- name: libwebrtc
2131
---

Diff for: .yamato/upm-ci-publish-github-release.yml

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ platforms:
77
artifact_filename: webrtc-linux.zip
88
- name: macos
99
artifact_filename: webrtc-mac.zip
10+
- name: ios
11+
artifact_filename: webrtc-ios.zip
12+
- name: android
13+
artifact_filename: webrtc-android.zip
1014
---
1115
publish_com.unity.webrtc_github_release:
1216
name: Publish com.unity.webrtc to Github Release

Diff for: BuildScripts~/build_libwebrtc_android.sh

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
3+
if [ ! -e "$(pwd)/depot_tools" ]
4+
then
5+
git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git
6+
fi
7+
8+
export COMMAND_DIR=$(cd $(dirname $0); pwd)
9+
export PATH="$(pwd)/depot_tools:$PATH"
10+
export WEBRTC_VERSION=4183
11+
export OUTPUT_DIR="$(pwd)/out"
12+
export ARTIFACTS_DIR="$(pwd)/artifacts"
13+
14+
if [ ! -e "$(pwd)/src" ]
15+
then
16+
fetch --nohooks webrtc_android
17+
cd src
18+
git config --system core.longpaths true
19+
git checkout "refs/remotes/branch-heads/$WEBRTC_VERSION"
20+
cd ..
21+
gclient sync -f
22+
fi
23+
24+
# add jsoncpp
25+
patch -N "src/BUILD.gn" < "$COMMAND_DIR/patches/add_jsoncpp.patch"
26+
27+
mkdir -p "$ARTIFACTS_DIR/lib"
28+
29+
for target_cpu in "arm64" "x64"
30+
do
31+
mkdir "$ARTIFACTS_DIR/lib/${target_cpu}"
32+
for is_debug in "true" "false"
33+
do
34+
# generate ninja files
35+
gn gen "$OUTPUT_DIR" --root="src" \
36+
--args="is_debug=${is_debug} target_os=\"android\" target_cpu=\"${target_cpu}\" rtc_use_h264=false rtc_include_tests=false rtc_build_examples=false"
37+
38+
39+
# build static library
40+
ninja -C "$OUTPUT_DIR" webrtc
41+
42+
filename="libwebrtc.a"
43+
if [ $is_debug = "true" ]; then
44+
filename="libwebrtcd.a"
45+
fi
46+
47+
# cppy static library
48+
cp "$OUTPUT_DIR/obj/libwebrtc.a" "$ARTIFACTS_DIR/lib/${target_cpu}/${filename}"
49+
done
50+
done
51+
52+
# fix error when generate license
53+
patch -N "./src/tools_webrtc/libs/generate_licenses.py" < \
54+
"$COMMAND_DIR/patches/generate_licenses.patch"
55+
56+
python "./src/tools_webrtc/libs/generate_licenses.py" \
57+
--target //:default "$OUTPUT_DIR" "$OUTPUT_DIR"
58+
59+
cd src
60+
find . -name "*.h" -print | cpio -pd "$ARTIFACTS_DIR/include"
61+
62+
cp "$OUTPUT_DIR/LICENSE.md" "$ARTIFACTS_DIR"
63+
64+
# create zip
65+
cd "$ARTIFACTS_DIR"
66+
zip -r webrtc-android.zip lib include LICENSE.md

Diff for: BuildScripts~/build_libwebrtc_ios.sh

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
if [ ! -e "$(pwd)/depot_tools" ]
4+
then
5+
git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git
6+
fi
7+
8+
export COMMAND_DIR=$(cd $(dirname $0); pwd)
9+
export PATH="$(pwd)/depot_tools:$PATH"
10+
export WEBRTC_VERSION=4183
11+
export OUTPUT_DIR="$(pwd)/out"
12+
export ARTIFACTS_DIR="$(pwd)/artifacts"
13+
14+
if [ ! -e "$(pwd)/src" ]
15+
then
16+
fetch --nohooks webrtc_ios
17+
cd src
18+
git config --system core.longpaths true
19+
git checkout "refs/remotes/branch-heads/$WEBRTC_VERSION"
20+
cd ..
21+
gclient sync -f
22+
fi
23+
24+
# add jsoncpp
25+
patch -N "src/BUILD.gn" < "$COMMAND_DIR/patches/add_jsoncpp.patch"
26+
27+
mkdir -p "$ARTIFACTS_DIR/lib"
28+
29+
# add jsoncpp
30+
patch -N "src/BUILD.gn" < "$COMMAND_DIR/patches/add_jsoncpp.patch"
31+
32+
mkdir -p "$ARTIFACTS_DIR/lib"
33+
34+
for target_cpu in "arm64" "x64"
35+
do
36+
mkdir "$ARTIFACTS_DIR/lib/${target_cpu}"
37+
for is_debug in "true" "false"
38+
do
39+
# generate ninja files
40+
gn gen "$OUTPUT_DIR" --root="src" \
41+
--args="is_debug=${is_debug} target_os=\"ios\" target_cpu=\"${target_cpu}\" rtc_use_h264=false rtc_include_tests=false rtc_build_examples=false"
42+
43+
# build static library
44+
ninja -C "$OUTPUT_DIR" webrtc
45+
46+
filename="libwebrtc.a"
47+
if [ $is_debug = "true" ]; then
48+
filename="libwebrtcd.a"
49+
fi
50+
51+
# cppy static library
52+
cp "$OUTPUT_DIR/obj/libwebrtc.a" "$ARTIFACTS_DIR/lib/${target_cpu}/${filename}"
53+
done
54+
done
55+
56+
# fix error when generate license
57+
patch -N "./src/tools_webrtc/libs/generate_licenses.py" < \
58+
"$COMMAND_DIR/patches/generate_licenses.patch"
59+
60+
python "./src/tools_webrtc/libs/generate_licenses.py" \
61+
--target //:default "$OUTPUT_DIR" "$OUTPUT_DIR"
62+
63+
cd src
64+
find . -name "*.h" -print | cpio -pd "$ARTIFACTS_DIR/include"
65+
66+
cp "$OUTPUT_DIR/LICENSE.md" "$ARTIFACTS_DIR"
67+
68+
# create zip
69+
cd "$ARTIFACTS_DIR"
70+
zip -r webrtc-ios.zip lib include LICENSE.md

Diff for: BuildScripts~/build_libwebrtc_linux.sh

+22-20
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export ARTIFACTS_DIR="$(pwd)/artifacts"
1313

1414
if [ ! -e "$(pwd)/src" ]
1515
then
16-
fetch webrtc
16+
fetch --nohooks webrtc
1717
cd src
1818
git config --system core.longpaths true
1919
git checkout "refs/remotes/branch-heads/$WEBRTC_VERSION"
@@ -26,25 +26,27 @@ patch -N "src/BUILD.gn" < "$COMMAND_DIR/patches/add_jsoncpp.patch"
2626

2727
mkdir -p "$ARTIFACTS_DIR/lib"
2828

29-
# generate ninja files for release
30-
gn gen "$OUTPUT_DIR" --root="src" \
31-
--args="is_debug=false target_os=\"linux\" rtc_include_tests=false rtc_build_examples=false rtc_use_h264=false symbol_level=0 enable_iterator_debugging=false is_component_build=false use_rtti=true rtc_use_x11=false libcxx_abi_unstable=false"
32-
33-
# build static library for release
34-
ninja -C "$OUTPUT_DIR" webrtc
35-
36-
# cppy static library for release
37-
cp "$OUTPUT_DIR/obj/libwebrtc.a" "$ARTIFACTS_DIR/lib/libwebrtc.a"
38-
39-
# generate ninja files for debug
40-
gn gen "$OUTPUT_DIR" --root="src" \
41-
--args="is_debug=true target_os=\"linux\" rtc_include_tests=false rtc_build_examples=false rtc_use_h264=false symbol_level=0 enable_iterator_debugging=false is_component_build=false use_rtti=true rtc_use_x11=false libcxx_abi_unstable=false"
42-
43-
# build static library for debug
44-
ninja -C "$OUTPUT_DIR" webrtc
45-
46-
# cppy static library for debug
47-
cp "$OUTPUT_DIR/obj/libwebrtc.a" "$ARTIFACTS_DIR/lib/libwebrtcd.a"
29+
for target_cpu in "x64"
30+
do
31+
mkdir "$ARTIFACTS_DIR/lib/${target_cpu}"
32+
for is_debug in "true" "false"
33+
do
34+
# generate ninja files
35+
gn gen "$OUTPUT_DIR" --root="src" \
36+
--args="is_debug=${is_debug} target_os=\"linux\" target_cpu=\"${target_cpu}\" rtc_include_tests=false rtc_build_examples=false rtc_use_h264=false symbol_level=0 enable_iterator_debugging=false is_component_build=false use_rtti=true rtc_use_x11=false libcxx_abi_unstable=false"
37+
38+
# build static library
39+
ninja -C "$OUTPUT_DIR" webrtc
40+
41+
filename="libwebrtc.a"
42+
if [ $is_debug = "true" ]; then
43+
filename="libwebrtcd.a"
44+
fi
45+
46+
# cppy static library
47+
cp "$OUTPUT_DIR/obj/libwebrtc.a" "$ARTIFACTS_DIR/lib/${target_cpu}/${filename}"
48+
done
49+
done
4850

4951
# fix error when generate license
5052
patch -N "./src/tools_webrtc/libs/generate_licenses.py" < \

Diff for: BuildScripts~/build_libwebrtc_macos.sh

+22-20
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export ARTIFACTS_DIR="$(pwd)/artifacts"
1313

1414
if [ ! -e "$(pwd)/src" ]
1515
then
16-
fetch webrtc
16+
fetch --nohooks webrtc
1717
cd src
1818
git config --system core.longpaths true
1919
git checkout "refs/remotes/branch-heads/$WEBRTC_VERSION"
@@ -29,25 +29,27 @@ patch -N "src/sdk/BUILD.gn" < "$COMMAND_DIR/patches/add_objc_mac.patch"
2929

3030
mkdir -p "$ARTIFACTS_DIR/lib"
3131

32-
# generate ninja files for release
33-
gn gen "$OUTPUT_DIR" --root="src" \
34-
--args="is_debug=false target_os=\"mac\" rtc_include_tests=false rtc_build_examples=false rtc_use_h264=false symbol_level=0 enable_iterator_debugging=false is_component_build=false use_rtti=true rtc_use_x11=false libcxx_abi_unstable=false"
35-
36-
# build static library for release
37-
ninja -C "$OUTPUT_DIR" webrtc
38-
39-
# cppy static library for release
40-
cp "$OUTPUT_DIR/obj/libwebrtc.a" "$ARTIFACTS_DIR/lib/libwebrtc.a"
41-
42-
# generate ninja files for debug
43-
gn gen "$OUTPUT_DIR" --root="src" \
44-
--args="is_debug=true target_os=\"mac\" rtc_include_tests=false rtc_build_examples=false rtc_use_h264=false symbol_level=0 enable_iterator_debugging=false is_component_build=false use_rtti=true rtc_use_x11=false libcxx_abi_unstable=false"
45-
46-
# build static library for debug
47-
ninja -C "$OUTPUT_DIR" webrtc
48-
49-
# cppy static library for debug
50-
cp "$OUTPUT_DIR/obj/libwebrtc.a" "$ARTIFACTS_DIR/lib/libwebrtcd.a"
32+
for target_cpu in "x64"
33+
do
34+
mkdir "$ARTIFACTS_DIR/lib/${target_cpu}"
35+
for is_debug in "true" "false"
36+
do
37+
# generate ninja files
38+
gn gen "$OUTPUT_DIR" --root="src" \
39+
--args="is_debug=${is_debug} target_os=\"mac\" target_cpu=\"${target_cpu}\" rtc_include_tests=false rtc_build_examples=false rtc_use_h264=false symbol_level=0 enable_iterator_debugging=false is_component_build=false use_rtti=true rtc_use_x11=false libcxx_abi_unstable=false"
40+
41+
# build static library
42+
ninja -C "$OUTPUT_DIR" webrtc
43+
44+
filename="libwebrtc.a"
45+
if [ $is_debug = "true" ]; then
46+
filename="libwebrtcd.a"
47+
fi
48+
49+
# cppy static library
50+
cp "$OUTPUT_DIR/obj/libwebrtc.a" "$ARTIFACTS_DIR/lib/${target_cpu}/${filename}"
51+
done
52+
done
5153

5254
# fix error when generate license
5355
patch -N "./src/tools_webrtc/libs/generate_licenses.py" < \

Diff for: BuildScripts~/build_libwebrtc_win.cmd

+23-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set PYPI_URL=https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/si
1717
set vs2017_install=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools
1818

1919
if not exist src (
20-
call fetch.bat webrtc
20+
call fetch.bat --nohooks webrtc
2121
cd src
2222
call git.bat config --system core.longpaths true
2323
call git.bat checkout refs/remotes/branch-heads/%WEBRTC_VERSION%
@@ -32,27 +32,34 @@ rem install pywin32
3232
call "%cd%\depot_tools\bootstrap-3_8_0_chromium_8_bin\python\bin\python.exe" ^
3333
-m pip install pywin32 --index-url "%PYPI_URL%" --upgrade
3434

35-
rem generate ninja for release
36-
call gn.bat gen %OUTPUT_DIR% --root="src" ^
37-
--args="is_debug=false is_clang=false target_cpu=\"x64\" rtc_include_tests=false rtc_build_examples=false rtc_use_h264=false symbol_level=0 enable_iterator_debugging=false"
35+
mkdir "%ARTIFACTS_DIR%\lib"
3836

39-
rem build
40-
ninja.exe -C %OUTPUT_DIR%
37+
setlocal enabledelayedexpansion
4138

42-
mkdir "%ARTIFACTS_DIR%\lib"
39+
for %%i in (x64) do (
40+
mkdir "%ARTIFACTS_DIR%/lib/%%i"
41+
for %%j in (true false) do (
4342

44-
rem copy static library for release build
45-
copy "%OUTPUT_DIR%\obj\webrtc.lib" "%ARTIFACTS_DIR%\lib\webrtc.lib"
43+
rem generate ninja for release
44+
call gn.bat gen %OUTPUT_DIR% --root="src" ^
45+
--args="is_debug=%%j is_clang=false target_cpu=\"%%i\" rtc_include_tests=false rtc_build_examples=false rtc_use_h264=false symbol_level=0 enable_iterator_debugging=false"
4646

47-
rem generate ninja for debug build
48-
call gn.bat gen %OUTPUT_DIR% --root="src" ^
49-
--args="is_debug=true is_clang=false target_cpu=\"x64\" rtc_include_tests=false rtc_build_examples=false rtc_use_h264=false symbol_level=0 enable_iterator_debugging=false"
47+
rem build
48+
ninja.exe -C %OUTPUT_DIR%
5049

51-
rem build
52-
ninja.exe -C %OUTPUT_DIR%
50+
set filename=
51+
if true==%%j (
52+
set filename=webrtcd.lib
53+
) else (
54+
set filename=webrtc.lib
55+
)
56+
57+
rem copy static library for release build
58+
copy "%OUTPUT_DIR%\obj\webrtc.lib" "%ARTIFACTS_DIR%\lib\%%i\!filename!"
59+
)
60+
)
5361

54-
rem copy static library for debug build
55-
copy "%OUTPUT_DIR%\obj\webrtc.lib" "%ARTIFACTS_DIR%\lib\webrtcd.lib"
62+
endlocal
5663

5764
rem fix error when generate license
5865
patch -N "%cd%\src\tools_webrtc\libs\generate_licenses.py" < ^

Diff for: Plugin~/cmake/FindWebRTC.cmake

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,22 @@ set(WEBRTC_LIBRARY_DIR
1818
${WEBRTC_DIR}/lib
1919
)
2020

21+
if(MSVC)
22+
set(SYSTEM_PROCESSOR ${CMAKE_GENERATOR_PLATFORM})
23+
elseif(APPLE)
24+
set(SYSTEM_PROCESSOR x64)
25+
elseif(UNIX)
26+
set(SYSTEM_PROCESSOR x64)
27+
endif()
28+
2129
find_library(WEBRTC_LIBRARY_DEBUG
2230
NAMES webrtcd
23-
PATHS ${WEBRTC_LIBRARY_DIR}
31+
PATHS ${WEBRTC_LIBRARY_DIR}/${SYSTEM_PROCESSOR}
2432
)
2533

2634
find_library(WEBRTC_LIBRARY_RELEASE
2735
NAMES webrtc
28-
PATHS ${WEBRTC_LIBRARY_DIR}
36+
PATHS ${WEBRTC_LIBRARY_DIR}/${SYSTEM_PROCESSOR}
2937
)
3038

3139
set(WEBRTC_LIBRARY

0 commit comments

Comments
 (0)