build_libwebrtc_ios.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash -eu
  2. if [ ! -e "$(pwd)/depot_tools" ]
  3. then
  4. git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git
  5. fi
  6. export COMMAND_DIR=$(cd $(dirname $0); pwd)
  7. export PATH="$(pwd)/depot_tools:$PATH"
  8. export WEBRTC_VERSION=4515
  9. export OUTPUT_DIR="$(pwd)/out"
  10. export ARTIFACTS_DIR="$(pwd)/artifacts"
  11. if [ ! -e "$(pwd)/src" ]
  12. then
  13. fetch --nohooks webrtc_ios
  14. cd src
  15. sudo sh -c 'echo 127.0.1.1 $(hostname) >> /etc/hosts'
  16. sudo git config --system core.longpaths true
  17. git checkout "refs/remotes/branch-heads/$WEBRTC_VERSION"
  18. cd ..
  19. gclient sync -f
  20. fi
  21. # add jsoncpp
  22. patch -N "src/BUILD.gn" < "$COMMAND_DIR/patches/add_jsoncpp.patch"
  23. # add objc library to use videotoolbox
  24. patch -N "src/sdk/BUILD.gn" < "$COMMAND_DIR/patches/add_objc_deps.patch"
  25. # use included python
  26. export PATH="$(pwd)/depot_tools/bootstrap-3.8.0.chromium.8_bin/python/bin:$PATH"
  27. mkdir -p "$ARTIFACTS_DIR/lib"
  28. for is_debug in "true" "false"
  29. do
  30. for target_cpu in "arm64" "x64"
  31. do
  32. # generate ninja files
  33. #
  34. # note: `treat_warnings_as_errors=false` is for avoiding LLVM warning.
  35. # https://reviews.llvm.org/D72212
  36. # See below for details.
  37. # https://bugs.chromium.org/p/webrtc/issues/detail?id=11729
  38. #
  39. # note: `use_xcode_clang=true` is for using bitcode.
  40. #
  41. gn gen "$OUTPUT_DIR" --root="src" \
  42. --args="is_debug=${is_debug} \
  43. target_os=\"ios\" \
  44. target_cpu=\"${target_cpu}\" \
  45. rtc_use_h264=false \
  46. treat_warnings_as_errors=false \
  47. use_xcode_clang=true \
  48. enable_ios_bitcode=true \
  49. ios_enable_code_signing=false \
  50. rtc_include_tests=false \
  51. rtc_build_examples=false"
  52. # build static library
  53. ninja -C "$OUTPUT_DIR" webrtc
  54. # copy static library
  55. mkdir -p "$ARTIFACTS_DIR/lib/${target_cpu}"
  56. cp "$OUTPUT_DIR/obj/libwebrtc.a" "$ARTIFACTS_DIR/lib/${target_cpu}/"
  57. done
  58. filename="libwebrtc.a"
  59. if [ $is_debug = "true" ]; then
  60. filename="libwebrtcd.a"
  61. fi
  62. # make universal binary
  63. lipo -create -output \
  64. "$ARTIFACTS_DIR/lib/${filename}" \
  65. "$ARTIFACTS_DIR/lib/arm64/libwebrtc.a" \
  66. "$ARTIFACTS_DIR/lib/x64/libwebrtc.a"
  67. rm -r "$ARTIFACTS_DIR/lib/arm64"
  68. rm -r "$ARTIFACTS_DIR/lib/x64"
  69. done
  70. # fix error when generate license
  71. patch -N "./src/tools_webrtc/libs/generate_licenses.py" < \
  72. "$COMMAND_DIR/patches/generate_licenses.patch"
  73. vpython "./src/tools_webrtc/libs/generate_licenses.py" \
  74. --target //:default "$OUTPUT_DIR" "$OUTPUT_DIR"
  75. cd src
  76. find . -name "*.h" -print | cpio -pd "$ARTIFACTS_DIR/include"
  77. cp "$OUTPUT_DIR/LICENSE.md" "$ARTIFACTS_DIR"
  78. # create zip
  79. cd "$ARTIFACTS_DIR"
  80. zip -r webrtc-ios.zip lib include LICENSE.md