blob: eaeab201f864b237d3785107d00333330cfd86b8 [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
36 local custom_gn_options=$6
hjonbc73fe12016-03-21 11:38:26 -070037
Zeke Chindd0e1e02016-10-11 13:27:26 -070038 OUTPUT_DIR=${SDK_OUTPUT_DIR}/${target_arch}_libs
39 GN_ARGS="target_os=\"ios\" ios_enable_code_signing=false \
kthelgason5ec208f2016-11-10 01:13:43 -080040use_xcode_clang=true is_component_build=false rtc_ios_enable_bitcode=true"
Zeke Chindd0e1e02016-10-11 13:27:26 -070041
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
87function 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
103SDK_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs
104SDK_LIB_NAME="librtc_sdk_objc.a"
105SDK_FRAMEWORK_NAME="WebRTC.framework"
106
107BUILD_FLAVOR="release"
108BUILD_TYPE="framework"
kthelgason5ec208f2016-11-10 01:13:43 -0800109ENABLED_ARCHITECTURES=("arm" "arm64" "x64")
Zeke Chindd0e1e02016-10-11 13:27:26 -0700110IOS_DEPLOYMENT_TARGET="8.0"
111LIBVPX_BUILD_VP9="false"
112CUSTOM_GN_OPTS=""
113WEBRTC_REVISION="0"
114
115# Parse arguments.
116while getopts "hb:co:r:" opt; do
117 case "${opt}" in
118 h) usage;;
119 b) BUILD_TYPE="${OPTARG}";;
120 c) PERFORM_CLEAN=1;;
121 o) SDK_OUTPUT_DIR="${OPTARG}";;
122 r) WEBRTC_REVISION="${OPTARG}";;
123 *)
124 usage
125 exit 1
126 ;;
127 esac
128done
129
130if [[ ${PERFORM_CLEAN} -ne 0 ]]; then
131 clean_artifacts ${SDK_OUTPUT_DIR}
132 exit 0
133fi
134
135# Build all architectures.
kthelgason5ec208f2016-11-10 01:13:43 -0800136for arch in ${ENABLED_ARCHITECTURES[*]}; do
137 build_webrtc $arch ${BUILD_FLAVOR} ${BUILD_TYPE} \
138 ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${CUSTOM_GN_OPTS}
139done
Zeke Chindd0e1e02016-10-11 13:27:26 -0700140
141# Ignoring x86 except for static libraries for now because of a GN build issue
142# where the generated dynamic framework has the wrong architectures.
143
144# Create FAT archive.
145if [[ ${BUILD_TYPE} = "static_only" ]]; then
146 build_webrtc "x86" ${BUILD_FLAVOR} ${BUILD_TYPE} \
147 ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${CUSTOM_GN_OPTS}
148
149 ARM_LIB_PATH=${SDK_OUTPUT_DIR}/arm_libs/${SDK_LIB_NAME}
150 ARM64_LIB_PATH=${SDK_OUTPUT_DIR}/arm64_libs/${SDK_LIB_NAME}
151 X64_LIB_PATH=${SDK_OUTPUT_DIR}/x64_libs/${SDK_LIB_NAME}
152 X86_LIB_PATH=${SDK_OUTPUT_DIR}/x86_libs/${SDK_LIB_NAME}
153
154 # Combine the slices.
155 lipo ${ARM_LIB_PATH} ${ARM64_LIB_PATH} ${X64_LIB_PATH} ${X86_LIB_PATH} \
156 -create -output ${SDK_OUTPUT_DIR}/${SDK_LIB_NAME}
157elif [[ ${BUILD_TYPE} = "framework" ]]; then
158 ARM_LIB_PATH=${SDK_OUTPUT_DIR}/arm_libs
159 ARM64_LIB_PATH=${SDK_OUTPUT_DIR}/arm64_libs
160 X64_LIB_PATH=${SDK_OUTPUT_DIR}/x64_libs
161 X86_LIB_PATH=${SDK_OUTPUT_DIR}/x86_libs
162
163 # Combine the slices.
164 DYLIB_PATH="WebRTC.framework/WebRTC"
165 cp -R ${ARM64_LIB_PATH}/WebRTC.framework ${SDK_OUTPUT_DIR}
166 rm ${SDK_OUTPUT_DIR}/${DYLIB_PATH}
167 echo "Merging framework slices."
168 lipo ${ARM_LIB_PATH}/${DYLIB_PATH} \
169 ${ARM64_LIB_PATH}/${DYLIB_PATH} \
170 ${X64_LIB_PATH}/${DYLIB_PATH} \
171 -create -output ${SDK_OUTPUT_DIR}/${DYLIB_PATH}
172
173 # Remove stray mobileprovision if it exists until chromium roll lands.
174 # See https://codereview.chromium.org/2397433002.
175 PROVISION_FILE=${SDK_OUTPUT_DIR}/WebRTC.framework/embedded.mobileprovision
176 if [[ -e ${PROVISION_FILE} ]]; then
177 rm ${PROVISION_FILE}
178 fi
179
180 # Merge the dSYM slices.
181 DSYM_PATH="WebRTC.dSYM/Contents/Resources/DWARF/WebRTC"
182 cp -R ${ARM64_LIB_PATH}/WebRTC.dSYM ${SDK_OUTPUT_DIR}
183 rm ${SDK_OUTPUT_DIR}/${DSYM_PATH}
184 echo "Merging dSYM slices."
185 lipo ${ARM_LIB_PATH}/${DSYM_PATH} \
186 ${ARM64_LIB_PATH}/${DSYM_PATH} \
187 ${X64_LIB_PATH}/${DSYM_PATH} \
188 -create -output ${SDK_OUTPUT_DIR}/${DSYM_PATH}
189
190 # Modify the version number.
191 # Format should be <Branch cut MXX>.<Hotfix #>.<Rev #>.
192 # e.g. 55.0.14986 means branch cut 55, no hotfixes, and revision number 14986.
193 INFOPLIST_PATH=${SDK_OUTPUT_DIR}/WebRTC.framework/Info.plist
194 MAJOR_MINOR=$(PlistBuddy -c "Print :CFBundleShortVersionString" \
195 ${INFOPLIST_PATH})
196 VERSION_NUMBER="${MAJOR_MINOR}.${WEBRTC_REVISION}"
197 echo "Substituting revision number: ${VERSION_NUMBER}"
198 PlistBuddy -c "Set :CFBundleVersion ${VERSION_NUMBER}" ${INFOPLIST_PATH}
199 plutil -convert binary1 ${INFOPLIST_PATH}
200else
201 echo "BUILD_TYPE ${BUILD_TYPE} not supported."
202 exit 1
203fi
hjonbc73fe12016-03-21 11:38:26 -0700204
tkchin5fa51e22016-10-05 13:16:03 -0700205echo "Done."