blob: a95221ffcb5f78ee24cffb15533290cbb2997d3b [file] [log] [blame]
# Copyright 2024 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("//build/rust/rustc_binary.gni")
import("//src/starnix/kernel/starnix.gni")
# Build a Rust 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 `rustc_binary()`, except `testonly = true` is forced.
template("starnix_linux_rustc_binary") {
_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) {
rustc_binary(_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 ]
}
}