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