| # Copyright 2017 The Fuchsia 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/config/lto/config.gni") | |
| import("//build/toolchain/variant.gni") | |
| # This config is added unconditionally by BUILDCONFIG.gn to pick up the | |
| # global `use_lto` build argument. For fine-grained control, leave | |
| # `use_lto=false` and use `select_variant` to choose the `lto` or `thinlto` | |
| # variant for some components. | |
| config("default") { | |
| if (use_lto) { | |
| if (use_thinlto) { | |
| configs = [ ":thinlto" ] | |
| } else { | |
| configs = [ ":lto" ] | |
| } | |
| } | |
| } | |
| variant("lto") { | |
| common_flags = [ | |
| "-flto", | |
| # Enable whole-program devirtualization and virtual constant propagation. | |
| "-fwhole-program-vtables", | |
| ] | |
| rustflags = [ "-Clto=fat" ] | |
| } | |
| variant("thinlto") { | |
| common_flags = [ "-flto=thin" ] | |
| # These switches have the same meaning but different spellings for | |
| # lld-link vs ld.lld. | |
| if (current_os == "win") { | |
| _jobs = "/opt:lldltojobs=" | |
| _cache_dir = "/lldltocache:" | |
| } else { | |
| _jobs = "--thinlto-jobs=" | |
| _cache_dir = "--thinlto-cache-dir=" | |
| } | |
| ldflags = [ | |
| # The ThinLTO driver launches a number of threads in parallel whose | |
| # number is by default equivalent to the number of cores. We need | |
| # to limit the parallelism to avoid aggressive competition between | |
| # different linker jobs. | |
| "-Wl,${_jobs}$thinlto_jobs", | |
| # Set the ThinLTO cache directory which is used to cache native | |
| # object files for ThinLTO incremental builds. This directory is | |
| # not managed by Ninja and has to be cleaned manually, but it is | |
| # periodically garbage-collected by the ThinLTO driver. | |
| "-Wl,${_cache_dir}$thinlto_cache_dir", | |
| ] | |
| rustflags = [ "-Clto=thin" ] | |
| } |