blob: 1b659b5707c42f865cb3e7f08a3e8f28f79ba1f3 [file] [log] [blame]
hjonbc73fe12016-03-21 11:38:26 -07001#!/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
tkchin5fa51e22016-10-05 13:16:03 -070011# Generates static FAT libraries for ios in out_ios_libs.
hjonbc73fe12016-03-21 11:38:26 -070012
tkchin5209d672016-04-16 12:06:33 -070013# Exit on errors.
14set -e
hjonbc73fe12016-03-21 11:38:26 -070015
VladimirTechMan18b87742016-10-30 23:09:44 -070016# Environment
17export PATH=/usr/libexec:$PATH
18
tkchin5209d672016-04-16 12:06:33 -070019SCRIPT_DIR=$(cd $(dirname $0) && pwd)
hjonbc73fe12016-03-21 11:38:26 -070020WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../..
hjonbc73fe12016-03-21 11:38:26 -070021
Zeke Chindd0e1e02016-10-11 13:27:26 -070022function 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
hjonbc73fe12016-03-21 11:38:26 -070028}
29
Zeke Chindd0e1e02016-10-11 13:27:26 -070030function 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
tkchinfb94cd62016-11-21 23:30:56 -080036 local use_bitcode=$6
37 local custom_gn_options=$7
hjonbc73fe12016-03-21 11:38:26 -070038
Zeke Chindd0e1e02016-10-11 13:27:26 -070039 OUTPUT_DIR=${SDK_OUTPUT_DIR}/${target_arch}_libs
40 GN_ARGS="target_os=\"ios\" ios_enable_code_signing=false \
tkchinfb94cd62016-11-21 23:30:56 -080041use_xcode_clang=true is_component_build=false"
Zeke Chindd0e1e02016-10-11 13:27:26 -070042
43 # Add flavor option.
44 if [[ ${flavor} = "debug" ]]; then
45 GN_ARGS="${GN_ARGS} is_debug=true"
46 elif [[ ${flavor} = "release" ]]; then
47 GN_ARGS="${GN_ARGS} is_debug=false"
48 else
49 echo "Unexpected flavor type: ${flavor}"
50 exit 1
51 fi
52
53 # Add the specified architecture.
54 OUTPUT_LIB=${OUTPUT_DIR}/${SDK_LIB_NAME}
55 GN_ARGS="${GN_ARGS} target_cpu=\"${target_arch}\""
56
57 # Add deployment target.
58 GN_ARGS="${GN_ARGS} ios_deployment_target=\"${ios_deployment_target}\""
59
60 # Add vp9 option.
61 GN_ARGS="${GN_ARGS} rtc_libvpx_build_vp9=${libvpx_build_vp9}"
62
tkchinfb94cd62016-11-21 23:30:56 -080063 # Add bitcode option.
64 GN_ARGS="${GN_ARGS} rtc_ios_enable_bitcode=${use_bitcode}"
65
Zeke Chindd0e1e02016-10-11 13:27:26 -070066 # Add custom options.
67 if [[ -n "${custom_gn_options}" ]]; then
68 GN_ARGS="${GN_ARGS} ${custom_gn_options}"
69 fi
70
71 # Generate static or dynamic.
72 if [[ ${build_type} = "static_only" ]]; then
73 GN_TARGET_NAME="rtc_sdk_objc"
74 elif [[ ${build_type} == "framework" ]]; then
75 GN_TARGET_NAME="rtc_sdk_framework_objc"
76 GN_ARGS="${GN_ARGS} enable_dsyms=true enable_stripping=true"
77 fi
78
79 echo "Building WebRTC with args: ${GN_ARGS}"
80 gn gen ${OUTPUT_DIR} --args="${GN_ARGS}"
81 echo "Building target: ${GN_TARGET_NAME}"
82 ninja -C ${OUTPUT_DIR} ${GN_TARGET_NAME}
83
84 # Strip debug symbols to reduce size.
85 if [[ ${build_type} = "static_only" ]]; then
86 strip -S ${OUTPUT_DIR}/obj/webrtc/sdk/lib${GN_TARGET_NAME}.a -o \
87 ${OUTPUT_DIR}/lib${GN_TARGET_NAME}.a
88 fi
89}
90
91function usage {
92 echo "WebRTC iOS FAT libraries build script."
93 echo "Each architecture is compiled separately before being merged together."
94 echo "By default, the fat libraries will be created in out_ios_libs/."
95 echo "The headers will be copied to out_ios_libs/include."
96 echo "Usage: $0 [-h] [-b build_type] [-c] [-o output_dir]"
97 echo " -h Print this help."
98 echo " -b The build type. Can be framework or static_only."
99 echo " Defaults to framework."
100 echo " -c Removes generated build output."
101 echo " -o Specifies a directory to output build artifacts to."
102 echo " If specified together with -c, deletes the dir."
103 echo " -r Specifies a revision number to embed if building the framework."
tkchinfb94cd62016-11-21 23:30:56 -0800104 echo " -e Compile with bitcode."
Zeke Chindd0e1e02016-10-11 13:27:26 -0700105 exit 0
106}
107
108SDK_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs
109SDK_LIB_NAME="librtc_sdk_objc.a"
110SDK_FRAMEWORK_NAME="WebRTC.framework"
111
112BUILD_FLAVOR="release"
113BUILD_TYPE="framework"
kthelgason5ec208f2016-11-10 01:13:43 -0800114ENABLED_ARCHITECTURES=("arm" "arm64" "x64")
Zeke Chindd0e1e02016-10-11 13:27:26 -0700115IOS_DEPLOYMENT_TARGET="8.0"
116LIBVPX_BUILD_VP9="false"
tkchinfb94cd62016-11-21 23:30:56 -0800117USE_BITCODE="false"
Zeke Chindd0e1e02016-10-11 13:27:26 -0700118CUSTOM_GN_OPTS=""
119WEBRTC_REVISION="0"
120
121# Parse arguments.
122while getopts "hb:co:r:" opt; do
123 case "${opt}" in
124 h) usage;;
125 b) BUILD_TYPE="${OPTARG}";;
126 c) PERFORM_CLEAN=1;;
tkchinfb94cd62016-11-21 23:30:56 -0800127 e) USE_BITCODE="true";;
Zeke Chindd0e1e02016-10-11 13:27:26 -0700128 o) SDK_OUTPUT_DIR="${OPTARG}";;
129 r) WEBRTC_REVISION="${OPTARG}";;
130 *)
131 usage
132 exit 1
133 ;;
134 esac
135done
136
137if [[ ${PERFORM_CLEAN} -ne 0 ]]; then
138 clean_artifacts ${SDK_OUTPUT_DIR}
139 exit 0
140fi
141
142# Build all architectures.
kthelgason5ec208f2016-11-10 01:13:43 -0800143for arch in ${ENABLED_ARCHITECTURES[*]}; do
144 build_webrtc $arch ${BUILD_FLAVOR} ${BUILD_TYPE} \
tkchinfb94cd62016-11-21 23:30:56 -0800145 ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${USE_BITCODE} \
146 ${CUSTOM_GN_OPTS}
kthelgason5ec208f2016-11-10 01:13:43 -0800147done
Zeke Chindd0e1e02016-10-11 13:27:26 -0700148
149# Ignoring x86 except for static libraries for now because of a GN build issue
150# where the generated dynamic framework has the wrong architectures.
151
152# Create FAT archive.
153if [[ ${BUILD_TYPE} = "static_only" ]]; then
154 build_webrtc "x86" ${BUILD_FLAVOR} ${BUILD_TYPE} \
tkchinfb94cd62016-11-21 23:30:56 -0800155 ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${USE_BITCODE} \
156 ${CUSTOM_GN_OPTS}
Zeke Chindd0e1e02016-10-11 13:27:26 -0700157
158 ARM_LIB_PATH=${SDK_OUTPUT_DIR}/arm_libs/${SDK_LIB_NAME}
159 ARM64_LIB_PATH=${SDK_OUTPUT_DIR}/arm64_libs/${SDK_LIB_NAME}
160 X64_LIB_PATH=${SDK_OUTPUT_DIR}/x64_libs/${SDK_LIB_NAME}
161 X86_LIB_PATH=${SDK_OUTPUT_DIR}/x86_libs/${SDK_LIB_NAME}
162
163 # Combine the slices.
164 lipo ${ARM_LIB_PATH} ${ARM64_LIB_PATH} ${X64_LIB_PATH} ${X86_LIB_PATH} \
165 -create -output ${SDK_OUTPUT_DIR}/${SDK_LIB_NAME}
166elif [[ ${BUILD_TYPE} = "framework" ]]; then
167 ARM_LIB_PATH=${SDK_OUTPUT_DIR}/arm_libs
168 ARM64_LIB_PATH=${SDK_OUTPUT_DIR}/arm64_libs
169 X64_LIB_PATH=${SDK_OUTPUT_DIR}/x64_libs
170 X86_LIB_PATH=${SDK_OUTPUT_DIR}/x86_libs
171
172 # Combine the slices.
173 DYLIB_PATH="WebRTC.framework/WebRTC"
174 cp -R ${ARM64_LIB_PATH}/WebRTC.framework ${SDK_OUTPUT_DIR}
175 rm ${SDK_OUTPUT_DIR}/${DYLIB_PATH}
176 echo "Merging framework slices."
177 lipo ${ARM_LIB_PATH}/${DYLIB_PATH} \
178 ${ARM64_LIB_PATH}/${DYLIB_PATH} \
179 ${X64_LIB_PATH}/${DYLIB_PATH} \
180 -create -output ${SDK_OUTPUT_DIR}/${DYLIB_PATH}
181
182 # Remove stray mobileprovision if it exists until chromium roll lands.
183 # See https://codereview.chromium.org/2397433002.
184 PROVISION_FILE=${SDK_OUTPUT_DIR}/WebRTC.framework/embedded.mobileprovision
185 if [[ -e ${PROVISION_FILE} ]]; then
186 rm ${PROVISION_FILE}
187 fi
188
189 # Merge the dSYM slices.
190 DSYM_PATH="WebRTC.dSYM/Contents/Resources/DWARF/WebRTC"
191 cp -R ${ARM64_LIB_PATH}/WebRTC.dSYM ${SDK_OUTPUT_DIR}
192 rm ${SDK_OUTPUT_DIR}/${DSYM_PATH}
193 echo "Merging dSYM slices."
194 lipo ${ARM_LIB_PATH}/${DSYM_PATH} \
195 ${ARM64_LIB_PATH}/${DSYM_PATH} \
196 ${X64_LIB_PATH}/${DSYM_PATH} \
197 -create -output ${SDK_OUTPUT_DIR}/${DSYM_PATH}
198
199 # Modify the version number.
200 # Format should be <Branch cut MXX>.<Hotfix #>.<Rev #>.
201 # e.g. 55.0.14986 means branch cut 55, no hotfixes, and revision number 14986.
202 INFOPLIST_PATH=${SDK_OUTPUT_DIR}/WebRTC.framework/Info.plist
203 MAJOR_MINOR=$(PlistBuddy -c "Print :CFBundleShortVersionString" \
204 ${INFOPLIST_PATH})
205 VERSION_NUMBER="${MAJOR_MINOR}.${WEBRTC_REVISION}"
206 echo "Substituting revision number: ${VERSION_NUMBER}"
207 PlistBuddy -c "Set :CFBundleVersion ${VERSION_NUMBER}" ${INFOPLIST_PATH}
208 plutil -convert binary1 ${INFOPLIST_PATH}
209else
210 echo "BUILD_TYPE ${BUILD_TYPE} not supported."
211 exit 1
212fi
hjonbc73fe12016-03-21 11:38:26 -0700213
tkchin5fa51e22016-10-05 13:16:03 -0700214echo "Done."