• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# This file should only be imported from files that define toolchains.
6# There's no way to enforce this exactly, but all toolchains are processed
7# in the context of the default_toolchain, so we can at least check for that.
8assert(current_toolchain == default_toolchain)
9
10import("//build/config/android/config.gni")
11import("//build/config/apple/symbols.gni")
12import("//build/config/chromeos/ui_mode.gni")
13import("//build/config/compiler/compiler.gni")
14import("//build/config/coverage/coverage.gni")
15import("//build/config/sanitizers/sanitizers.gni")
16import("//build/toolchain/toolchain.gni")
17
18declare_args() {
19  # Limit the number of concurrent links; we often want to run fewer
20  # links at once than we do compiles, because linking is memory-intensive.
21  # The default to use varies by platform and by the amount of memory
22  # available, so we call out to a script to get the right value.
23  concurrent_links = -1
24}
25
26if (concurrent_links == -1) {
27  if (use_thin_lto) {
28    _args = [ "--reserve_mem_gb=10" ]
29    if (use_goma_thin_lto) {
30      _args += [ "--thin-lto=goma" ]
31    } else {
32      _args += [ "--thin-lto=local" ]
33    }
34    if (is_win) {
35      # Based on measurements of linking chrome.dll and chrome_child.dll, plus
36      # a little padding to account for future growth.
37      _args += [ "--mem_per_link_gb=45" ]
38    } else {
39      _args += [ "--mem_per_link_gb=20" ]
40    }
41  } else if ((use_clang_coverage &&
42              # When coverage_instrumentation_input_file is not empty it means
43              # we're only instrumenting changed files and not using a lot of
44              # memory. Likewise, when it's empty we're building everything with
45              # coverage, which requires more memory.
46              coverage_instrumentation_input_file == "") ||
47             use_sanitizer_coverage || use_fuzzing_engine) {
48    # Full sanitizer coverage instrumentation increases linker memory consumption
49    # significantly.
50    _args = [ "--mem_per_link_gb=16" ]
51  } else if (is_win && symbol_level == 1 && !is_debug && is_component_build) {
52    _args = [ "--mem_per_link_gb=3" ]
53  } else if (is_win) {
54    _args = [ "--mem_per_link_gb=6" ]
55  } else if (is_mac) {
56    if (enable_dsyms) {
57      _args = [ "--mem_per_link_gb=12" ]
58    } else {
59      _args = [ "--mem_per_link_gb=4" ]
60    }
61  } else if (is_android && !is_component_build && symbol_level == 2) {
62    # Full debug symbols require large memory for link.
63    _args = [ "--mem_per_link_gb=25" ]
64  } else if (is_android && !is_debug && !using_sanitizer && symbol_level < 2) {
65    if (symbol_level == 1) {
66      _args = [ "--mem_per_link_gb=6" ]
67    } else {
68      _args = [ "--mem_per_link_gb=4" ]
69    }
70  } else if ((is_linux || is_chromeos_lacros) && symbol_level == 0) {
71    # Memory consumption on link without debug symbols is low on linux.
72    _args = [ "--mem_per_link_gb=3" ]
73  } else if (current_os == "zos") {
74    _args = [ "--mem_per_link_gb=1" ]
75  } else if (is_fuchsia) {
76    # TODO(crbug.com/1347159): This was defaulting to 8GB. The number of
77    #    linker instances to run in parallel is calculated by diviging
78    #    the available memory by this value. On a 32GB machine with
79    #    roughly 29GB of available memory, this would cause three instances
80    #    to run. This started running out of memory and thrashing. This change
81    #    addresses that issue to get the SDk rollers running again but
82    #    could be optimized (maybe to 12GB or for different configs like
83    #    component build).
84    _args = [ "--mem_per_link_gb=16" ]
85  } else {
86    _args = []
87  }
88
89  # For Android builds, we also need to be wary of:
90  # * ProGuard / R8
91  # * Android Lint
92  # These both have a peak usage of < 2GB, but that is still large enough for
93  # them to need to use a pool since they both typically happen at the
94  # same time as linking.
95  if (is_android) {
96    _args += [ "--secondary_mem_per_link=2" ]
97  }
98
99  # TODO(crbug.com/617429) Pass more build configuration info to the script
100  # so that we can compute better values.
101  _command_dict = exec_script("get_concurrent_links.py", _args, "scope")
102
103  concurrent_links = _command_dict.primary_pool_size
104  concurrent_links_logs = _command_dict.explanation
105
106  if (_command_dict.secondary_pool_size >= concurrent_links) {
107    # Have R8 / Lint share the link pool unless we would safely get more
108    # concurrency out of using a separate one.
109    # On low-RAM machines, this allows an apk's native library to link at the
110    # same time as its java is optimized with R8.
111    java_cmd_pool_size = _command_dict.secondary_pool_size
112  }
113} else {
114  assert(!use_thin_lto, "can't explicitly set concurrent_links with thinlto")
115  concurrent_links_logs =
116      [ "concurrent_links set by GN arg (value=$concurrent_links)" ]
117}
118