hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license |
| 6 | # that can be found in the LICENSE file in the root of the source |
| 7 | # tree. An additional intellectual property rights grant can be found |
| 8 | # in the file PATENTS. All contributing project authors may |
| 9 | # be found in the AUTHORS file in the root of the source tree. |
| 10 | |
tkchin | 5fa51e2 | 2016-10-05 13:16:03 -0700 | [diff] [blame] | 11 | # Generates static FAT libraries for ios in out_ios_libs. |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 12 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 13 | # Exit on errors. |
| 14 | set -e |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 15 | |
VladimirTechMan | 18b8774 | 2016-10-30 23:09:44 -0700 | [diff] [blame^] | 16 | # Environment |
| 17 | export PATH=/usr/libexec:$PATH |
| 18 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 19 | SCRIPT_DIR=$(cd $(dirname $0) && pwd) |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 20 | WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 21 | |
Zeke Chin | dd0e1e0 | 2016-10-11 13:27:26 -0700 | [diff] [blame] | 22 | function clean_artifacts { |
| 23 | local output_dir=$1 |
| 24 | if [[ -d ${output_dir} ]]; then |
| 25 | echo "Deleting ${output_dir}" |
| 26 | rm -r ${output_dir} |
| 27 | fi |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Zeke Chin | dd0e1e0 | 2016-10-11 13:27:26 -0700 | [diff] [blame] | 30 | function build_webrtc { |
| 31 | local target_arch=$1 |
| 32 | local flavor=$2 |
| 33 | local build_type=$3 |
| 34 | local ios_deployment_target=$4 |
| 35 | local libvpx_build_vp9=$5 |
| 36 | local custom_gn_options=$6 |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 37 | |
Zeke Chin | dd0e1e0 | 2016-10-11 13:27:26 -0700 | [diff] [blame] | 38 | OUTPUT_DIR=${SDK_OUTPUT_DIR}/${target_arch}_libs |
| 39 | GN_ARGS="target_os=\"ios\" ios_enable_code_signing=false \ |
| 40 | use_xcode_clang=true is_component_build=false" |
| 41 | |
| 42 | # Add flavor option. |
| 43 | if [[ ${flavor} = "debug" ]]; then |
| 44 | GN_ARGS="${GN_ARGS} is_debug=true" |
| 45 | elif [[ ${flavor} = "release" ]]; then |
| 46 | GN_ARGS="${GN_ARGS} is_debug=false" |
| 47 | else |
| 48 | echo "Unexpected flavor type: ${flavor}" |
| 49 | exit 1 |
| 50 | fi |
| 51 | |
| 52 | # Add the specified architecture. |
| 53 | OUTPUT_LIB=${OUTPUT_DIR}/${SDK_LIB_NAME} |
| 54 | GN_ARGS="${GN_ARGS} target_cpu=\"${target_arch}\"" |
| 55 | |
| 56 | # Add deployment target. |
| 57 | GN_ARGS="${GN_ARGS} ios_deployment_target=\"${ios_deployment_target}\"" |
| 58 | |
| 59 | # Add vp9 option. |
| 60 | GN_ARGS="${GN_ARGS} rtc_libvpx_build_vp9=${libvpx_build_vp9}" |
| 61 | |
| 62 | # Add custom options. |
| 63 | if [[ -n "${custom_gn_options}" ]]; then |
| 64 | GN_ARGS="${GN_ARGS} ${custom_gn_options}" |
| 65 | fi |
| 66 | |
| 67 | # Generate static or dynamic. |
| 68 | if [[ ${build_type} = "static_only" ]]; then |
| 69 | GN_TARGET_NAME="rtc_sdk_objc" |
| 70 | elif [[ ${build_type} == "framework" ]]; then |
| 71 | GN_TARGET_NAME="rtc_sdk_framework_objc" |
| 72 | GN_ARGS="${GN_ARGS} enable_dsyms=true enable_stripping=true" |
| 73 | fi |
| 74 | |
| 75 | echo "Building WebRTC with args: ${GN_ARGS}" |
| 76 | gn gen ${OUTPUT_DIR} --args="${GN_ARGS}" |
| 77 | echo "Building target: ${GN_TARGET_NAME}" |
| 78 | ninja -C ${OUTPUT_DIR} ${GN_TARGET_NAME} |
| 79 | |
| 80 | # Strip debug symbols to reduce size. |
| 81 | if [[ ${build_type} = "static_only" ]]; then |
| 82 | strip -S ${OUTPUT_DIR}/obj/webrtc/sdk/lib${GN_TARGET_NAME}.a -o \ |
| 83 | ${OUTPUT_DIR}/lib${GN_TARGET_NAME}.a |
| 84 | fi |
| 85 | } |
| 86 | |
| 87 | function usage { |
| 88 | echo "WebRTC iOS FAT libraries build script." |
| 89 | echo "Each architecture is compiled separately before being merged together." |
| 90 | echo "By default, the fat libraries will be created in out_ios_libs/." |
| 91 | echo "The headers will be copied to out_ios_libs/include." |
| 92 | echo "Usage: $0 [-h] [-b build_type] [-c] [-o output_dir]" |
| 93 | echo " -h Print this help." |
| 94 | echo " -b The build type. Can be framework or static_only." |
| 95 | echo " Defaults to framework." |
| 96 | echo " -c Removes generated build output." |
| 97 | echo " -o Specifies a directory to output build artifacts to." |
| 98 | echo " If specified together with -c, deletes the dir." |
| 99 | echo " -r Specifies a revision number to embed if building the framework." |
| 100 | exit 0 |
| 101 | } |
| 102 | |
| 103 | SDK_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs |
| 104 | SDK_LIB_NAME="librtc_sdk_objc.a" |
| 105 | SDK_FRAMEWORK_NAME="WebRTC.framework" |
| 106 | |
| 107 | BUILD_FLAVOR="release" |
| 108 | BUILD_TYPE="framework" |
| 109 | IOS_DEPLOYMENT_TARGET="8.0" |
| 110 | LIBVPX_BUILD_VP9="false" |
| 111 | CUSTOM_GN_OPTS="" |
| 112 | WEBRTC_REVISION="0" |
| 113 | |
| 114 | # Parse arguments. |
| 115 | while getopts "hb:co:r:" opt; do |
| 116 | case "${opt}" in |
| 117 | h) usage;; |
| 118 | b) BUILD_TYPE="${OPTARG}";; |
| 119 | c) PERFORM_CLEAN=1;; |
| 120 | o) SDK_OUTPUT_DIR="${OPTARG}";; |
| 121 | r) WEBRTC_REVISION="${OPTARG}";; |
| 122 | *) |
| 123 | usage |
| 124 | exit 1 |
| 125 | ;; |
| 126 | esac |
| 127 | done |
| 128 | |
| 129 | if [[ ${PERFORM_CLEAN} -ne 0 ]]; then |
| 130 | clean_artifacts ${SDK_OUTPUT_DIR} |
| 131 | exit 0 |
| 132 | fi |
| 133 | |
| 134 | # Build all architectures. |
| 135 | build_webrtc "arm" ${BUILD_FLAVOR} ${BUILD_TYPE} \ |
| 136 | ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${CUSTOM_GN_OPTS} |
| 137 | build_webrtc "arm64" ${BUILD_FLAVOR} ${BUILD_TYPE} \ |
| 138 | ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${CUSTOM_GN_OPTS} |
| 139 | build_webrtc "x64" ${BUILD_FLAVOR} ${BUILD_TYPE} \ |
| 140 | ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${CUSTOM_GN_OPTS} |
| 141 | |
| 142 | # Ignoring x86 except for static libraries for now because of a GN build issue |
| 143 | # where the generated dynamic framework has the wrong architectures. |
| 144 | |
| 145 | # Create FAT archive. |
| 146 | if [[ ${BUILD_TYPE} = "static_only" ]]; then |
| 147 | build_webrtc "x86" ${BUILD_FLAVOR} ${BUILD_TYPE} \ |
| 148 | ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${CUSTOM_GN_OPTS} |
| 149 | |
| 150 | ARM_LIB_PATH=${SDK_OUTPUT_DIR}/arm_libs/${SDK_LIB_NAME} |
| 151 | ARM64_LIB_PATH=${SDK_OUTPUT_DIR}/arm64_libs/${SDK_LIB_NAME} |
| 152 | X64_LIB_PATH=${SDK_OUTPUT_DIR}/x64_libs/${SDK_LIB_NAME} |
| 153 | X86_LIB_PATH=${SDK_OUTPUT_DIR}/x86_libs/${SDK_LIB_NAME} |
| 154 | |
| 155 | # Combine the slices. |
| 156 | lipo ${ARM_LIB_PATH} ${ARM64_LIB_PATH} ${X64_LIB_PATH} ${X86_LIB_PATH} \ |
| 157 | -create -output ${SDK_OUTPUT_DIR}/${SDK_LIB_NAME} |
| 158 | elif [[ ${BUILD_TYPE} = "framework" ]]; then |
| 159 | ARM_LIB_PATH=${SDK_OUTPUT_DIR}/arm_libs |
| 160 | ARM64_LIB_PATH=${SDK_OUTPUT_DIR}/arm64_libs |
| 161 | X64_LIB_PATH=${SDK_OUTPUT_DIR}/x64_libs |
| 162 | X86_LIB_PATH=${SDK_OUTPUT_DIR}/x86_libs |
| 163 | |
| 164 | # Combine the slices. |
| 165 | DYLIB_PATH="WebRTC.framework/WebRTC" |
| 166 | cp -R ${ARM64_LIB_PATH}/WebRTC.framework ${SDK_OUTPUT_DIR} |
| 167 | rm ${SDK_OUTPUT_DIR}/${DYLIB_PATH} |
| 168 | echo "Merging framework slices." |
| 169 | lipo ${ARM_LIB_PATH}/${DYLIB_PATH} \ |
| 170 | ${ARM64_LIB_PATH}/${DYLIB_PATH} \ |
| 171 | ${X64_LIB_PATH}/${DYLIB_PATH} \ |
| 172 | -create -output ${SDK_OUTPUT_DIR}/${DYLIB_PATH} |
| 173 | |
| 174 | # Remove stray mobileprovision if it exists until chromium roll lands. |
| 175 | # See https://codereview.chromium.org/2397433002. |
| 176 | PROVISION_FILE=${SDK_OUTPUT_DIR}/WebRTC.framework/embedded.mobileprovision |
| 177 | if [[ -e ${PROVISION_FILE} ]]; then |
| 178 | rm ${PROVISION_FILE} |
| 179 | fi |
| 180 | |
| 181 | # Merge the dSYM slices. |
| 182 | DSYM_PATH="WebRTC.dSYM/Contents/Resources/DWARF/WebRTC" |
| 183 | cp -R ${ARM64_LIB_PATH}/WebRTC.dSYM ${SDK_OUTPUT_DIR} |
| 184 | rm ${SDK_OUTPUT_DIR}/${DSYM_PATH} |
| 185 | echo "Merging dSYM slices." |
| 186 | lipo ${ARM_LIB_PATH}/${DSYM_PATH} \ |
| 187 | ${ARM64_LIB_PATH}/${DSYM_PATH} \ |
| 188 | ${X64_LIB_PATH}/${DSYM_PATH} \ |
| 189 | -create -output ${SDK_OUTPUT_DIR}/${DSYM_PATH} |
| 190 | |
| 191 | # Modify the version number. |
| 192 | # Format should be <Branch cut MXX>.<Hotfix #>.<Rev #>. |
| 193 | # e.g. 55.0.14986 means branch cut 55, no hotfixes, and revision number 14986. |
| 194 | INFOPLIST_PATH=${SDK_OUTPUT_DIR}/WebRTC.framework/Info.plist |
| 195 | MAJOR_MINOR=$(PlistBuddy -c "Print :CFBundleShortVersionString" \ |
| 196 | ${INFOPLIST_PATH}) |
| 197 | VERSION_NUMBER="${MAJOR_MINOR}.${WEBRTC_REVISION}" |
| 198 | echo "Substituting revision number: ${VERSION_NUMBER}" |
| 199 | PlistBuddy -c "Set :CFBundleVersion ${VERSION_NUMBER}" ${INFOPLIST_PATH} |
| 200 | plutil -convert binary1 ${INFOPLIST_PATH} |
| 201 | else |
| 202 | echo "BUILD_TYPE ${BUILD_TYPE} not supported." |
| 203 | exit 1 |
| 204 | fi |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 205 | |
tkchin | 5fa51e2 | 2016-10-05 13:16:03 -0700 | [diff] [blame] | 206 | echo "Done." |