blob: e074dfdfa6f48a12d93fd94c6e49b0ad51bb2a01 [file] [log] [blame]
# 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.
# This file should only be imported from files that define toolchains.
# There's no way to enforce this exactly, but all toolchains are processed
# in the context of the default_toolchain, so we can at least check for that.
assert(current_toolchain == default_toolchain)
import("//build/config/android/config.gni")
import("//build/config/apple/symbols.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/coverage/coverage.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/toolchain/toolchain.gni")
declare_args() {
# Limit the number of concurrent links; we often want to run fewer
# links at once than we do compiles, because linking is memory-intensive.
# The default to use varies by platform and by the amount of memory
# available, so we call out to a script to get the right value.
concurrent_links = getenv("COBALT_CONCURRENT_LINKS")
}
if (concurrent_links == "") {
if (use_thin_lto) {
_args = [ "--reserve_mem_gb=10" ]
if (use_goma_thin_lto) {
_args += [ "--thin-lto=goma" ]
} else {
_args += [ "--thin-lto=local" ]
}
if (is_win) {
# Based on measurements of linking chrome.dll and chrome_child.dll, plus
# a little padding to account for future growth.
_args += [ "--mem_per_link_gb=45" ]
} else {
_args += [ "--mem_per_link_gb=10" ]
}
} else if ((use_clang_coverage &&
# When coverage_instrumentation_input_file is not empty it means
# we're only instrumenting changed files and not using a lot of
# memory. Likewise, when it's empty we're building everything with
# coverage, which requires more memory.
coverage_instrumentation_input_file == "") ||
use_sanitizer_coverage || use_fuzzing_engine) {
# Full sanitizer coverage instrumentation increases linker memory consumption
# significantly.
_args = [ "--mem_per_link_gb=16" ]
} else if (is_win && symbol_level == 1 && !is_debug && is_component_build) {
_args = [ "--mem_per_link_gb=3" ]
} else if (is_win) {
_args = [ "--mem_per_link_gb=6" ]
} else if (is_mac) {
if (enable_dsyms) {
_args = [ "--mem_per_link_gb=12" ]
} else {
_args = [ "--mem_per_link_gb=4" ]
}
} else if (is_android && !is_component_build && symbol_level == 2) {
# Full debug symbols require large memory for link.
_args = [ "--mem_per_link_gb=25" ]
} else if (is_android && !is_debug && !using_sanitizer && is_java_debug &&
disable_android_lint && symbol_level < 2) {
if (symbol_level == 1) {
_args = [ "--mem_per_link_gb=6" ]
} else {
_args = [ "--mem_per_link_gb=4" ]
}
} else if ((is_linux || is_chromeos_lacros) && symbol_level == 0) {
# Memory consumption on link without debug symbols is low on linux.
_args = [ "--mem_per_link_gb=3" ]
} else {
_args = []
}
# For Android builds, we also need to be wary of:
# * ProGuard / R8
# * Android Lint
# These both have a peak usage of < 2GB, but that is still large enough for
# them to need to use a pool since they both typically happen at the
# same time as linking.
if (is_android) {
_args += [ "--secondary_mem_per_link=2" ]
}
# TODO(crbug.com/617429) Pass more build configuration info to the script
# so that we can compute better values.
_command_dict = exec_script("get_concurrent_links.py", _args, "scope")
concurrent_links = _command_dict.primary_pool_size
concurrent_links_logs = _command_dict.explanation
if (_command_dict.secondary_pool_size >= concurrent_links) {
# Have R8 / Lint share the link pool unless we would safely get more
# concurrency out of using a separate one.
# On low-RAM machines, this allows an apk's native library to link at the
# same time as its java is optimized with R8.
java_cmd_pool_size = _command_dict.secondary_pool_size
}
} else {
assert(!use_thin_lto, "can't explicitly set concurrent_links with thinlto")
# Convert the value to a number if it's a string.
concurrent_links =
exec_script("//starboard/build/echo.py", [ concurrent_links ], "value")
concurrent_links_logs =
[ "concurrent_links set by GN arg (value=$concurrent_links)" ]
}