blob: 8ad105f90822cc7d676c0bdcee5d8d637fa3c799 [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/compiled_action.gni")
import("//build/fidl/toolchain.gni")
# Declares a source_set for the coding tables of a FIDL library.
#
# Parameters (see //build/fidl/fidl.gni for descriptions):
#
# testonly
# visibility
#
template("fidl_tables") {
not_needed(invoker,
[
"name",
"public_deps",
"sdk_category",
])
fidl_target_gen_dir =
get_label_info(":bogus($fidl_toolchain)", "target_gen_dir")
generated_binding_dir = "$fidl_target_gen_dir/$target_name/c"
coding_tables = "$generated_binding_dir/$target_name.fidl.tables.c"
coding_tables_target = ":${target_name}($fidl_toolchain)"
# The C simple $type code is generated by the frontend, so we just need to
# produce a target with the generated file name and configuration information.
source_set("${target_name}_tables") {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
sources = [ coding_tables ]
deps = [ coding_tables_target ]
public_deps = [ "//sdk/lib/fidl_base" ]
if (is_fuchsia) {
public_deps += [ "//zircon/public/sysroot:headers" ]
} else {
public_deps += [ "//src/zircon/lib/zircon:zircon-headers" ]
}
}
}
# Helper for the fidl_c template. The `type` option should be "header",
# "client", or "server".
template("_fidl_c_target") {
assert(is_fuchsia, "This template can only be used in $target_toolchain.")
type = invoker.type
main_target_name = target_name
c_target_name = "${target_name}_c_${type}"
config_target_name = "${c_target_name}_config"
library_name = target_name
if (defined(invoker.name)) {
library_name = invoker.name
}
c_stem = string_replace(library_name, ".", "/") + "/c/fidl"
fidl_target_gen_dir =
get_label_info(":bogus($fidl_toolchain)", "target_gen_dir")
generated_binding_dir = "$fidl_target_gen_dir/$target_name/c"
c_header = "$generated_binding_dir/$c_stem.h"
config(config_target_name) {
include_dirs = [ generated_binding_dir ]
}
# The C simple $type code is generated by the frontend, so we just need to
# produce a target with the generated file name and configuration information.
source_set(c_target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
public = [ c_header ]
if (type != "header") {
sources = [ "$generated_binding_dir/$c_stem.$type.c" ]
}
# Let dependencies use `#include "$file_stem.h"`.
public_configs = [ ":$config_target_name" ]
deps = [
":${main_target_name}($fidl_toolchain)",
":${main_target_name}_tables",
]
public_deps = [ "//sdk/lib/fidl" ]
if (is_fuchsia) {
public_deps += [ "//zircon/public/sysroot:headers" ]
} else {
public_deps += [ "//src/zircon/lib/zircon:zircon-headers" ]
}
if (defined(invoker.public_deps)) {
foreach(dep, invoker.public_deps) {
_label = get_label_info(dep, "label_no_toolchain")
_toolchain = get_label_info(dep, "toolchain")
public_deps += [ "${_label}_c_${type}(${_toolchain})" ]
}
}
# TODO(fxbug.dev/95833): We suppress deprecated usage warnings
# in generated C bindings code itself. Delete this line after everything
# migrates off of the C bindings.
configs += [ "//build/c:fidl-deprecated-c-bindings-reserved-for-fidlc-generated-code-only" ]
}
}
# C simple client and server bindings for a FIDL library.
#
# Parameters (see //build/fidl/fidl.gni for descriptions):
#
# name
# public_deps
# testonly
# visibility
#
template("fidl_c") {
not_needed(invoker, [ "sdk_category" ])
# TODO(fxbug.dev/99732): Evaluate whether we really need this.
_fidl_c_target(target_name) {
forward_variables_from(invoker, "*")
type = "header"
}
_fidl_c_target(target_name) {
forward_variables_from(invoker, "*")
type = "client"
}
_fidl_c_target(target_name) {
forward_variables_from(invoker, "*")
type = "server"
}
group("${target_name}_c") {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
public_deps = [
":${target_name}_client",
":${target_name}_header",
":${target_name}_server",
]
}
}