blob: 965293f4df18a5a8fa3de455a3dac2ac61a981d1 [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/dart/toolchain.gni")
import("//build/fidl/toolchain.gni")
import("//build/go/toolchain.gni")
import("//build/rust/toolchain.gni")
# Declares a FIDL library.
#
# Depending on the toolchain in which this targets is expanded, it will yield
# different results:
# - in the FIDL 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++ bindings.
#
# Parameters
#
# sources (required)
# List of paths to library source files.
#
# name (optional)
# Name of the library.
# Defaults to the target's name.
#
# sdk_category (optional)
# Publication level of the library in SDKs.
# See //build/sdk/sdk_atom.gni.
#
# api (optional)
# Path to the file representing the API of this library.
# This file is used to ensure modifications to the library's API are
# explicitly acknowledged. It is mandatory for publication categories of
# "partner" or "public".
# Defaults to "<target name>.api".
#
# excluded_checks (optional)
# A list of fidl-lint check IDs to ignore (by passing the command line flag
# "-e some-check-id" for each value).
#
# fuzzers (optional)
# Protocol/methods for which to generate LibFuzzer fuzz targets. Example:
# [
# {
# # Required:
# protocol = "fully.qualified.FIDLProtocolName"
# # Optional. Default: All methods in protocol.
# methods = [ "MethodName1", "MethodName2", ... ]
# },
# ...
# ]
#
# experimental_flags (optional)
# A list of experimental fidlc features to enable.
#
# host_llcpp (optional)
# A flag to enable or disable llcpp host generation.
#
# non_fidl_deps (optional)
# A list of non-FIDL dependency targets, i.e. targets that don't contribute
# FIDL artifacts, but should be built before this target regardless.
#
# should_lint (optional, boolean)
# If set to false, the linting step is skipped.
#
# experimental_api_summary (optional, boolean, default false)
# If set, the builder will generate FIDL API summary files. The generated
# file names are "<fidl_library_name>.api_summary" (human-readable), and
# "<fidl_library_name>.api_summary.json" (machine-readable).
template("fidl") {
if (defined(invoker.sdk_category)) {
not_needed(invoker, [ "sdk_category" ])
}
if (defined(invoker.api)) {
not_needed(invoker, [ "api" ])
}
if (defined(invoker.excluded_checks)) {
not_needed(invoker, [ "excluded_checks" ])
}
if (defined(invoker.fuzzers)) {
not_needed(invoker, [ "fuzzers" ])
}
if (defined(invoker.experimental_flags)) {
not_needed(invoker, [ "experimental_flags" ])
}
if (defined(invoker.host_llcpp)) {
not_needed(invoker, [ "host_llcpp" ])
}
if (defined(invoker.experimental_api_summary)) {
not_needed(invoker, [ "experimental_api_summary" ])
}
# Allow generated targets visibility to their dependant generated targets
if (defined(invoker.visibility)) {
invoker.visibility += [ ":*" ]
}
assert(!defined(invoker.deps),
"All FIDL dependencies are inherently " +
"public, use 'public_deps' instead of 'deps'.")
deps = []
if (defined(invoker.non_fidl_deps)) {
deps += invoker.non_fidl_deps
}
if (current_toolchain == dart_toolchain) {
import("//build/dart/fidl_dart.gni")
fidl_dart(target_name) {
forward_variables_from(invoker, "*")
}
} else if (current_toolchain == rust_toolchain) {
import("//build/rust/fidl_rust.gni")
fidl_rust(target_name) {
forward_variables_from(invoker, "*")
}
} else if (current_toolchain == go_toolchain) {
import("//build/go/fidl_go.gni")
fidl_go(target_name) {
forward_variables_from(invoker, "*")
}
} else {
if (current_toolchain == fidl_toolchain) {
import("//build/fidl/fidl_library.gni")
fidl_library(target_name) {
forward_variables_from(invoker, "*")
}
}
# Define the C++ family of generated bindings
import("//build/cpp/fidl_cpp.gni")
fidl_cpp_family(target_name) {
forward_variables_from(invoker, "*")
}
# Define FIDL coding tables target, used by C and C++
import("//build/c/fidl_c.gni")
fidl_tables(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
}
# TODO(cramertj): remove pending fxbug.dev/26853.
import("//build/rust/fidl_rust_library.gni")
fidl_rust_library(target_name) {
forward_variables_from(invoker, "*")
}
# Define the C generated bindings
if (is_fuchsia) {
fidl_c_client(target_name) {
forward_variables_from(invoker, "*")
}
fidl_c_server(target_name) {
forward_variables_from(invoker, "*")
}
group("${target_name}_c") {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
public_deps = [
":${target_name}_client",
":${target_name}_server",
]
}
import("//build/banjo/fidl_banjo.gni")
fidl_banjo(target_name) {
forward_variables_from(invoker, "*")
}
}
}
}