build_libwebrtc_macos.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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
  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. # avoid crashes when using Full HD resolution with HWA enabled
  26. # workaround referred from this discussion: https://groups.google.com/g/discuss-webrtc/c/AVeyMXnM0gY
  27. patch -N "src/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm" < "$COMMAND_DIR/patches/avoid_crashusingvideoencoderh264.patch"
  28. mkdir -p "$ARTIFACTS_DIR/lib"
  29. for is_debug in "true" "false"
  30. do
  31. for target_cpu in "x64" "arm64"
  32. do
  33. # generate ninja files
  34. gn gen "$OUTPUT_DIR" --root="src" \
  35. --args="is_debug=${is_debug} \
  36. target_os=\"mac\" \
  37. target_cpu=\"${target_cpu}\" \
  38. rtc_include_tests=false \
  39. rtc_build_examples=false \
  40. rtc_use_h264=false \
  41. symbol_level=0 \
  42. enable_iterator_debugging=false \
  43. is_component_build=false \
  44. use_rtti=true \
  45. rtc_use_x11=false \
  46. libcxx_abi_unstable=false"
  47. # build static library
  48. ninja -C "$OUTPUT_DIR" webrtc
  49. # copy static library
  50. mkdir -p "$ARTIFACTS_DIR/lib/${target_cpu}"
  51. cp "$OUTPUT_DIR/obj/libwebrtc.a" "$ARTIFACTS_DIR/lib/${target_cpu}/"
  52. done
  53. filename="libwebrtc.a"
  54. if [ $is_debug = "true" ]; then
  55. filename="libwebrtcd.a"
  56. fi
  57. # make universal binary
  58. lipo -create -output \
  59. "$ARTIFACTS_DIR/lib/${filename}" \
  60. "$ARTIFACTS_DIR/lib/arm64/libwebrtc.a" \
  61. "$ARTIFACTS_DIR/lib/x64/libwebrtc.a"
  62. rm -r "$ARTIFACTS_DIR/lib/arm64"
  63. rm -r "$ARTIFACTS_DIR/lib/x64"
  64. done
  65. # fix error when generate license
  66. patch -N "./src/tools_webrtc/libs/generate_licenses.py" < \
  67. "$COMMAND_DIR/patches/generate_licenses.patch"
  68. vpython "./src/tools_webrtc/libs/generate_licenses.py" \
  69. --target //:default "$OUTPUT_DIR" "$OUTPUT_DIR"
  70. cd src
  71. find . -name "*.h" -print | cpio -pd "$ARTIFACTS_DIR/include"
  72. cp "$OUTPUT_DIR/LICENSE.md" "$ARTIFACTS_DIR"
  73. # create zip
  74. cd "$ARTIFACTS_DIR"
  75. zip -r webrtc-mac.zip lib include LICENSE.md