| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 3 # Copyright (c) 2017 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 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 28 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 29 WEBRTC_BASE_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..')) | 29 WEBRTC_BASE_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..')) |
| 30 SDK_OUTPUT_DIR = os.path.join(WEBRTC_BASE_DIR, 'out_ios_libs') | 30 SDK_OUTPUT_DIR = os.path.join(WEBRTC_BASE_DIR, 'out_ios_libs') |
| 31 SDK_LIB_NAME = 'librtc_sdk_objc.a' | 31 SDK_LIB_NAME = 'librtc_sdk_objc.a' |
| 32 SDK_FRAMEWORK_NAME = 'WebRTC.framework' | 32 SDK_FRAMEWORK_NAME = 'WebRTC.framework' |
| 33 | 33 |
| 34 ENABLED_ARCHITECTURES = ['arm', 'arm64', 'x64'] | 34 ENABLED_ARCHITECTURES = ['arm', 'arm64', 'x64'] |
| 35 IOS_DEPLOYMENT_TARGET = '8.0' | 35 IOS_DEPLOYMENT_TARGET = '8.0' |
| 36 LIBVPX_BUILD_VP9 = False | 36 LIBVPX_BUILD_VP9 = False |
| 37 CUSTOM_GN_OPTS = [] # example: ['some_option=foo bar', 'other_option=true'] | |
| 38 | 37 |
| 39 | 38 |
| 40 def _ParseArgs(): | 39 def _ParseArgs(): |
| 41 parser = argparse.ArgumentParser(description=__doc__) | 40 parser = argparse.ArgumentParser(description=__doc__) |
| 42 parser.add_argument('-b', '--build_type', default='framework', | 41 parser.add_argument('-b', '--build_type', default='framework', |
| 43 choices=['framework', 'static_only'], | 42 choices=['framework', 'static_only'], |
| 44 help='The build type. Can be "framework" or "static_only". ' | 43 help='The build type. Can be "framework" or "static_only". ' |
| 45 'Defaults to "framework".') | 44 'Defaults to "framework".') |
| 46 parser.add_argument('--build_config', default='release', | 45 parser.add_argument('--build_config', default='release', |
| 47 choices=['debug', 'release'], | 46 choices=['debug', 'release'], |
| 48 help='The build config. Can be "debug" or "release". ' | 47 help='The build config. Can be "debug" or "release". ' |
| 49 'Defaults to "release".') | 48 'Defaults to "release".') |
| 50 parser.add_argument('-c', '--clean', action='store_true', default=False, | 49 parser.add_argument('-c', '--clean', action='store_true', default=False, |
| 51 help='Removes the previously generated build output, if any.') | 50 help='Removes the previously generated build output, if any.') |
| 52 parser.add_argument('-o', '--output-dir', default=SDK_OUTPUT_DIR, | 51 parser.add_argument('-o', '--output-dir', default=SDK_OUTPUT_DIR, |
| 53 help='Specifies a directory to output the build artifacts to. ' | 52 help='Specifies a directory to output the build artifacts to. ' |
| 54 'If specified together with -c, deletes the dir.') | 53 'If specified together with -c, deletes the dir.') |
| 55 parser.add_argument('-r', '--revision', type=int, default=0, | 54 parser.add_argument('-r', '--revision', type=int, default=0, |
| 56 help='Specifies a revision number to embed if building the framework.') | 55 help='Specifies a revision number to embed if building the framework.') |
| 57 parser.add_argument('-e', '--bitcode', action='store_true', default=False, | 56 parser.add_argument('-e', '--bitcode', action='store_true', default=False, |
| 58 help='Compile with bitcode.') | 57 help='Compile with bitcode.') |
| 59 parser.add_argument('--verbose', action='store_true', default=False, | 58 parser.add_argument('--verbose', action='store_true', default=False, |
| 60 help='Debug logging.') | 59 help='Debug logging.') |
| 60 parser.add_argument('--use-goma', action='store_true', default=False, |
| 61 help='Use goma to build.') |
| 62 parser.add_argument('--extra-gn-args', default=[], nargs='*', |
| 63 help='Additional GN args to be used during Ninja generation.') |
| 64 |
| 61 return parser.parse_args() | 65 return parser.parse_args() |
| 62 | 66 |
| 63 | 67 |
| 64 def _RunCommand(cmd): | 68 def _RunCommand(cmd): |
| 65 logging.debug('Running: %r', cmd) | 69 logging.debug('Running: %r', cmd) |
| 66 subprocess.check_call(cmd) | 70 subprocess.check_call(cmd) |
| 67 | 71 |
| 68 | 72 |
| 69 def _CleanArtifacts(output_dir): | 73 def _CleanArtifacts(output_dir): |
| 70 if os.path.isdir(output_dir): | 74 if os.path.isdir(output_dir): |
| 71 logging.info('Deleting %s', output_dir) | 75 logging.info('Deleting %s', output_dir) |
| 72 shutil.rmtree(output_dir) | 76 shutil.rmtree(output_dir) |
| 73 | 77 |
| 74 | 78 |
| 75 def BuildWebRTC(output_dir, target_arch, flavor, build_type, | 79 def BuildWebRTC(output_dir, target_arch, flavor, build_type, |
| 76 ios_deployment_target, libvpx_build_vp9, use_bitcode, | 80 ios_deployment_target, libvpx_build_vp9, use_bitcode, |
| 77 custom_gn_options=()): | 81 use_goma, extra_gn_args): |
| 78 output_dir = os.path.join(output_dir, target_arch + '_libs') | 82 output_dir = os.path.join(output_dir, target_arch + '_libs') |
| 79 gn_args = ['target_os="ios"', 'ios_enable_code_signing=false', | 83 gn_args = ['target_os="ios"', 'ios_enable_code_signing=false', |
| 80 'use_xcode_clang=true', 'is_component_build=false'] | 84 'use_xcode_clang=true', 'is_component_build=false'] |
| 81 | 85 |
| 82 # Add flavor option. | 86 # Add flavor option. |
| 83 if flavor == 'debug': | 87 if flavor == 'debug': |
| 84 gn_args.append('is_debug=true') | 88 gn_args.append('is_debug=true') |
| 85 elif flavor == 'release': | 89 elif flavor == 'release': |
| 86 gn_args.append('is_debug=false') | 90 gn_args.append('is_debug=false') |
| 87 else: | 91 else: |
| 88 raise ValueError('Unexpected flavor type: %s' % flavor) | 92 raise ValueError('Unexpected flavor type: %s' % flavor) |
| 89 | 93 |
| 90 gn_args.append('target_cpu="%s"' % target_arch) | 94 gn_args.append('target_cpu="%s"' % target_arch) |
| 91 | 95 |
| 92 gn_args.append('ios_deployment_target="%s"' % ios_deployment_target) | 96 gn_args.append('ios_deployment_target="%s"' % ios_deployment_target) |
| 93 | 97 |
| 94 gn_args.append('rtc_libvpx_build_vp9=' + | 98 gn_args.append('rtc_libvpx_build_vp9=' + |
| 95 ('true' if libvpx_build_vp9 else 'false')) | 99 ('true' if libvpx_build_vp9 else 'false')) |
| 96 | 100 |
| 97 gn_args.append('enable_ios_bitcode=' + | 101 gn_args.append('enable_ios_bitcode=' + |
| 98 ('true' if use_bitcode else 'false')) | 102 ('true' if use_bitcode else 'false')) |
| 99 | 103 gn_args.append('use_goma=' + ('true' if use_goma else 'false')) |
| 100 gn_args.extend(custom_gn_options) | |
| 101 | 104 |
| 102 # Generate static or dynamic. | 105 # Generate static or dynamic. |
| 103 if build_type == 'static_only': | 106 if build_type == 'static_only': |
| 104 gn_target_name = 'rtc_sdk_objc' | 107 gn_target_name = 'rtc_sdk_objc' |
| 105 elif build_type == 'framework': | 108 elif build_type == 'framework': |
| 106 gn_target_name = 'rtc_sdk_framework_objc' | 109 gn_target_name = 'rtc_sdk_framework_objc' |
| 107 gn_args.append('enable_dsyms=true') | 110 gn_args.append('enable_dsyms=true') |
| 108 gn_args.append('enable_stripping=true') | 111 gn_args.append('enable_stripping=true') |
| 109 else: | 112 else: |
| 110 raise ValueError('Build type "%s" is not supported.' % build_type) | 113 raise ValueError('Build type "%s" is not supported.' % build_type) |
| 111 | 114 |
| 112 logging.info('Building WebRTC with args: %s', ' '.join(gn_args)) | 115 logging.info('Building WebRTC with args: %s', ' '.join(gn_args)) |
| 113 cmd = ['gn', 'gen', output_dir, | 116 cmd = ['gn', 'gen', output_dir, |
| 114 '--args=' + ' '.join(gn_args)] | 117 '--args=' + ' '.join(gn_args + extra_gn_args)] |
| 115 _RunCommand(cmd) | 118 _RunCommand(cmd) |
| 116 logging.info('Building target: %s', gn_target_name) | 119 logging.info('Building target: %s', gn_target_name) |
| 117 cmd = ['ninja', '-C', output_dir, gn_target_name] | 120 cmd = ['ninja', '-C', output_dir, gn_target_name] |
| 118 _RunCommand(cmd) | 121 _RunCommand(cmd) |
| 119 | 122 |
| 120 # Strip debug symbols to reduce size. | 123 # Strip debug symbols to reduce size. |
| 121 if build_type == 'static_only': | 124 if build_type == 'static_only': |
| 122 gn_target_path = os.path.join(output_dir, 'obj', 'webrtc', 'sdk', | 125 gn_target_path = os.path.join(output_dir, 'obj', 'webrtc', 'sdk', |
| 123 'lib%s.a' % gn_target_name) | 126 'lib%s.a' % gn_target_name) |
| 124 cmd = ['strip', '-S', gn_target_path, '-o', | 127 cmd = ['strip', '-S', gn_target_path, '-o', |
| 125 os.path.join(output_dir, 'lib%s.a' % gn_target_name)] | 128 os.path.join(output_dir, 'lib%s.a' % gn_target_name)] |
| 126 _RunCommand(cmd) | 129 _RunCommand(cmd) |
| 127 | 130 |
| 128 | 131 |
| 129 def main(): | 132 def main(): |
| 130 args = _ParseArgs() | 133 args = _ParseArgs() |
| 131 | 134 |
| 132 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) | 135 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) |
| 133 | 136 |
| 134 if args.clean: | 137 if args.clean: |
| 135 _CleanArtifacts(args.output_dir) | 138 _CleanArtifacts(args.output_dir) |
| 136 return 0 | 139 return 0 |
| 137 | 140 |
| 138 # Build all architectures. | 141 # Build all architectures. |
| 139 for arch in ENABLED_ARCHITECTURES: | 142 for arch in ENABLED_ARCHITECTURES: |
| 140 BuildWebRTC(args.output_dir, arch, args.build_config, args.build_type, | 143 BuildWebRTC(args.output_dir, arch, args.build_config, args.build_type, |
| 141 IOS_DEPLOYMENT_TARGET, LIBVPX_BUILD_VP9, args.bitcode, | 144 IOS_DEPLOYMENT_TARGET, LIBVPX_BUILD_VP9, args.bitcode, |
| 142 CUSTOM_GN_OPTS) | 145 args.use_goma, args.extra_gn_args) |
| 143 | 146 |
| 144 # Ignoring x86 except for static libraries for now because of a GN build issue | 147 # Ignoring x86 except for static libraries for now because of a GN build issue |
| 145 # where the generated dynamic framework has the wrong architectures. | 148 # where the generated dynamic framework has the wrong architectures. |
| 146 | 149 |
| 147 # Create FAT archive. | 150 # Create FAT archive. |
| 148 if args.build_type == 'static_only': | 151 if args.build_type == 'static_only': |
| 149 BuildWebRTC(args.output_dir, 'x86', args.build_config, args.build_type, | 152 BuildWebRTC(args.output_dir, 'x86', args.build_config, args.build_type, |
| 150 IOS_DEPLOYMENT_TARGET, LIBVPX_BUILD_VP9, args.bitcode, | 153 IOS_DEPLOYMENT_TARGET, LIBVPX_BUILD_VP9, args.bitcode, |
| 151 CUSTOM_GN_OPTS) | 154 args.use_goma, args.extra_gn_args) |
| 152 | 155 |
| 153 arm_lib_path = os.path.join(args.output_dir, 'arm_libs', SDK_LIB_NAME) | 156 arm_lib_path = os.path.join(args.output_dir, 'arm_libs', SDK_LIB_NAME) |
| 154 arm64_lib_path = os.path.join(args.output_dir, 'arm64_libs', SDK_LIB_NAME) | 157 arm64_lib_path = os.path.join(args.output_dir, 'arm64_libs', SDK_LIB_NAME) |
| 155 x64_lib_path = os.path.join(args.output_dir, 'x64_libs', SDK_LIB_NAME) | 158 x64_lib_path = os.path.join(args.output_dir, 'x64_libs', SDK_LIB_NAME) |
| 156 x86_lib_path = os.path.join(args.output_dir, 'x86_libs', SDK_LIB_NAME) | 159 x86_lib_path = os.path.join(args.output_dir, 'x86_libs', SDK_LIB_NAME) |
| 157 | 160 |
| 158 # Combine the slices. | 161 # Combine the slices. |
| 159 cmd = ['lipo', arm_lib_path, arm64_lib_path, x64_lib_path, x86_lib_path, | 162 cmd = ['lipo', arm_lib_path, arm64_lib_path, x64_lib_path, x86_lib_path, |
| 160 '-create', '-output', os.path.join(args.output_dir, SDK_LIB_NAME)] | 163 '-create', '-output', os.path.join(args.output_dir, SDK_LIB_NAME)] |
| 161 _RunCommand(cmd) | 164 _RunCommand(cmd) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 'Set :CFBundleVersion ' + version_number, infoplist_path] | 215 'Set :CFBundleVersion ' + version_number, infoplist_path] |
| 213 _RunCommand(cmd) | 216 _RunCommand(cmd) |
| 214 _RunCommand(['plutil', '-convert', 'binary1', infoplist_path]) | 217 _RunCommand(['plutil', '-convert', 'binary1', infoplist_path]) |
| 215 | 218 |
| 216 logging.info('Done.') | 219 logging.info('Done.') |
| 217 return 0 | 220 return 0 |
| 218 | 221 |
| 219 | 222 |
| 220 if __name__ == '__main__': | 223 if __name__ == '__main__': |
| 221 sys.exit(main()) | 224 sys.exit(main()) |
| OLD | NEW |