| # Copyright 2020 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/rust/rustc_binary.gni") | 
 | import("//src/developer/ffx/lib/version/build/ffx_apply_version.gni") | 
 | import("ffx_plugin.gni") | 
 |  | 
 | # Defines FFX | 
 | # | 
 | template("ffx") { | 
 |   assert(is_host, "ffx presently only builds in host toolchains") | 
 |  | 
 |   if (defined(invoker.ffx_deps)) { | 
 |     ffx_deps = invoker.ffx_deps | 
 |   } else { | 
 |     ffx_deps = [] | 
 |   } | 
 |  | 
 |   ffx_name = target_name | 
 |  | 
 |   if (defined(invoker.name)) { | 
 |     ffx_name = invoker.name | 
 |   } | 
 |  | 
 |   suite_name = ffx_name + "_lib" | 
 |  | 
 |   _original_target_name = target_name | 
 |   ffx_plugin(suite_name) { | 
 |     original_target_name = _original_target_name | 
 |     forward_variables_from(invoker, "*", [ "test_deps" ]) | 
 |     config_data = [ "data/config.json" ] | 
 |   } | 
 |  | 
 |   rustc_binary(ffx_name + "_bin_unversioned") { | 
 |     output_name = ffx_name + "_unversioned" | 
 |     original_target_name = _original_target_name | 
 |  | 
 |     # As ffx is a tool that's used by subsequent build actions, speeding up its | 
 |     # compilation allows other tasks to be started more quickly, lowering | 
 |     # overall drag on the graph. | 
 |  | 
 |     # These options cause it to fail in RBE, due to OOM | 
 |     disable_rbe = false | 
 |  | 
 |     # Since RBE is disabled, this runs locally and is known to require | 
 |     # massive memory.  Until RBE is re-enabled for this target, | 
 |     # we must limit its concurrency with other memory-intensive jobs. | 
 |     # See https://fxbug.dev/111094 for context. | 
 |     if (disable_rbe) { | 
 |       pool = "//build/config:highmem($default_toolchain)" | 
 |     } | 
 |  | 
 |     # Use up to 16 threads for codegen | 
 |     configs += [ "//build/config/rust:codegen_units_16" ] | 
 |  | 
 |     if (is_debug) { | 
 |       # Disable lto for debug builds, as the additional codegen units imply the | 
 |       # use of thin-local lto | 
 |       configs += [ "//build/config/rust:lto_disabled" ] | 
 |     } else { | 
 |       # Use thin lto (instead of implied thin-local), to run (thin) lto across | 
 |       # the entire set of dependency crates, to minimize final binary size | 
 |       # without spending an undue amount of time (this is still faster than | 
 |       # using codegen_units=1) | 
 |       configs += [ "//build/config/rust:lto_thin" ] | 
 |     } | 
 |  | 
 |     deps = ffx_deps | 
 |     non_rust_deps = [ | 
 |       "//src/lib/chunked-compression", | 
 |       "//third_party/boringssl", | 
 |     ] | 
 |     forward_variables_from(invoker, | 
 |                            "*", | 
 |                            [ | 
 |                              "deps", | 
 |                              "name", | 
 |                              "non_rust_deps", | 
 |                            ]) | 
 |  | 
 |     configs += [ "//build/config/rust:panic_abort" ] | 
 |   } | 
 |  | 
 |   # Replace the special linker sections containing the version information with the real values | 
 |   ffx_apply_version(ffx_name + "_bin") { | 
 |     output_name = ffx_name | 
 |  | 
 |     deps = [ ":${ffx_name}_bin_unversioned" ] | 
 |   } | 
 |  | 
 |   group(ffx_name + "_tests") { | 
 |     testonly = true | 
 |  | 
 |     deps = [ | 
 |       ":" + ffx_name + "_bin_unversioned_test", | 
 |       ":" + suite_name + "_tests", | 
 |     ] | 
 |   } | 
 | } |