blob: a53a080532d9b4540bc958160ed5cf3b5015c5bc [file] [log] [blame]
# Copyright 2018 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/banjo/fidl_adapter.gni")
import("//build/banjo/toolchain.gni")
import("//build/rust/toolchain.gni")
# Declares a BANJO library.
#
# Depending on the toolchain in which this targets is expanded, it will yield
# different results:
# - in the BANJO toolchain, it will compile its source files into an
# intermediate representation consumable by language bindings generators;
# - in the target or shared toolchain, this will produce a source_set
# containing C/C++ bindings.
#
# Parameters
#
# sources (required)
# List of paths to library source files.
#
# name (optional)
# Name of the library.
# Defaults to the target's name.
#
# needs_composite (optional)
# Defines whether composite dep should be auto-added or not.
# Defaults to true.
#
# sdk_category (optional)
# Publication level of the library in SDKs.
# See //build/sdk/sdk_atom.gni.
#
# translate_to_fidl (optional)
# Whether to add extra targets presenting this library as a FIDL library.
# This is part of the Banjo deprecation effort and should not be used in
# any other context.
# Defaults to true.
#
# fidl_only (optional)
# Whether to only present this library as a FIDL library.
# This is to ensure to once we start using a library as a FIDL one, no new
# legacy reference gets introduced.
# Defaults to false.
template("banjo") {
if (defined(invoker.sdk_category)) {
not_needed(invoker, [ "sdk_category" ])
}
if (defined(invoker.needs_composite)) {
not_needed(invoker, [ "needs_composite" ])
}
excluded_variables = [
"fidl_only",
"translate_to_fidl",
]
if (current_toolchain == banjo_toolchain) {
import("//build/banjo/banjo_library.gni")
banjo_library(target_name) {
forward_variables_from(invoker, "*", excluded_variables)
if (!defined(deps)) {
deps = []
}
}
} else if (!defined(invoker.fidl_only) || !invoker.fidl_only) {
if (is_fuchsia) {
import("//build/c/banjo_c.gni")
import("//build/rust/banjo_rust_library.gni")
banjo_rust_library(target_name) {
forward_variables_from(invoker, "*", excluded_variables)
}
banjo_c_target(target_name) {
forward_variables_from(invoker, "*", excluded_variables)
}
} else {
assert(false,
"Unable to process BANJO target in toolchain $current_toolchain.")
}
}
if (!defined(invoker.translate_to_fidl) || invoker.translate_to_fidl) {
if (is_fuchsia) {
# Add an extra set of targets handling Banjo sources as a FIDL library.
fidl_adapter(target_name) {
forward_variables_from(invoker, "*", excluded_variables)
}
}
}
}
template("banjo_dummy") {
if (defined(invoker.sdk_category)) {
not_needed(invoker, [ "sdk_category" ])
}
if (current_toolchain == banjo_toolchain) {
import("//build/banjo/banjo_library.gni")
banjo_dummy_library(target_name) {
forward_variables_from(invoker, "*")
}
} else if (is_fuchsia) {
import("//build/c/banjo_c.gni")
import("//build/rust/banjo_rust_library.gni")
banjo_dummy_rust_library(target_name) {
forward_variables_from(invoker, "*")
}
banjo_dummy_c_target(target_name) {
forward_variables_from(invoker, "*")
}
} else {
assert(false,
"Unable to process BANJO target in toolchain $current_toolchain.")
}
}