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