You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
7.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. # WebRTC iOS development
  2. ## Using Cocoapods
  3. The WebRTC framework is published on [cocoapods.org][cocoapods].
  4. The framework is built from tip-of-tree.
  5. _NOTICE_: The pod version of the framework doesn't support bitcode currently.
  6. If you need bitcode support, you'll need to manually build the framework.
  7. The process is described in detail in the following sections.
  8. To integrate it into your project add the following lines to your Podfile
  9. ```
  10. source 'https://github.com/CocoaPods/Specs.git'
  11. target 'YOUR_APPLICATION_TARGET_NAME_HERE' do
  12. platform :ios, '9.0'
  13. pod 'GoogleWebRTC'
  14. end
  15. ```
  16. The versioning system used is *1.1.cr-commit-position*, where *cr-commit-position* can
  17. be used to identify the exact WebRTC revision the pod was built from. You can check the
  18. revision at crrev.com/CR_COMMIT_POSITION_HERE.
  19. ## Development Environment
  20. In case you need to build the framework manually
  21. (for instance if you need to support bitcode) or you want to try out the demo application
  22. AppRTCMobile, follow the instructions illustrated bellow.
  23. A macOS machine is required for iOS development. While it's possible to
  24. develop purely from the command line with text editors, it's easiest to use
  25. Xcode. Both methods will be illustrated here.
  26. _NOTICE:_ You will need to install [Chromium depot_tools][webrtc-prerequisite-sw].
  27. ## Getting the Code
  28. Create a working directory, enter it, and run:
  29. ```
  30. $ fetch --nohooks webrtc_ios
  31. $ gclient sync
  32. ```
  33. This will fetch a regular WebRTC checkout with the iOS-specific parts
  34. added. Notice the size is quite large: about 6GB. The same checkout can be used
  35. for both Mac and iOS development, since GN allows you to generate your
  36. [Ninja][ninja] project files in different directories for each build config.
  37. You may want to disable Spotlight indexing for the checkout to speed up
  38. file operations.
  39. Note that the git repository root is in `src`.
  40. From here you can check out a new local branch with:
  41. ```
  42. $ git new-branch <branch name>
  43. ```
  44. See [Development][webrtc-development] for generic instructions on how
  45. to update the code in your checkout.
  46. ## Generating project files
  47. [GN][gn] is used to generate [Ninja][ninja] project files. In order to configure
  48. [GN][gn] to generate build files for iOS certain variables need to be set.
  49. Those variables can be edited for the various build configurations as needed.
  50. The variables you should care about are the following:
  51. * `target_os`:
  52. - To build for iOS this should be set as `target_os="ios"` in your `gn args`.
  53. The default is whatever OS you are running the script on, so this can be
  54. omitted when generating build files for macOS.
  55. * `target_cpu`:
  56. - For builds targeting iOS devices, this should be set to either `"arm"` or
  57. `"arm64"`, depending on the architecture of the device. For builds to run in
  58. the simulator, this should be set to `"x64"`.
  59. * `is_debug`:
  60. - Debug builds are the default. When building for release, specify `false`.
  61. The component build is the default for Debug builds, which are also enabled by
  62. default unless `is_debug=false` is specified.
  63. The [GN][gn] command for generating build files is `gn gen <output folder>`.
  64. After you've generated your build files once, subsequent invocations of `gn gen`
  65. with the same output folder will use the same arguments as first supplied.
  66. To edit these at any time use `gn args <output folder>`. This will open up
  67. a file in `$EDITOR` where you can edit the arguments. When you've made
  68. changes and save the file, `gn` will regenerate your project files for you
  69. with the new arguments.
  70. ### Examples
  71. ```
  72. $ # debug build for 64-bit iOS
  73. $ gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64"'
  74. $ # debug build for simulator
  75. $ gn gen out/ios_sim --args='target_os="ios" target_cpu="x64"'
  76. ```
  77. ## Compiling with ninja
  78. To compile, just run ninja on the appropriate target. For example:
  79. ```
  80. $ ninja -C out/ios_64 AppRTCMobile
  81. ```
  82. Replace `AppRTCMobile` in the command above with the target you
  83. are interested in.
  84. To see a list of available targets, run `gn ls out/<output folder>`.
  85. ## Using Xcode
  86. Xcode is the default and preferred IDE to develop for the iOS platform.
  87. *Generating an Xcode project*
  88. To have GN generate Xcode project files, pass the argument `--ide=xcode`
  89. when running `gn gen`. This will result in a file named `all.xcworkspace`
  90. placed in your specified output directory.
  91. Example:
  92. ```
  93. $ gn gen out/ios --args='target_os="ios" target_cpu="arm64"' --ide=xcode
  94. $ open -a Xcode.app out/ios/all.xcworkspace
  95. ```
  96. *Compile and run with Xcode*
  97. Compiling with Xcode is not supported! What we do instead is compile using a
  98. script that runs ninja from Xcode. This is done with a custom _run script_
  99. action in the build phases of the generated project. This script will simply
  100. call ninja as you would when building from the command line.
  101. This gives us access to the usual deployment/debugging workflow iOS developers
  102. are used to in Xcode, without sacrificing the build speed of Ninja.
  103. ## Running the tests
  104. There are several test targets in WebRTC. To run the tests, you must deploy the
  105. `.app` bundle to a device (see next section) and run them from there.
  106. To run a specific test or collection of tests, normally with gtest one would pass
  107. the `--gtest_filter` argument to the test binary when running. To do this when
  108. running the tests from Xcode, from the targets menu, select the test bundle
  109. and press _edit scheme..._ at the bottom of the target dropdown menu. From there
  110. click _Run_ in the sidebar and add `--gtest_filter` to the _Arguments passed on
  111. Launch_ list.
  112. If deploying to a device via the command line using [`ios-deploy`][ios-deploy],
  113. use the `-a` flag to pass arguments to the executable on launch.
  114. ## Deploying to Device
  115. It's easiest to deploy to a device using Xcode. Other command line tools exist
  116. as well, e.g. [`ios-deploy`][ios-deploy].
  117. **NOTICE:** To deploy to an iOS device you must have a valid signing identity
  118. set up. You can verify this by running:
  119. ```
  120. $ xcrun security find-identity -v -p codesigning
  121. ```
  122. If you don't have a valid signing identity, you can still build for ARM,
  123. but you won't be able to deploy your code to an iOS device. To do this,
  124. add the flag `ios_enable_code_signing=false` to the `gn gen` args when you
  125. generate the build files.
  126. ## Using WebRTC in your app
  127. To build WebRTC for use in a native iOS app, it's easiest to build
  128. `WebRTC.framework`. This can be done with ninja as follows, replacing `ios`
  129. with the actual location of your generated build files.
  130. ```
  131. ninja -C out/ios framework_objc
  132. ```
  133. This should result in a `.framework` bundle being generated in `out/ios`.
  134. This bundle can now be directly included in another app.
  135. If you need a FAT `.framework`, that is, a binary that contains code for
  136. multiple architectures, and will work both on device and in the simulator,
  137. a script is available [here][framework-script]
  138. To build the framework with bitcode support, pass the `--bitcode` flag to the script like so
  139. ```
  140. $ python build_ios_libs.py --bitcode
  141. ```
  142. The resulting framework can be found in out_ios_libs/.
  143. Please note that you can not ship the FAT framework binary with your app
  144. if you intend to distribute it through the app store.
  145. To solve this either remove "x86-64" from the list of architectures in
  146. the [build script][framework-script] or split the binary and recreate it without x86-64.
  147. For instructions on how to do this see [here][strip-arch].
  148. [cocoapods]: https://cocoapods.org/pods/GoogleWebRTC
  149. [webrtc-prerequisite-sw]: https://webrtc.googlesource.com/src/+/refs/heads/master/docs/native-code/development/prerequisite-sw/index.md
  150. [webrtc-development]: https://webrtc.googlesource.com/src/+/refs/heads/master/docs/native-code/development/index.md
  151. [framework-script]: https://chromium.googlesource.com/external/webrtc/+/master/tools_webrtc/ios/build_ios_libs.py
  152. [ninja]: https://ninja-build.org/
  153. [gn]: https://gn.googlesource.com/gn/+/master/README.md
  154. [ios-deploy]: https://github.com/phonegap/ios-deploy
  155. [strip-arch]: http://ikennd.ac/blog/2015/02/stripping-unwanted-architectures-from-dynamic-libraries-in-xcode/