blob: 36b809e3c47979f28811df48e20174812978df9d [file] [log] [blame]
# 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
}
_large_binary_optimizations = false
if (defined(invoker.large_ffx_binary_optimizations)) {
_large_binary_optimizations = invoker.large_ffx_binary_optimizations
}
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" ])
}
rustc_binary(ffx_name + "_bin_unversioned") {
output_name = ffx_name + "_unversioned"
original_target_name = _original_target_name
if (_large_binary_optimizations) {
# ffx is known to be a massive, time/resource-consuming target.
# When running locally (including RBE local and racing strategies),
# limit its concurrency with other memory-intensive jobs.
# See https://fxbug.dev/42062387 for context.
pool = "//build/config:highmem($default_toolchain)"
# Since remote workers tend to be slightly slower than the local
# machine, and ffx is frequently on critical path, race local against
# remote execution, which stll lets it remotely cache.
configs += [ "//build/config/rust:rbe_strategy_racing" ]
# 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" ]
forward_variables_from(invoker,
"*",
[
"deps",
"name",
"non_rust_deps",
])
}
# Replace the special linker sections containing the version information with the real values
ffx_apply_version(ffx_name + "_bin") {
output_name = ffx_name
ffx_unversioned_binary_path = "${root_out_dir}/${ffx_name}_unversioned"
deps = [ ":${ffx_name}_bin_unversioned" ]
}
group(ffx_name + "_tests") {
testonly = true
deps = [
":" + ffx_name + "_bin_unversioned_test",
":" + suite_name + "_tests",
]
}
}