1. 程式人生 > 其它 >IOS技術分享| WebRTC iOS原始碼下載&編譯

IOS技術分享| WebRTC iOS原始碼下載&編譯

前言

最近對 WebRTC iOS 端原始碼進行了下載和編譯,網上針對 WebRTC iOS 端的編譯文章基本都是幾年前的,有些地方已經不適用於最新版的 WebRTC 的編譯,簡單記錄下載&編譯的過程,以 M93 版本為例。

編譯環境

硬體:MacBook Pro (Retina, 15-inch, Mid 2015)

系統:macOS Big Sur 11.5

安裝 depot_tools

depot_tools 是一套 Google 用來編譯 Chromium 或者 WebRTC 的構建工具,獲取 depot_tools 原始碼前,需開啟 VPN 服務。

$ mkdir webrtc

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

如果出現如下錯誤,首先檢查 VPN 是否連線成功,其次配置 macOS 終端代理

配置終端代理

在開啟的 VPN 客戶端偏好設定中配置資訊如下:

注意:配置終端代理只對當前終端有用,重啟後需要重新配置

$ export http_proxy=http://127.0.0.1:10887
$ export https_proxy=http://127.0.0.1:10887
$ export all_proxy=http://127.0.0.1:10887

配置環境變數

$ echo "export PATH=$PWD/depot_tools:$PATH" > $HOME/.bash_profile
$ source $HOME/.bash_profile

檢查是否配置成功

$ echo $PATH

安裝 ninja

ninja 是 WebRTC 的編譯工具。

$ git clone git://github.com/martine/ninja.git
$ cd ninja/
$ ./bootstrap.py

複製到系統目錄(也可配置壞境變數)

$ sudo cp ninja /usr/local/bin/
$ sudo chmod a+rx /usr/local/bin/ninja

下載 WebRTC 原始碼

設定要編譯的平臺到環境變數

$ export GYP_DEFINES="OS=ios"

下載原始碼

$ fetch --nohooks webrtc_ios

指定分支(以 M93版本為例)

$ gclient sync -r 25e3fd53a79bfdb2bd647ee3a199eb9c3a71d271

分支版本可以在Release Notes中查詢,目前最新的是M95版本。

編譯 WebRTC 原始碼

iOS 版本我們可以使用原始碼中自帶的編譯指令碼,目錄如下,不同的 WebRTC 版本路徑可能不一樣,指令碼可根據需求自行配置。

$ cd /Users/a1/Desktop/webrtc/src 
$ /Users/a1/Desktop/webrtc/src/tools_webrtc/ios/build_ios_libs.py 

編譯完成後可在 src/out_ios_libs 目錄下找到WebRTC.framework

生成 Example 並執行

$ gn gen out/ios --args='target_os="ios" target_cpu="arm64" is_component_build=false ios_enable_code_signing=false' --ide=xcode 

下載&編譯操作原始碼

Last login: Tue Sep 14 12:49:30 on ttys001

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
yushengzhudeMacBook-Pro:~ a1$ cd /Users/a1/Desktop/webrtc
$ ls
depot_tools
$ export PATH=$PATH:"/Users/a1/Desktop/webrtc/depot_tools"
$ export http_proxy=http://127.0.0.1:10887
$ export https_proxy=http://127.0.0.1:10887
$ export all_proxy=http://127.0.0.1:10887
$ export GYP_DEFINES="OS=ios"
$ fetch --nohooks webrtc_ios
Running: gclient root
WARNING: Your metrics.cfg file was invalid or nonexistent. A new one will be created.
Running: gclient config --spec 'solutions = [
  {
    "name": "src",
    "url": "https://webrtc.googlesource.com/src.git",
    "deps_file": "DEPS",
    "managed": False,
    "custom_deps": {},
  },
]
target_os = ["ios"]
'
Running: gclient sync --nohooks --with_branch_heads

