summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/toolchain/apple
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/build/toolchain/apple')
-rw-r--r--third_party/libwebrtc/build/toolchain/apple/BUILD.gn22
-rw-r--r--third_party/libwebrtc/build/toolchain/apple/OWNERS1
-rw-r--r--third_party/libwebrtc/build/toolchain/apple/filter_libtool.py52
-rw-r--r--third_party/libwebrtc/build/toolchain/apple/get_tool_mtime.py19
-rwxr-xr-xthird_party/libwebrtc/build/toolchain/apple/linker_driver.py306
-rw-r--r--third_party/libwebrtc/build/toolchain/apple/toolchain.gni611
6 files changed, 1011 insertions, 0 deletions
diff --git a/third_party/libwebrtc/build/toolchain/apple/BUILD.gn b/third_party/libwebrtc/build/toolchain/apple/BUILD.gn
new file mode 100644
index 0000000000..6f074fd2d8
--- /dev/null
+++ b/third_party/libwebrtc/build/toolchain/apple/BUILD.gn
@@ -0,0 +1,22 @@
+# Copyright 2021 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/toolchain/concurrent_links.gni")
+
+declare_args() {
+ # Reduce the number of tasks using the copy_bundle_data and compile_xcassets
+ # tools as they can cause lots of I/O contention when invoking ninja with a
+ # large number of parallel jobs (e.g. when using distributed build like goma).
+ bundle_pool_depth = -1
+}
+
+if (current_toolchain == default_toolchain) {
+ pool("bundle_pool") {
+ if (bundle_pool_depth == -1) {
+ depth = concurrent_links
+ } else {
+ depth = bundle_pool_depth
+ }
+ }
+}
diff --git a/third_party/libwebrtc/build/toolchain/apple/OWNERS b/third_party/libwebrtc/build/toolchain/apple/OWNERS
new file mode 100644
index 0000000000..6f3324f07c
--- /dev/null
+++ b/third_party/libwebrtc/build/toolchain/apple/OWNERS
@@ -0,0 +1 @@
+file://build/apple/OWNERS
diff --git a/third_party/libwebrtc/build/toolchain/apple/filter_libtool.py b/third_party/libwebrtc/build/toolchain/apple/filter_libtool.py
new file mode 100644
index 0000000000..44c1c4400d
--- /dev/null
+++ b/third_party/libwebrtc/build/toolchain/apple/filter_libtool.py
@@ -0,0 +1,52 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from __future__ import print_function
+
+import os
+import re
+import subprocess
+import sys
+
+# This script executes libool and filters out logspam lines like:
+# '/path/to/libtool: file: foo.o has no symbols'
+
+SUPPRESSED_PATTERNS = [
+ re.compile(v) for v in [
+ r'^.*libtool: (?:for architecture: \S* )?file: .* has no symbols$',
+ # Xcode 11 spelling of the "empty archive" warning.
+ # TODO(thakis): Remove once we require Xcode 12.
+ r'^.*libtool: warning for library: .* the table of contents is empty ' \
+ r'\(no object file members in the library define global symbols\)$',
+ # Xcode 12 spelling of the "empty archive" warning.
+ r'^warning: .*libtool: archive library: .* ' \
+ r'the table of contents is empty ',
+ r'\(no object file members in the library define global symbols\)$',
+ r'^.*libtool: warning same member name \(\S*\) in output file used ' \
+ r'for input files: \S* and: \S* \(due to use of basename, ' \
+ r'truncation, blank padding or duplicate input files\)$',
+ ]
+]
+
+
+def ShouldSuppressLine(line):
+ """Returns whether the line should be filtered out."""
+ for pattern in SUPPRESSED_PATTERNS:
+ if pattern.match(line):
+ return True
+ return False
+
+
+def Main(cmd_list):
+ env = os.environ.copy()
+ libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env)
+ _, err = libtoolout.communicate()
+ for line in err.decode('UTF-8').splitlines():
+ if not ShouldSuppressLine(line):
+ print(line, file=sys.stderr)
+ return libtoolout.returncode
+
+
+if __name__ == '__main__':
+ sys.exit(Main(sys.argv[1:]))
diff --git a/third_party/libwebrtc/build/toolchain/apple/get_tool_mtime.py b/third_party/libwebrtc/build/toolchain/apple/get_tool_mtime.py
new file mode 100644
index 0000000000..ff0254c635
--- /dev/null
+++ b/third_party/libwebrtc/build/toolchain/apple/get_tool_mtime.py
@@ -0,0 +1,19 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from __future__ import print_function
+
+import os
+import sys
+
+# Usage: python get_tool_mtime.py path/to/file1.py path/to/file2.py
+#
+# Prints a GN scope with the variable name being the basename sans-extension
+# and the value being the file modification time. A variable is emitted for
+# each file argument on the command line.
+
+if __name__ == '__main__':
+ for f in sys.argv[1:]:
+ variable = os.path.splitext(os.path.basename(f))[0]
+ print('%s = %d' % (variable, os.path.getmtime(f)))
diff --git a/third_party/libwebrtc/build/toolchain/apple/linker_driver.py b/third_party/libwebrtc/build/toolchain/apple/linker_driver.py
new file mode 100755
index 0000000000..c21e18a0fb
--- /dev/null
+++ b/third_party/libwebrtc/build/toolchain/apple/linker_driver.py
@@ -0,0 +1,306 @@
+#!/usr/bin/env python
+
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import os.path
+import shutil
+import subprocess
+import sys
+
+# On mac, the values of these globals are modified when parsing -Wcrl, flags. On
+# ios, the script uses the defaults.
+DSYMUTIL_INVOKE = ['xcrun', 'dsymutil']
+STRIP_INVOKE = ['xcrun', 'strip']
+
+# Setting this flag will emit a deterministic binary by stripping dates from the
+# N_OSO field.
+DETERMINISTIC_FLAG = '--deterministic'
+
+# The linker_driver.py is responsible for forwarding a linker invocation to
+# the compiler driver, while processing special arguments itself.
+#
+# Usage: linker_driver.py clang++ main.o -L. -llib -o prog -Wcrl,dsym,out
+#
+# On Mac, the logical step of linking is handled by three discrete tools to
+# perform the image link, debug info link, and strip. The linker_driver.py
+# combines these three steps into a single tool.
+#
+# The command passed to the linker_driver.py should be the compiler driver
+# invocation for the linker. It is first invoked unaltered (except for the
+# removal of the special driver arguments, described below). Then the driver
+# performs additional actions, based on these arguments:
+#
+# -Wcrl,dsym,<dsym_path_prefix>
+# After invoking the linker, this will run `dsymutil` on the linker's
+# output, producing a dSYM bundle, stored at dsym_path_prefix. As an
+# example, if the linker driver were invoked with:
+# "... -o out/gn/obj/foo/libbar.dylib ... -Wcrl,dsym,out/gn ..."
+# The resulting dSYM would be out/gn/libbar.dylib.dSYM/.
+#
+# -Wcrl,dsymutilpath,<dsymutil_path>
+# Sets the path to the dsymutil to run with -Wcrl,dsym, in which case
+# `xcrun` is not used to invoke it.
+#
+# -Wcrl,unstripped,<unstripped_path_prefix>
+# After invoking the linker, and before strip, this will save a copy of
+# the unstripped linker output in the directory unstripped_path_prefix.
+#
+# -Wcrl,strip,<strip_arguments>
+# After invoking the linker, and optionally dsymutil, this will run
+# the strip command on the linker's output. strip_arguments are
+# comma-separated arguments to be passed to the strip command.
+#
+# -Wcrl,strippath,<strip_path>
+# Sets the path to the strip to run with -Wcrl,strip, in which case
+# `xcrun` is not used to invoke it.
+
+
+def Main(args):
+ """Main function for the linker driver. Separates out the arguments for
+ the main compiler driver and the linker driver, then invokes all the
+ required tools.
+
+ Args:
+ args: list of string, Arguments to the script.
+ """
+
+ if len(args) < 2:
+ raise RuntimeError("Usage: linker_driver.py [linker-invocation]")
+
+ # Collect arguments to the linker driver (this script) and remove them from
+ # the arguments being passed to the compiler driver.
+ linker_driver_actions = {}
+ compiler_driver_args = []
+ deterministic = False
+ for arg in args[1:]:
+ if arg.startswith(_LINKER_DRIVER_ARG_PREFIX):
+ # Convert driver actions into a map of name => lambda to invoke.
+ driver_action = ProcessLinkerDriverArg(arg)
+ assert driver_action[0] not in linker_driver_actions
+ linker_driver_actions[driver_action[0]] = driver_action[1]
+ elif arg == DETERMINISTIC_FLAG:
+ deterministic = True
+ else:
+ compiler_driver_args.append(arg)
+
+ linker_driver_outputs = [_FindLinkerOutput(compiler_driver_args)]
+
+ try:
+ # Zero the mtime in OSO fields for deterministic builds.
+ # https://crbug.com/330262.
+ env = os.environ.copy()
+ if deterministic:
+ env['ZERO_AR_DATE'] = '1'
+ # Run the linker by invoking the compiler driver.
+ subprocess.check_call(compiler_driver_args, env=env)
+
+ # Run the linker driver actions, in the order specified by the actions list.
+ for action in _LINKER_DRIVER_ACTIONS:
+ name = action[0]
+ if name in linker_driver_actions:
+ linker_driver_outputs += linker_driver_actions[name](args)
+ except:
+ # If a linker driver action failed, remove all the outputs to make the
+ # build step atomic.
+ map(_RemovePath, linker_driver_outputs)
+
+ # Re-report the original failure.
+ raise
+
+
+def ProcessLinkerDriverArg(arg):
+ """Processes a linker driver argument and returns a tuple containing the
+ name and unary lambda to invoke for that linker driver action.
+
+ Args:
+ arg: string, The linker driver argument.
+
+ Returns:
+ A 2-tuple:
+ 0: The driver action name, as in _LINKER_DRIVER_ACTIONS.
+ 1: An 1-ary lambda that takes the full list of arguments passed to
+ Main(). The lambda should call the linker driver action that
+ corresponds to the argument and return a list of outputs from the
+ action.
+ """
+ if not arg.startswith(_LINKER_DRIVER_ARG_PREFIX):
+ raise ValueError('%s is not a linker driver argument' % (arg, ))
+
+ sub_arg = arg[len(_LINKER_DRIVER_ARG_PREFIX):]
+
+ for driver_action in _LINKER_DRIVER_ACTIONS:
+ (name, action) = driver_action
+ if sub_arg.startswith(name):
+ return (name, lambda full_args: action(sub_arg[len(name):], full_args))
+
+ raise ValueError('Unknown linker driver argument: %s' % (arg, ))
+
+
+def RunDsymUtil(dsym_path_prefix, full_args):
+ """Linker driver action for -Wcrl,dsym,<dsym-path-prefix>. Invokes dsymutil
+ on the linker's output and produces a dsym file at |dsym_file| path.
+
+ Args:
+ dsym_path_prefix: string, The path at which the dsymutil output should be
+ located.
+ full_args: list of string, Full argument list for the linker driver.
+
+ Returns:
+ list of string, Build step outputs.
+ """
+ if not len(dsym_path_prefix):
+ raise ValueError('Unspecified dSYM output file')
+
+ linker_out = _FindLinkerOutput(full_args)
+ base = os.path.basename(linker_out)
+ dsym_out = os.path.join(dsym_path_prefix, base + '.dSYM')
+
+ # Remove old dSYMs before invoking dsymutil.
+ _RemovePath(dsym_out)
+
+ tools_paths = _FindToolsPaths(full_args)
+ if os.environ.get('PATH'):
+ tools_paths.append(os.environ['PATH'])
+ dsymutil_env = os.environ.copy()
+ dsymutil_env['PATH'] = ':'.join(tools_paths)
+ subprocess.check_call(DSYMUTIL_INVOKE + ['-o', dsym_out, linker_out],
+ env=dsymutil_env)
+ return [dsym_out]
+
+
+def SetDsymutilPath(dsymutil_path, full_args):
+ """Linker driver action for -Wcrl,dsymutilpath,<dsymutil_path>.
+
+ Sets the invocation command for dsymutil, which allows the caller to specify
+ an alternate dsymutil. This action is always processed before the RunDsymUtil
+ action.
+
+ Args:
+ dsymutil_path: string, The path to the dsymutil binary to run
+ full_args: list of string, Full argument list for the linker driver.
+
+ Returns:
+ No output - this step is run purely for its side-effect.
+ """
+ global DSYMUTIL_INVOKE
+ DSYMUTIL_INVOKE = [dsymutil_path]
+ return []
+
+
+def RunSaveUnstripped(unstripped_path_prefix, full_args):
+ """Linker driver action for -Wcrl,unstripped,<unstripped_path_prefix>. Copies
+ the linker output to |unstripped_path_prefix| before stripping.
+
+ Args:
+ unstripped_path_prefix: string, The path at which the unstripped output
+ should be located.
+ full_args: list of string, Full argument list for the linker driver.
+
+ Returns:
+ list of string, Build step outputs.
+ """
+ if not len(unstripped_path_prefix):
+ raise ValueError('Unspecified unstripped output file')
+
+ linker_out = _FindLinkerOutput(full_args)
+ base = os.path.basename(linker_out)
+ unstripped_out = os.path.join(unstripped_path_prefix, base + '.unstripped')
+
+ shutil.copyfile(linker_out, unstripped_out)
+ return [unstripped_out]
+
+
+def RunStrip(strip_args_string, full_args):
+ """Linker driver action for -Wcrl,strip,<strip_arguments>.
+
+ Args:
+ strip_args_string: string, Comma-separated arguments for `strip`.
+ full_args: list of string, Full arguments for the linker driver.
+
+ Returns:
+ list of string, Build step outputs.
+ """
+ strip_command = list(STRIP_INVOKE)
+ if len(strip_args_string) > 0:
+ strip_command += strip_args_string.split(',')
+ strip_command.append(_FindLinkerOutput(full_args))
+ subprocess.check_call(strip_command)
+ return []
+
+
+def SetStripPath(strip_path, full_args):
+ """Linker driver action for -Wcrl,strippath,<strip_path>.
+
+ Sets the invocation command for strip, which allows the caller to specify
+ an alternate strip. This action is always processed before the RunStrip
+ action.
+
+ Args:
+ strip_path: string, The path to the strip binary to run
+ full_args: list of string, Full argument list for the linker driver.
+
+ Returns:
+ No output - this step is run purely for its side-effect.
+ """
+ global STRIP_INVOKE
+ STRIP_INVOKE = [strip_path]
+ return []
+
+
+def _FindLinkerOutput(full_args):
+ """Finds the output of the linker by looking for the output flag in its
+ argument list. As this is a required linker argument, raises an error if it
+ cannot be found.
+ """
+ # The linker_driver.py script may be used to wrap either the compiler linker
+ # (uses -o to configure the output) or lipo (uses -output to configure the
+ # output). Since wrapping the compiler linker is the most likely possibility
+ # use try/except and fallback to checking for -output if -o is not found.
+ try:
+ output_flag_index = full_args.index('-o')
+ except ValueError:
+ output_flag_index = full_args.index('-output')
+ return full_args[output_flag_index + 1]
+
+
+def _FindToolsPaths(full_args):
+ """Finds all paths where the script should look for additional tools."""
+ paths = []
+ for idx, arg in enumerate(full_args):
+ if arg in ['-B', '--prefix']:
+ paths.append(full_args[idx + 1])
+ elif arg.startswith('-B'):
+ paths.append(arg[2:])
+ elif arg.startswith('--prefix='):
+ paths.append(arg[9:])
+ return paths
+
+
+def _RemovePath(path):
+ """Removes the file or directory at |path| if it exists."""
+ if os.path.exists(path):
+ if os.path.isdir(path):
+ shutil.rmtree(path)
+ else:
+ os.unlink(path)
+
+
+_LINKER_DRIVER_ARG_PREFIX = '-Wcrl,'
+"""List of linker driver actions. The sort order of this list affects the
+order in which the actions are invoked. The first item in the tuple is the
+argument's -Wcrl,<sub_argument> and the second is the function to invoke.
+"""
+_LINKER_DRIVER_ACTIONS = [
+ ('dsymutilpath,', SetDsymutilPath),
+ ('dsym,', RunDsymUtil),
+ ('unstripped,', RunSaveUnstripped),
+ ('strippath,', SetStripPath),
+ ('strip,', RunStrip),
+]
+
+if __name__ == '__main__':
+ Main(sys.argv)
+ sys.exit(0)
diff --git a/third_party/libwebrtc/build/toolchain/apple/toolchain.gni b/third_party/libwebrtc/build/toolchain/apple/toolchain.gni
new file mode 100644
index 0000000000..f914d8d400
--- /dev/null
+++ b/third_party/libwebrtc/build/toolchain/apple/toolchain.gni
@@ -0,0 +1,611 @@
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# TODO(brettw) Use "gcc_toolchain.gni" like the Linux toolchains. This requires
+# some enhancements since the commands on Mac are slightly different than on
+# Linux.
+
+import("//build/config/apple/symbols.gni")
+import("//build/config/clang/clang.gni")
+import("//build/config/compiler/compiler.gni")
+import("//build/config/coverage/coverage.gni")
+import("//build/config/rust.gni")
+import("//build/toolchain/cc_wrapper.gni")
+import("//build/toolchain/goma.gni")
+import("//build/toolchain/rbe.gni")
+import("//build/toolchain/toolchain.gni")
+
+assert((target_os == "ios" && host_os == "mac") || host_os != "win")
+
+declare_args() {
+ # This controls whether whole module optimization is enabled when building
+ # Swift modules. If enabled, the compiler will compile the module as one
+ # unit, generating just one single object file. Otherwise, it will generate
+ # one object file per .swift file. If unspecified, will default to "true"
+ # for official builds, and "false" for all other builds.
+ swift_whole_module_optimization = -1
+}
+
+if (swift_whole_module_optimization == -1) {
+ swift_whole_module_optimization = is_official_build
+}
+
+# When implementing tools using Python scripts, a TOOL_VERSION=N env
+# variable is placed in front of the command. The N should be incremented
+# whenever the script is changed, so that the build system rebuilds all
+# edges that utilize the script. Ideally this should be changed to use
+# proper input-dirty checking, but that could be expensive. Instead, use a
+# script to get the tool scripts' modification time to use as the version.
+# This won't cause a re-generation of GN files when the tool script changes
+# but it will cause edges to be marked as dirty if the ninja files are
+# regenerated. See https://crbug.com/619083 for details. A proper fix
+# would be to have inputs to tools (https://crbug.com/621119).
+tool_versions =
+ exec_script("get_tool_mtime.py",
+ rebase_path([
+ "//build/toolchain/apple/filter_libtool.py",
+ "//build/toolchain/apple/linker_driver.py",
+ "//build/toolchain/ios/compile_xcassets.py",
+ "//build/toolchain/ios/swiftc.py",
+ ],
+ root_build_dir),
+ "trim scope")
+
+# Shared toolchain definition. Invocations should set current_os to set the
+# build args in this definition.
+template("apple_toolchain") {
+ toolchain(target_name) {
+ # When invoking this toolchain not as the default one, these args will be
+ # passed to the build. They are ignored when this is the default toolchain.
+ assert(defined(invoker.toolchain_args),
+ "Toolchains must declare toolchain_args")
+ toolchain_args = {
+ # Populate toolchain args from the invoker.
+ forward_variables_from(invoker.toolchain_args, "*")
+
+ # The host toolchain value computed by the default toolchain's setup
+ # needs to be passed through unchanged to all secondary toolchains to
+ # ensure that it's always the same, regardless of the values that may be
+ # set on those toolchains.
+ host_toolchain = host_toolchain
+ }
+
+ # When the invoker has explicitly overridden use_goma or cc_wrapper in the
+ # toolchain args, use those values, otherwise default to the global one.
+ # This works because the only reasonable override that toolchains might
+ # supply for these values are to force-disable them.
+ if (defined(toolchain_args.use_remoteexec)) {
+ toolchain_uses_remoteexec = toolchain_args.use_remoteexec
+ } else {
+ toolchain_uses_remoteexec = use_remoteexec
+ }
+ if (defined(toolchain_args.use_goma)) {
+ toolchain_uses_goma = toolchain_args.use_goma
+ } else {
+ toolchain_uses_goma = use_goma
+ }
+ if (defined(toolchain_args.cc_wrapper)) {
+ toolchain_cc_wrapper = toolchain_args.cc_wrapper
+ } else {
+ toolchain_cc_wrapper = cc_wrapper
+ }
+ assert(!(toolchain_uses_remoteexec && toolchain_uses_goma),
+ "Goma and re-client can't be used together.")
+ assert(!(toolchain_cc_wrapper != "" && toolchain_uses_remoteexec),
+ "re-client and cc_wrapper can't be used together.")
+ assert(!(toolchain_cc_wrapper != "" && toolchain_uses_goma),
+ "Goma and cc_wrapper can't be used together.")
+
+ if (defined(toolchain_args.use_lld)) {
+ toolchain_uses_lld = toolchain_args.use_lld
+ } else {
+ toolchain_uses_lld = use_lld
+ }
+ if (defined(toolchain_args.use_xcode_clang)) {
+ toolchain_uses_xcode_clang = toolchain_args.use_xcode_clang
+ } else {
+ toolchain_uses_xcode_clang = use_xcode_clang
+ }
+
+ # Supports building with the version of clang shipped with Xcode when
+ # targeting iOS by not respecting clang_base_path.
+ if (toolchain_uses_xcode_clang) {
+ prefix = invoker.bin_path
+ } else {
+ prefix = rebase_path("$clang_base_path/bin/", root_build_dir)
+ }
+
+ _cc = "${prefix}clang"
+ _cxx = "${prefix}clang++"
+
+ swiftmodule_switch = "-Wl,-add_ast_path,"
+
+ # Compute the compiler prefix.
+ if (toolchain_uses_remoteexec) {
+ if (defined(toolchain_args.rbe_cc_cfg_file)) {
+ toolchain_rbe_cc_cfg_file = toolchain_args.rbe_cc_cfg_file
+ } else {
+ toolchain_rbe_cc_cfg_file = rbe_cc_cfg_file
+ }
+
+ # C/C++ (clang) rewrapper prefix to use when use_remoteexec is true.
+ compiler_prefix = "${rbe_bin_dir}/rewrapper -cfg=${toolchain_rbe_cc_cfg_file} -exec_root=${rbe_exec_root} "
+ } else if (toolchain_uses_goma) {
+ assert(toolchain_cc_wrapper == "",
+ "Goma and cc_wrapper can't be used together.")
+ compiler_prefix = "$goma_dir/gomacc "
+ if (use_goma_rust) {
+ rust_compiler_prefix = compiler_prefix
+ }
+ } else if (toolchain_cc_wrapper != "") {
+ compiler_prefix = toolchain_cc_wrapper + " "
+ } else {
+ compiler_prefix = ""
+ }
+
+ cc = compiler_prefix + _cc
+ cxx = compiler_prefix + _cxx
+ ld = _cxx
+
+ # Set the explicit search path for clang++ so it uses the right linker
+ # binary.
+ if (!toolchain_uses_lld) {
+ ld += " -B " + invoker.bin_path
+ }
+
+ if (defined(toolchain_args.coverage_instrumentation_input_file)) {
+ toolchain_coverage_instrumentation_input_file =
+ toolchain_args.coverage_instrumentation_input_file
+ } else {
+ toolchain_coverage_instrumentation_input_file =
+ coverage_instrumentation_input_file
+ }
+ _use_clang_coverage_wrapper =
+ toolchain_coverage_instrumentation_input_file != ""
+ if (_use_clang_coverage_wrapper) {
+ _coverage_wrapper =
+ rebase_path("//build/toolchain/clang_code_coverage_wrapper.py",
+ root_build_dir) + " --files-to-instrument=" +
+ rebase_path(toolchain_coverage_instrumentation_input_file,
+ root_build_dir) + " --target-os=" + target_os
+ cc = "$python_path $_coverage_wrapper ${cc}"
+ cxx = "$python_path $_coverage_wrapper ${cxx}"
+ }
+
+ linker_driver =
+ "TOOL_VERSION=${tool_versions.linker_driver} " +
+ rebase_path("//build/toolchain/apple/linker_driver.py", root_build_dir)
+
+ # Specify an explicit path for the strip binary.
+ _strippath = invoker.bin_path + "strip"
+ linker_driver += " -Wcrl,strippath," + _strippath
+
+ # This makes the linker set timestamps in Mach-O files to 0.
+ linker_driver += " --deterministic"
+
+ # On iOS, the final applications are assembled using lipo (to support fat
+ # builds). The correct flags are passed to the linker_driver.py script
+ # directly during the lipo call. The test is against the target_os because
+ # there is no need to create .dSYMs for targets compiled for the host.
+ if (defined(invoker.strip_with_lipo) && invoker.strip_with_lipo) {
+ _enable_dsyms = false
+ _save_unstripped_output = false
+ } else {
+ _enable_dsyms = enable_dsyms
+ _save_unstripped_output = save_unstripped_output
+ }
+
+ # Make these apply to all tools below.
+ lib_switch = "-l"
+ lib_dir_switch = "-L"
+
+ # Object files go in this directory. Use label_name instead of
+ # target_output_name since labels will generally have no spaces and will be
+ # unique in the directory.
+ object_subdir = "{{target_out_dir}}/{{label_name}}"
+
+ # If dSYMs are enabled, this flag will be added to the link tools.
+ if (_enable_dsyms) {
+ dsym_switch = " -Wcrl,dsym,{{root_out_dir}} "
+ dsym_switch += "-Wcrl,dsymutilpath," +
+ rebase_path("//tools/clang/dsymutil/bin/dsymutil",
+ root_build_dir) + " "
+
+ dsym_output_dir =
+ "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.dSYM"
+ dsym_output = [
+ "$dsym_output_dir/Contents/Info.plist",
+ "$dsym_output_dir/Contents/Resources/DWARF/" +
+ "{{target_output_name}}{{output_extension}}",
+ ]
+ } else {
+ dsym_switch = ""
+ }
+
+ if (_save_unstripped_output) {
+ _unstripped_output = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.unstripped"
+ }
+
+ if (toolchain_has_rust) {
+ if (!defined(rust_compiler_prefix)) {
+ rust_compiler_prefix = ""
+ }
+ rustc = "$rust_compiler_prefix${rust_prefix}rustc"
+
+ # Ideally, we'd add -Clink-args=\"{{ldflags}}\" to each of the Rust
+ # tools below which may link (i.e. rust_bin, rust_cdylib, rust_macro).
+ # However, it seems -fuse-ld=lld causes difficulties.
+
+ tool("rust_staticlib") {
+ rust_outfile = "{{target_out_dir}}/{{crate_name}}.a"
+ depfile = "{{output}}.d"
+ command = "$rustc $rustc_common_args --emit=dep-info=$depfile,link -o $rust_outfile"
+ description = "RUST $rust_outfile"
+ outputs = [ rust_outfile ]
+ }
+
+ tool("rust_rlib") {
+ rust_outfile = "{{target_out_dir}}/lib{{crate_name}}.rlib"
+ depfile = "{{output}}.d"
+ command = "$rustc $rustc_common_args --emit=dep-info=$depfile,link -o $rust_outfile"
+ description = "RUST $rust_outfile"
+ outputs = [ rust_outfile ]
+ }
+
+ if (rustc_can_link) {
+ tool("rust_bin") {
+ rust_outfile = "{{root_out_dir}}/{{crate_name}}"
+ depfile = "{{output}}.d"
+ command = "$rustc $rustc_common_args --emit=dep-info=$depfile,link -o $rust_outfile"
+ description = "RUST $rust_outfile"
+ outputs = [ rust_outfile ]
+ }
+
+ tool("rust_cdylib") {
+ rust_outfile = "{{target_out_dir}}/lib{{crate_name}}.dylib"
+ depfile = "{{output}}.d"
+ command = "$rustc $rustc_common_args --emit=dep-info=$depfile,link -o $rust_outfile"
+ description = "RUST $rust_outfile"
+ outputs = [ rust_outfile ]
+ }
+
+ tool("rust_macro") {
+ rust_outfile = "{{target_out_dir}}/lib{{crate_name}}.dylib"
+ depfile = "{{output}}.d"
+ command = "$rustc $rustc_common_args --emit=dep-info=$depfile,link -o $rust_outfile"
+ description = "RUST $rust_outfile"
+ outputs = [ rust_outfile ]
+ }
+ }
+ }
+
+ tool("cc") {
+ depfile = "{{output}}.d"
+ precompiled_header_type = "gcc"
+ command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
+ depsformat = "gcc"
+ description = "CC {{output}}"
+ outputs = [ "$object_subdir/{{source_name_part}}.o" ]
+ }
+
+ tool("cxx") {
+ depfile = "{{output}}.d"
+ precompiled_header_type = "gcc"
+ command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
+ depsformat = "gcc"
+ description = "CXX {{output}}"
+ outputs = [ "$object_subdir/{{source_name_part}}.o" ]
+ }
+
+ tool("asm") {
+ # For GCC we can just use the C compiler to compile assembly.
+ depfile = "{{output}}.d"
+ command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
+ depsformat = "gcc"
+ description = "ASM {{output}}"
+ outputs = [ "$object_subdir/{{source_name_part}}.o" ]
+ }
+
+ tool("objc") {
+ depfile = "{{output}}.d"
+ precompiled_header_type = "gcc"
+ command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{framework_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
+ depsformat = "gcc"
+ description = "OBJC {{output}}"
+ outputs = [ "$object_subdir/{{source_name_part}}.o" ]
+ }
+
+ tool("objcxx") {
+ depfile = "{{output}}.d"
+ precompiled_header_type = "gcc"
+ command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{framework_dirs}} {{cflags}} {{cflags_objcc}} -c {{source}} -o {{output}}"
+ depsformat = "gcc"
+ description = "OBJCXX {{output}}"
+ outputs = [ "$object_subdir/{{source_name_part}}.o" ]
+ }
+
+ tool("alink") {
+ rspfile = "{{output}}.rsp"
+
+ if (!toolchain_uses_lld) {
+ # Note about -filelist: Apple's linker reads the file list file and
+ # interprets each newline-separated chunk of text as a file name. It
+ # doesn't do the things one would expect from the shell like unescaping
+ # or handling quotes. In contrast, when Ninja finds a file name with
+ # spaces, it single-quotes them in $inputs_newline as it would normally
+ # do for command-line arguments. Thus any source names with spaces, or
+ # label names with spaces (which GN bases the output paths on) will be
+ # corrupted by this process. Don't use spaces for source files or
+ # labels.
+ rspfile_content = "{{inputs_newline}}"
+
+ script = rebase_path("//build/toolchain/apple/filter_libtool.py",
+ root_build_dir)
+
+ # Specify explicit path for libtool.
+ libtool = invoker.bin_path + "libtool"
+ command = "rm -f {{output}} && TOOL_VERSION=${tool_versions.filter_libtool} $python_path $script $libtool -static -D {{arflags}} -o {{output}} -filelist $rspfile"
+ description = "LIBTOOL-STATIC {{output}}"
+ } else {
+ rspfile_content = "{{inputs}}"
+ ar = "${prefix}llvm-ar"
+ command = "\"$ar\" {{arflags}} -r -c -s -D {{output}} \"@$rspfile\""
+
+ # Remove the output file first so that ar doesn't try to modify the
+ # existing file.
+ command = "rm -f {{output}} && $command"
+ description = "AR {{output}}"
+ }
+ outputs = [ "{{output_dir}}/{{target_output_name}}{{output_extension}}" ]
+ default_output_dir = "{{target_out_dir}}"
+ default_output_extension = ".a"
+ output_prefix = "lib"
+ }
+
+ tool("solink") {
+ # E.g. "./libfoo.dylib":
+ dylib = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
+ rspfile = dylib + ".rsp"
+ pool = "//build/toolchain:link_pool($default_toolchain)"
+
+ # These variables are not built into GN but are helpers that implement
+ # (1) linking to produce a .dylib, (2) extracting the symbols from that
+ # file to a temporary file, (3) if the temporary file has differences from
+ # the existing .TOC file, overwrite it, otherwise, don't change it.
+ #
+ # As a special case, if the library reexports symbols from other dynamic
+ # libraries, we always update the .TOC and skip the temporary file and
+ # diffing steps, since that library always needs to be re-linked.
+ tocname = dylib + ".TOC"
+ temporary_tocname = dylib + ".tmp"
+
+ # Use explicit paths to binaries. The binaries present on the default
+ # search path in /usr/bin are thin wrappers around xcrun, which requires a
+ # full CommandLineTools or Xcode install, and still may not choose the
+ # appropriate binary if there are multiple installs.
+ if (host_os == "mac") {
+ nm = invoker.bin_path + "nm"
+ otool = invoker.bin_path + "otool"
+ } else {
+ nm = "${prefix}llvm-nm"
+ otool = "${prefix}llvm-otool"
+ }
+
+ does_reexport_command = "[ ! -e \"$dylib\" -o ! -e \"$tocname\" ] || $otool -l \"$dylib\" | grep -q LC_REEXPORT_DYLIB"
+
+ link_command = "$linker_driver $ld -shared "
+ if (is_component_build) {
+ link_command += " -Wl,-install_name,@rpath/\"{{target_output_name}}{{output_extension}}\" "
+ }
+ link_command += dsym_switch
+ link_command += "{{ldflags}} -o \"$dylib\" -Wl,-filelist,\"$rspfile\" {{frameworks}} {{swiftmodules}} {{solibs}} {{libs}} {{rlibs}}"
+
+ replace_command = "if ! cmp -s \"$temporary_tocname\" \"$tocname\"; then mv \"$temporary_tocname\" \"$tocname\""
+ extract_toc_command = "{ $otool -l \"$dylib\" | grep LC_ID_DYLIB -A 5; $nm -gPp \"$dylib\" | cut -f1-2 -d' ' | grep -v U\$\$; true; }"
+
+ command = "if $does_reexport_command ; then $link_command && $extract_toc_command > \"$tocname\"; else $link_command && $extract_toc_command > \"$temporary_tocname\" && $replace_command ; fi; fi"
+
+ rspfile_content = "{{inputs_newline}}"
+
+ description = "SOLINK {{output}}"
+
+ # Use this for {{output_extension}} expansions unless a target manually
+ # overrides it (in which case {{output_extension}} will be what the target
+ # specifies).
+ default_output_dir = "{{root_out_dir}}"
+ default_output_extension = ".dylib"
+
+ output_prefix = "lib"
+
+ # Since the above commands only updates the .TOC file when it changes, ask
+ # Ninja to check if the timestamp actually changed to know if downstream
+ # dependencies should be recompiled.
+ restat = true
+
+ # Tell GN about the output files. It will link to the dylib but use the
+ # tocname for dependency management.
+ outputs = [
+ dylib,
+ tocname,
+ ]
+ link_output = dylib
+ depend_output = tocname
+
+ if (_enable_dsyms) {
+ outputs += dsym_output
+ }
+ if (_save_unstripped_output) {
+ outputs += [ _unstripped_output ]
+ }
+ }
+
+ tool("solink_module") {
+ # E.g. "./libfoo.so":
+ sofile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
+ rspfile = sofile + ".rsp"
+ pool = "//build/toolchain:link_pool($default_toolchain)"
+
+ link_command = "$linker_driver $ld -bundle {{ldflags}} -o \"$sofile\" -Wl,-filelist,\"$rspfile\""
+ link_command += dsym_switch
+ link_command +=
+ " {{frameworks}} {{swiftmodules}} {{solibs}} {{libs}} {{rlibs}}"
+ command = link_command
+
+ rspfile_content = "{{inputs_newline}}"
+
+ description = "SOLINK_MODULE {{output}}"
+
+ # Use this for {{output_extension}} expansions unless a target manually
+ # overrides it (in which case {{output_extension}} will be what the target
+ # specifies).
+ default_output_dir = "{{root_out_dir}}"
+ default_output_extension = ".so"
+
+ outputs = [ sofile ]
+
+ if (_enable_dsyms) {
+ outputs += dsym_output
+ }
+ if (_save_unstripped_output) {
+ outputs += [ _unstripped_output ]
+ }
+ }
+
+ tool("link") {
+ outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
+ rspfile = "$outfile.rsp"
+ pool = "//build/toolchain:link_pool($default_toolchain)"
+
+ # Note about -filelist: Apple's linker reads the file list file and
+ # interprets each newline-separated chunk of text as a file name. It
+ # doesn't do the things one would expect from the shell like unescaping
+ # or handling quotes. In contrast, when Ninja finds a file name with
+ # spaces, it single-quotes them in $inputs_newline as it would normally
+ # do for command-line arguments. Thus any source names with spaces, or
+ # label names with spaces (which GN bases the output paths on) will be
+ # corrupted by this process. Don't use spaces for source files or labels.
+ command = "$linker_driver $ld $dsym_switch {{ldflags}} -o \"$outfile\" -Wl,-filelist,\"$rspfile\" {{frameworks}} {{swiftmodules}} {{solibs}} {{libs}} {{rlibs}}"
+ description = "LINK $outfile"
+ rspfile_content = "{{inputs_newline}}"
+ outputs = [ outfile ]
+
+ if (_enable_dsyms) {
+ outputs += dsym_output
+ }
+ if (_save_unstripped_output) {
+ outputs += [ _unstripped_output ]
+ }
+
+ default_output_dir = "{{root_out_dir}}"
+ }
+
+ # These two are really entirely generic, but have to be repeated in
+ # each toolchain because GN doesn't allow a template to be used here.
+ # See //build/toolchain/toolchain.gni for details.
+ tool("stamp") {
+ command = stamp_command
+ description = stamp_description
+ }
+ tool("copy") {
+ command = copy_command
+ description = copy_description
+ }
+
+ tool("copy_bundle_data") {
+ # copy_command use hardlink if possible but this does not work with
+ # directories. Also when running EG2 tests from Xcode, Xcode tries to
+ # copy some files into the application bundle which fails if source
+ # and destination are hardlinked together.
+ #
+ # Instead use clonefile to copy the files which is as efficient as
+ # hardlink but ensure the file have distinct metadata (thus avoid the
+ # error with ditto, see https://crbug.com/1042182).
+ if (host_os == "mac") {
+ command = "rm -rf {{output}} && /bin/cp -Rc {{source}} {{output}}"
+ } else {
+ command = "rm -rf {{output}} && /bin/cp -Rl {{source}} {{output}}"
+ }
+ description = "COPY_BUNDLE_DATA {{source}} {{output}}"
+ pool = "//build/toolchain/apple:bundle_pool($default_toolchain)"
+ }
+
+ # Swift is only used on iOS, not macOS. We want to minimize the number
+ # of Xcode-based tools used by the macOS toolchain, so we intentionally
+ # disallow future uses of Swift on macOS. https://crbug.com/965663.
+ if (toolchain_args.current_os == "ios") {
+ tool("swift") {
+ _tool = rebase_path("//build/toolchain/ios/swiftc.py", root_build_dir)
+
+ depfile = "{{target_out_dir}}/{{module_name}}.d"
+ depsformat = "gcc"
+
+ outputs = [
+ # The module needs to be the first output listed. The blank line after
+ # the module is required to prevent `gn format` from changing the file
+ # order.
+ "{{target_gen_dir}}/{{module_name}}.swiftmodule",
+
+ "{{target_gen_dir}}/{{module_name}}.h",
+ "{{target_gen_dir}}/{{module_name}}.swiftdoc",
+ "{{target_gen_dir}}/{{module_name}}.swiftsourceinfo",
+ ]
+
+ if (swift_whole_module_optimization) {
+ _extra_flags = "-whole-module-optimization"
+ _objects_dir = "{{target_out_dir}}"
+
+ outputs += [ "$_objects_dir/{{module_name}}.o" ]
+ } else {
+ _extra_flags = ""
+ _objects_dir = "{{target_out_dir}}/{{label_name}}"
+
+ partial_outputs = [ "$_objects_dir/{{source_name_part}}.o" ]
+ }
+
+ _env_vars = "TOOL_VERSION=${tool_versions.swiftc}"
+ if (invoker.sdk_developer_dir != "") {
+ _env_vars += " DEVELOPER_DIR=${toolchain_args.sdk_developer_dir}"
+ }
+
+ command =
+ "$_env_vars $python_path $_tool -module-name {{module_name}} " +
+ "-object-dir $_objects_dir " +
+ "-module-path {{target_gen_dir}}/{{module_name}}.swiftmodule " +
+ "-header-path {{target_gen_dir}}/{{module_name}}.h " +
+ "-depfile {{target_out_dir}}/{{module_name}}.d " +
+ "-depfile-filter {{target_gen_dir}}/{{module_name}}.swiftmodule " +
+ "-bridge-header {{bridge_header}} $_extra_flags " +
+ "{{swiftflags}} {{include_dirs}} {{module_dirs}} {{inputs}}"
+ }
+ }
+
+ # xcassets are only used on iOS, not macOS. We want to minimize the number
+ # of Xcode-based tools used by the macOS toolchain, so we intentionally
+ # disallow future uses of xcassets on macOS. https://crbug.com/965663.
+ if (toolchain_args.current_os == "ios") {
+ tool("compile_xcassets") {
+ _tool = rebase_path("//build/toolchain/ios/compile_xcassets.py",
+ root_build_dir)
+
+ _env_vars = "TOOL_VERSION=${tool_versions.compile_xcassets}"
+ if (invoker.sdk_developer_dir != "") {
+ _env_vars += " DEVELOPER_DIR=${toolchain_args.sdk_developer_dir}"
+ }
+
+ command =
+ "$_env_vars $python_path $_tool -p \"${invoker.sdk_name}\" " +
+ "-t \"${invoker.deployment_target}\" " +
+ "-T \"{{bundle_product_type}}\" " +
+ "-P \"{{bundle_partial_info_plist}}\" " + "-o {{output}} {{inputs}}"
+
+ description = "COMPILE_XCASSETS {{output}}"
+ pool = "//build/toolchain/apple:bundle_pool($default_toolchain)"
+ }
+ }
+
+ tool("action") {
+ pool = "//build/toolchain:action_pool($default_toolchain)"
+ }
+ }
+}