blob: 73b26fed8a1f7042d458f53092698bd4861a88e8 [file] [log] [blame]
# Copyright 2023 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/dist/resource.gni")
import("//src/starnix/kernel/starnix.gni")
# Build a C++ Linux executable so that it can be included in a Fuchsia package for use in Starnix.
#
# Binaries are included in packages at `data/tests/$output_name` to be compatible with typical
# Starnix container mount layouts. Note that `output_name` defaults to the target name if it is not
# specified.
#
# Arguments to the template are the same as `executable()`, except `testonly = true` is forced.
template("starnix_linux_executable") {
_output_name = target_name
if (defined(invoker.output_name)) {
_output_name = invoker.output_name
}
_bin_label = "${target_name}_bin"
_resource_label = target_name
if (is_linux) {
executable(_bin_label) {
forward_variables_from(invoker,
"*",
[
"output_name",
"visibility",
])
output_name = _output_name
# TODO(https://fxbug.dev/297293167) enable ASan instrumentation for Linux binaries in Starnix
if (!defined(exclude_toolchain_tags)) {
exclude_toolchain_tags = []
}
exclude_toolchain_tags += [ "instrumented" ]
visibility = [ ":${_resource_label}" ]
}
} else {
not_needed(invoker, "*")
}
_bin_label = ":${_bin_label}($target_linux_toolchain)"
_bin_out_dir = get_label_info(_bin_label, "root_out_dir")
resource(_resource_label) {
forward_variables_from(invoker,
"*",
[
"sources",
"outputs",
"deps",
])
sources = [ "${_bin_out_dir}/${_output_name}" ]
outputs = [ "data/tests/${_output_name}" ]
deps = [ _bin_label ]
}
}