OLD | NEW |
---|---|
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright 2015 The WebRTC project authors. All Rights Reserved. | 3 # Copyright 2015 The WebRTC project authors. All Rights Reserved. |
4 # | 4 # |
5 # Use of this source code is governed by a BSD-style license | 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 | 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 | 7 # tree. An additional intellectual property rights grant can be found |
8 # in the file PATENTS. All contributing project authors may | 8 # in the file PATENTS. All contributing project authors may |
9 # be found in the AUTHORS file in the root of the source tree. | 9 # be found in the AUTHORS file in the root of the source tree. |
10 | 10 |
11 # Generates static FAT libraries for ios in out_ios_libs. | 11 # Generates static FAT libraries for ios in out_ios_libs. |
12 | 12 |
13 # Exit on errors. | 13 # Exit on errors. |
14 set -e | 14 set -e |
15 | 15 |
16 SCRIPT_DIR=$(cd $(dirname $0) && pwd) | 16 SCRIPT_DIR=$(cd $(dirname $0) && pwd) |
17 WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. | 17 WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. |
18 | 18 |
19 function 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 | |
25 } | |
26 | |
27 function 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 | |
34 | |
35 OUTPUT_DIR=${SDK_OUTPUT_DIR}/${target_arch}_libs | |
36 GN_ARGS="target_os=\"ios\" ios_enable_code_signing=false \ | |
37 use_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 | |
84 function 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 | |
19 SDK_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs | 100 SDK_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs |
20 SDK_LIB_NAME="librtc_sdk_objc.a" | 101 SDK_LIB_NAME="librtc_sdk_objc.a" |
21 GN_BASE_ARGS="target_os=\"ios\" is_debug=false ios_enable_code_signing=false \ | 102 SDK_FRAMEWORK_NAME="WebRTC.framework" |
22 rtc_libvpx_build_vp9=false" | |
23 GN_STATIC_TARGET_NAMES="rtc_sdk_peerconnection_objc field_trial_default \ | |
24 metrics_default" | |
25 | 103 |
26 # TODO(tkchin): Restore functionality of old script to build dynamic framework, | 104 BUILD_FLAVOR="release" |
27 # symbols and license file. | 105 BUILD_TYPE="framework" |
106 IOS_DEPLOYMENT_TARGET="8.0" | |
107 LIBVPX_BUILD_VP9="false" | |
108 CUSTOM_GN_OPTS="" | |
109 WEBRTC_REVISION="1" | |
28 | 110 |
29 function build_static_webrtc { | 111 # Parse arguments. |
30 local arch=$1 | 112 while getopts "hb:co:r:" opt; do |
31 local xcode_arch=$2 | 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 | |
124 done | |
32 | 125 |
33 OUTPUT_DIR=${SDK_OUTPUT_DIR}/${arch}_libs | 126 if [[ ${PERFORM_CLEAN} -ne 0 ]]; then |
34 OUTPUT_LIB=${OUTPUT_DIR}/${SDK_LIB_NAME} | 127 clean_artifacts ${SDK_OUTPUT_DIR} |
35 GN_ARGS="${GN_BASE_ARGS} target_cpu=\"${arch}\"" | 128 exit 0 |
kjellander_webrtc
2016/10/11 04:04:30
I'm thinking maybe it's a bit unexpected that it a
tkchin_webrtc
2016/10/11 18:17:25
Was intended to be like gn clean, where it only ta
| |
36 gn gen ${OUTPUT_DIR} --args="${GN_ARGS}" | 129 fi |
37 ninja -C ${OUTPUT_DIR} ${GN_STATIC_TARGET_NAMES} | |
38 # Combine the object files together into a single archive and strip debug | |
39 # symbols. | |
40 find ${OUTPUT_DIR}/obj -type f -name "*.o" | | |
41 xargs ld -r -static -S -all_load -arch ${xcode_arch} -o ${OUTPUT_LIB} | |
42 } | |
43 | 130 |
44 # Build all the common architectures. | 131 # Build all architectures. |
45 build_static_webrtc "arm" "armv7" | 132 build_webrtc "arm" ${BUILD_FLAVOR} ${BUILD_TYPE} \ |
46 build_static_webrtc "arm64" "arm64" | 133 ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${CUSTOM_GN_OPTS} |
47 build_static_webrtc "x86" "i386" | 134 build_webrtc "arm64" ${BUILD_FLAVOR} ${BUILD_TYPE} \ |
48 build_static_webrtc "x64" "x86_64" | 135 ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${CUSTOM_GN_OPTS} |
136 build_webrtc "x64" ${BUILD_FLAVOR} ${BUILD_TYPE} \ | |
137 ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${CUSTOM_GN_OPTS} | |
49 | 138 |
50 # Combine the libraries. | 139 # Ignoring x86 except for static libraries for now because of a GN build issue |
51 lipo ${SDK_OUTPUT_DIR}/arm_libs/${SDK_LIB_NAME} \ | 140 # where the generated dynamic framework has the wrong architectures. |
52 ${SDK_OUTPUT_DIR}/arm64_libs/${SDK_LIB_NAME} \ | 141 |
53 ${SDK_OUTPUT_DIR}/x86_libs/${SDK_LIB_NAME} \ | 142 # Create FAT archive. |
54 ${SDK_OUTPUT_DIR}/x64_libs/${SDK_LIB_NAME} \ | 143 if [[ ${BUILD_TYPE} = "static_only" ]]; then |
55 -create -output ${SDK_OUTPUT_DIR}/${SDK_LIB_NAME} | 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} | |
155 elif [[ ${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 rm ${SDK_OUTPUT_DIR}/WebRTC.framework/*.mobileprovision | |
174 | |
175 # Merge the dSYM slices. | |
176 DSYM_PATH="WebRTC.dSYM/Contents/Resources/DWARF/WebRTC" | |
177 cp -R ${ARM64_LIB_PATH}/WebRTC.dSYM ${SDK_OUTPUT_DIR} | |
178 rm ${SDK_OUTPUT_DIR}/${DSYM_PATH} | |
179 echo "Merging dSYM slices." | |
180 lipo ${ARM_LIB_PATH}/${DSYM_PATH} \ | |
181 ${ARM64_LIB_PATH}/${DSYM_PATH} \ | |
182 ${X64_LIB_PATH}/${DSYM_PATH} \ | |
183 -create -output ${SDK_OUTPUT_DIR}/${DSYM_PATH} | |
184 | |
185 # Modify the version number. | |
186 INFOPLIST_PATH=${SDK_OUTPUT_DIR}/WebRTC.framework/Info.plist | |
187 VERSION_NUMBER="${WEBRTC_REVISION}.0" | |
188 echo "Substituting revision number: ${VERSION_NUMBER}" | |
189 PlistBuddy -c "Set :CFBundleVersion ${VERSION_NUMBER}" ${INFOPLIST_PATH} | |
190 plutil -convert binary1 ${INFOPLIST_PATH} | |
191 else | |
192 echo "BUILD_TYPE ${BUILD_TYPE} not supported." | |
193 exit 1 | |
194 fi | |
56 | 195 |
57 echo "Done." | 196 echo "Done." |
OLD | NEW |