| 1 | #!/bin/bash |
| 2 | # Exit immediately if any command fails. This ensures CI properly reports build |
| 3 | # failures instead of continuing to create empty/broken artifacts. |
| 4 | set -e |
| 5 | |
| 6 | # Copyright 2023 LiveKit, Inc. |
| 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | |
| 20 | |
| 21 | arch="" |
| 22 | profile="release" |
| 23 | |
| 24 | while [ "$#" -gt 0 ]; do |
| 25 | case "$1" in |
| 26 | --arch) |
| 27 | arch="$2" |
| 28 | if [ "$arch" != "x64" ] && [ "$arch" != "arm64" ]; then |
| 29 | echo "Error: Invalid value for --arch. Must be 'x64' or 'arm64'." |
| 30 | exit 1 |
| 31 | fi |
| 32 | shift 2 |
| 33 | ;; |
| 34 | --profile) |
| 35 | profile="$2" |
| 36 | if [ "$profile" != "debug" ] && [ "$profile" != "release" ]; then |
| 37 | echo "Error: Invalid value for --profile. Must be 'debug' or 'release'." |
| 38 | exit 1 |
| 39 | fi |
| 40 | shift 2 |
| 41 | ;; |
| 42 | *) |
| 43 | echo "Error: Unknown argument '$1'" |
| 44 | exit 1 |
| 45 | ;; |
| 46 | esac |
| 47 | done |
| 48 | |
| 49 | if [ -z "$arch" ]; then |
| 50 | echo "Error: --arch must be set." |
| 51 | exit 1 |
| 52 | fi |
| 53 | |
| 54 | echo "Building LiveKit WebRTC - MacOS" |
| 55 | echo "Arch: $arch" |
| 56 | echo "Profile: $profile" |
| 57 | |
| 58 | if [ ! -e "$(pwd)/depot_tools" ] |
| 59 | then |
| 60 | git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git |
| 61 | fi |
| 62 | |
| 63 | export COMMAND_DIR=$(cd $(dirname $0); pwd) |
| 64 | export PATH="$(pwd)/depot_tools:$PATH" |
| 65 | export OUTPUT_DIR="$(pwd)/src/out-$arch-$profile" |
| 66 | export ARTIFACTS_DIR="$(pwd)/mac-$arch-$profile" |
| 67 | |
| 68 | if [ ! -e "$(pwd)/src" ] |
| 69 | then |
| 70 | gclient sync -D --no-history |
| 71 | fi |
| 72 | |
| 73 | source "$COMMAND_DIR/apply_patch.sh" |
| 74 | |
| 75 | cd src |
| 76 | |
| 77 | apply_patch "$COMMAND_DIR/patches/add_licenses.patch" |
| 78 | apply_patch "$COMMAND_DIR/patches/fix_license_json_parsing.patch" |
| 79 | apply_patch "$COMMAND_DIR/patches/ssl_verify_callback_with_native_handle.patch" |
| 80 | apply_patch "$COMMAND_DIR/patches/add_deps.patch" |
| 81 | apply_patch "$COMMAND_DIR/patches/external_audio_source.patch" |
| 82 | |
| 83 | cd .. |
| 84 | |
| 85 | mkdir -p "$ARTIFACTS_DIR/lib" |
| 86 | |
| 87 | debug="false" |
| 88 | if [ "$profile" = "debug" ]; then |
| 89 | debug="true" |
| 90 | fi |
| 91 | |
| 92 | # generate ninja files |
| 93 | # Note: use_clang_modules=false is required to avoid libc++ header incompatibility |
| 94 | # with Xcode 26.0. When enabled, C++ module compilation fails with errors like |
| 95 | # "unknown type name 'size_t'" due to conflicts between WebRTC's bundled libc++ |
| 96 | # headers and the macOS SDK headers. |
| 97 | gn gen "$OUTPUT_DIR" --root="src" \ |
| 98 | --args="is_debug=$debug \ |
| 99 | enable_dsyms=$debug \ |
| 100 | target_os=\"mac\" \ |
| 101 | target_cpu=\"$arch\" \ |
| 102 | mac_deployment_target=\"10.15\" \ |
| 103 | mac_min_system_version=\"10.15\" \ |
| 104 | treat_warnings_as_errors=false \ |
| 105 | rtc_enable_protobuf=false \ |
| 106 | rtc_include_tests=false \ |
| 107 | rtc_build_examples=false \ |
| 108 | rtc_build_tools=false \ |
| 109 | rtc_libvpx_build_vp9=true \ |
| 110 | enable_libaom=true \ |
| 111 | is_component_build=false \ |
| 112 | enable_stripping=true \ |
| 113 | rtc_enable_symbol_export=true \ |
| 114 | rtc_enable_objc_symbol_export=false \ |
| 115 | rtc_include_dav1d_in_internal_decoder_factory = true \ |
| 116 | rtc_use_h264=true \ |
| 117 | rtc_use_h265=true \ |
| 118 | use_custom_libcxx=false \ |
| 119 | use_clang_modules=false \ |
| 120 | clang_use_chrome_plugins=false \ |
| 121 | use_rtti=true \ |
| 122 | use_lld=false \ |
| 123 | rtc_include_internal_audio_device=true" |
| 124 | |
| 125 | # build static library |
| 126 | ninja -C "$OUTPUT_DIR" :default \ |
| 127 | api/audio_codecs:builtin_audio_decoder_factory \ |
| 128 | api/task_queue:default_task_queue_factory \ |
| 129 | sdk:native_api \ |
| 130 | sdk:default_codec_factory_objc \ |
| 131 | pc:peer_connection \ |
| 132 | sdk:videocapture_objc \ |
| 133 | sdk:mac_framework_objc \ |
| 134 | desktop_capture_objc \ |
| 135 | modules/audio_device:audio_device |
| 136 | |
| 137 | # make libwebrtc.a |
| 138 | # don't include nasm |
| 139 | ar -rc "$ARTIFACTS_DIR/lib/libwebrtc.a" `find "$OUTPUT_DIR/obj" -name '*.o' -not -path "*/third_party/nasm/*"` |
| 140 | |
| 141 | # License generation - may fail locally due to GN warnings breaking JSON parsing |
| 142 | # Use vpython3 from depot_tools for consistent Python version |
| 143 | vpython3 "./src/tools_webrtc/libs/generate_licenses.py" \ |
| 144 | --target :webrtc "$OUTPUT_DIR" "$OUTPUT_DIR" || echo "Warning: License generation failed" |
| 145 | |
| 146 | cp "$OUTPUT_DIR/obj/webrtc.ninja" "$ARTIFACTS_DIR" |
| 147 | cp "$OUTPUT_DIR/obj/modules/desktop_capture/desktop_capture.ninja" "$ARTIFACTS_DIR" 2>/dev/null || true |
| 148 | cp "$OUTPUT_DIR/args.gn" "$ARTIFACTS_DIR" |
| 149 | |
| 150 | cp "$OUTPUT_DIR/LICENSE.md" "$ARTIFACTS_DIR" |
| 151 | |
| 152 | cd src |
| 153 | find . -name "*.h" -print | cpio -pd "$ARTIFACTS_DIR/include" |
| 154 | find . -name "*.inc" -print | cpio -pd "$ARTIFACTS_DIR/include" |