________ running 'git -c core.deltaBaseCacheLimit=2g clone --no-checkout --progress https://webrtc.googlesource.com/src.git /Users/a1/Desktop/webrtc/_gclient_src_mgr39v0v' in '/Users/a1/Desktop/webrtc'
Cloning into '/Users/a1/Desktop/webrtc/_gclient_src_mgr39v0v'...
remote: Sending approximately 332.17 MiB ...
remote: Counting objects: 75, done
remote: Finding sources: 100% (75/75)
remote: Total 388264 (delta 284781), reused 388243 (delta 284781)
Receiving objects: 100% (388264/388264), 332.12 MiB | 5.96 MiB/s, done.
Resolving deltas: 100% (284781/284781), done.

[0:01:50] Still working on:
[0:01:50]   src
1>Syncing projects:   0% ( 0/ 2)
[0:01:55] Still working on:
[0:01:55]   src
Syncing projects:  26% (11/42) src/ios
[0:04:39] Still working on:
[0:04:39]   src/third_party
[0:04:39]   src/tools

[0:08:52] Still working on:
[0:08:52]   src/third_party
[0:08:52]   src/tools
Syncing projects:  38% (16/42) src/tools/luci-go:infra/tools/luci/swarming/${pla
[0:09:52] Still working on:
[0:09:52]   src/third_party

...

[0:24:17] Still working on:
[0:24:17]   src/third_party
Syncing projects: 100% (42/42), done.
Running: git submodule foreach 'git config -f $toplevel/.git/config submodule.$name.ignore all'
Running: git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*'
Running: git config diff.ignoreSubmodules all
$ gclient sync
Syncing projects: 100% (42/42), done.
Running hooks:  41% (10/24) mac_toolchain
________ running 'vpython src/build/mac_toolchain.py' in '/Users/a1/Desktop/webrtc'
Skipping Mac toolchain installation for mac
Running hooks:  45% (11/24) clang
________ running 'vpython src/tools/clang/scripts/update.py' in '/Users/a1/Desktop/webrtc'
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac/clang-llvmorg-14-init-2175-g945cde8b-1.tgz .......... Done.
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac/clang-llvmorg-14-init-2175-g945cde8b-1.tgz .......... Done.
Hook 'vpython src/tools/clang/scripts/update.py' took 30.90 secs
Running hooks:  58% (14/24) clang_format_mac
________ running 'download_from_google_storage --no_resume --platform=darwin --no_auth --bucket chromium-clang-format -s src/buildtools/mac/clang-format.sha1' in '/Users/a1/Desktop/webrtc'
NOTICE: You have PROXY values set in your environment, but gsutilin depot_tools does not (yet) obey them.
Also, --no_auth prevents the normal BOTO_CONFIG environmentvariable from being used.
To use a proxy in this situation, please supply those settingsin a .boto file pointed to by the NO_AUTH_BOTO_CONFIG environmentvariable.
0> Downloading src/buildtools/mac/clang-format@5ba974b3b37f9f4e3b44fdde11d7ef2ab71619ab...
Downloading 1 files took 25.228423 second(s)
Hook 'download_from_google_storage --no_resume --platform=darwin --no_auth --bucket chromium-clang-format -s src/buildtools/mac/clang-format.sha1' took 25.33 secs
Running hooks:  79% (19/24) test_fonts
________ running 'download_from_google_storage --no_resume --extract --no_auth --bucket chromium-fonts -s src/third_party/test_fonts/test_fonts.tar.gz.sha1' in '/Users/a1/Desktop/webrtc'
NOTICE: You have PROXY values set in your environment, but gsutilin depot_tools does not (yet) obey them.
Also, --no_auth prevents the normal BOTO_CONFIG environmentvariable from being used.
To use a proxy in this situation, please supply those settingsin a .boto file pointed to by the NO_AUTH_BOTO_CONFIG environmentvariable.
0> Downloading src/third_party/test_fonts/test_fonts.tar.gz@cd96fc55dc243f6c6f4cb63ad117cad6cd48dceb...
0> Extracting 33 entries from src/third_party/test_fonts/test_fonts.tar.gz to src/third_party/test_fonts/test_fonts
Downloading 1 files took 25.751998 second(s)
Hook 'download_from_google_storage --no_resume --extract --no_auth --bucket chromium-fonts -s src/third_party/test_fonts/test_fonts.tar.gz.sha1' took 25.84 secs
Running hooks:  91% (22/24)
________ running 'download_from_google_storage --directory --recursive --num_threads=10 --no_auth --quiet --bucket chromium-webrtc-resources src/resources' in '/Users/a1/Desktop/webrtc'
NOTICE: You have PROXY values set in your environment, but gsutilin depot_tools does not (yet) obey them.
Also, --no_auth prevents the normal BOTO_CONFIG environmentvariable from being used.
To use a proxy in this situation, please supply those settingsin a .boto file pointed to by the NO_AUTH_BOTO_CONFIG environmentvariable.
Hook 'download_from_google_storage --directory --recursive --num_threads=10 --no_auth --quiet --bucket chromium-webrtc-resources src/resources' took 1268.21 secs
Hook 'vpython src/testing/generate_location_tags.py --out src/testing/location_tags.json' took 34.77 secs
Running hooks: 100% (24/24), done.
$ gclient sync -r 25e3fd53a79bfdb2bd647ee3a199eb9c3a71d271
Syncing projects: 100% (43/43), done.
Running hooks:  41% (10/24) mac_toolchain
________ running 'vpython src/build/mac_toolchain.py' in '/Users/a1/Desktop/webrtc'
Skipping Mac toolchain installation for mac
Running hooks:  45% (11/24) clang
________ running 'vpython src/tools/clang/scripts/update.py' in '/Users/a1/Desktop/webrtc'
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac/clang-llvmorg-13-init-14732-g8a7b5ebf-2.tgz .......... Done.
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac/clang-llvmorg-13-init-14732-g8a7b5ebf-2.tgz .......... Done.
Hook 'vpython src/tools/clang/scripts/update.py' took 31.97 secs
Running hooks:  58% (14/24) clang_format_mac
________ running 'download_from_google_storage --no_resume --platform=darwin --no_auth --bucket chromium-clang-format -s src/buildtools/mac/clang-format.sha1' in '/Users/a1/Desktop/webrtc'
NOTICE: You have PROXY values set in your environment, but gsutilin depot_tools does not (yet) obey them.
Also, --no_auth prevents the normal BOTO_CONFIG environmentvariable from being used.
To use a proxy in this situation, please supply those settingsin a .boto file pointed to by the NO_AUTH_BOTO_CONFIG environmentvariable.
Running hooks:  79% (19/24) test_fonts
________ running 'download_from_google_storage --no_resume --extract --no_auth --bucket chromium-fonts -s src/third_party/test_fonts/test_fonts.tar.gz.sha1' in '/Users/a1/Desktop/webrtc'
NOTICE: You have PROXY values set in your environment, but gsutilin depot_tools does not (yet) obey them.
Also, --no_auth prevents the normal BOTO_CONFIG environmentvariable from being used.
To use a proxy in this situation, please supply those settingsin a .boto file pointed to by the NO_AUTH_BOTO_CONFIG environmentvariable.
Running hooks:  91% (22/24)
________ running 'download_from_google_storage --directory --recursive --num_threads=10 --no_auth --quiet --bucket chromium-webrtc-resources src/resources' in '/Users/a1/Desktop/webrtc'
NOTICE: You have PROXY values set in your environment, but gsutilin depot_tools does not (yet) obey them.
Also, --no_auth prevents the normal BOTO_CONFIG environmentvariable from being used.
To use a proxy in this situation, please supply those settingsin a .boto file pointed to by the NO_AUTH_BOTO_CONFIG environmentvariable.
Hook 'vpython src/testing/generate_location_tags.py --out src/testing/location_tags.json' took 35.13 secs
Running hooks: 100% (24/24), done.