はやし雑記

はやしです

iOSのWebRTCを手元でビルドした

iOSでWebRTCをした話です Cocoapodsはいやだったので、手元マシンでビルドしました

webrtc.org

Install Chromium depot_tools

depot_tools_tutorial(7)

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=$PATH:/path/to/depot_tools

ちなみにこのdepot_toolsはPython 2で動いているので、pyenvとかでPython 3系をデフォルトにしている場合は$ pyenv local systemとして2系で動くようにする必要がある

Getting the Code

ソースを取ってくる

$ mkdir webrtc
$ cd webrtc
$ fetch --nohooks webrtc_ios
$ gclient sync

ネットワーク環境に依るだろうけど、10GBくらいダウンロードするので結構時間かかった(1時間くらい)

WebRTC.frameworkをビルドする

frameworkをビルドする方法としては、

  • gnコマンドでビルドファイルを作り、ninjaでビルドする
  • ビルドスクリプトbuild_ios_libs.shを使う

の2通りがあり、楽なので後者でいきます

ビルドスクリプトの実体は、tools_webrtc/ios/build_ios_libs.pyです

$ tools_webrtc/ios/build_ios_libs.py -h
usage: build_ios_libs.py [-h] [--build_config {debug,release}]
                         [--arch {arm64,arm,x64,x86} [{arm64,arm,x64,x86} ...]]
                         [-c] [-p] [-o OUTPUT_DIR] [-r REVISION] [-e]
                         [--verbose] [--use-goma]
                         [--extra-gn-args [EXTRA_GN_ARGS [EXTRA_GN_ARGS ...]]]

WebRTC iOS FAT libraries build script. Each architecture is compiled
separately before being merged together. By default, the library is created in
out_ios_libs/. (Change with -o.)

optional arguments:
  -h, --help            show this help message and exit
  --build_config {debug,release}
                        The build config. Can be "debug" or "release".
                        Defaults to "release".
  --arch {arm64,arm,x64,x86} [{arm64,arm,x64,x86} ...]
                        Architectures to build. Defaults to ['arm64', 'arm',
                        'x64', 'x86'].
  -c, --clean           Removes the previously generated build output, if any.
  -p, --purify          Purifies the previously generated build output by
                        removing the temporary results used when (re)building.
  -o OUTPUT_DIR, --output-dir OUTPUT_DIR
                        Specifies a directory to output the build artifacts
                        to. If specified together with -c, deletes the dir.
  -r REVISION, --revision REVISION
                        Specifies a revision number to embed if building the
                        framework.
  -e, --bitcode         Compile with bitcode.
  --verbose             Debug logging.
  --use-goma            Use goma to build.
  --extra-gn-args [EXTRA_GN_ARGS [EXTRA_GN_ARGS ...]]
                        Additional GN args to be used during Ninja generation.

だいたいデフォルトのままで良いと思いますが、正直32bit対応は不要な気がするので

$ python tools_webrtc/ios/build_ios_libs.py --arch arm64 x64

とかで良いでしょう

bitcode対応させるなら、--bitcodeを付けましょう。

ビルドが完了するとout_ios_libsWebRTC.frameworkができます

Bitcodeを無効にして、arm64, x64でビルドするとだいたい11MB程度です

Bitcodeを有効にすると、なんと412MBにもなる・・・

これを使ってWebRTCを試してみるのは次回・・・