blob: 7fdae1f8f0880502be00f736f812c8064fd8e0d3 [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")
template("fidl_tables") {
main_target_name = target_name
fidl_target_gen_dir =
get_label_info(":$target_name($fidl_toolchain)", "target_gen_dir")
coding_tables = "$fidl_target_gen_dir/$target_name.fidl.tables.c"
# 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(main_target_name + "_tables") {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
sources = [ coding_tables ]
deps = [ ":${main_target_name}_compile($fidl_toolchain)" ]
public_deps = [ "//zircon/system/ulib/fidl:fidl_base" ]
if (is_fuchsia) {
public_deps += [ "//zircon/public/sysroot:headers" ]
} else {
public_deps += [ "//src/zircon/lib/zircon:zircon-headers" ]
}
}
}
# C simple client bindings for a FIDL library.
#
# The parameters for this template are defined in //build/fidl/fidl.gni. The
# relevant parameters in this template are:
# name: string, name of the FIDL library
# type: string, '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
config_target_name = main_target_name + "_c_" + type + "_config"
library_name = invoker.name
c_stem = string_replace(library_name, ".", "/") + "/c/fidl"
fidl_target_gen_dir =
get_label_info(":$target_name($fidl_toolchain)", "target_gen_dir")
generated_binding_dir = "$fidl_target_gen_dir/$target_name/c"
c_header = "$generated_binding_dir/$c_stem.h"
c_file = "$generated_binding_dir/$c_stem.$type.c"
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(main_target_name + "_c_" + type) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
sources = [ c_file ]
public = [ c_header ]
# Let dependencies use `#include "$file_stem.h"`.
public_configs = [ ":$config_target_name" ]
deps = [
":${main_target_name}_compile($fidl_toolchain)",
":${main_target_name}_tables",
]
public_deps = [ "//zircon/system/ulib/fidl" ]
if (is_fuchsia) {
public_deps += [ "//zircon/public/sysroot:headers" ]
} else {
public_deps += [ "//src/zircon/lib/zircon:zircon-headers" ]
}
if (defined(invoker.deps)) {
public_deps += invoker.deps
}
if (defined(invoker.public_deps)) {
foreach(dep, invoker.public_deps) {
public_deps += [ get_label_info(dep, "label_no_toolchain") + "_c_" +
type + "(" + get_label_info(dep, "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" ]
}
}
template("fidl_c_client") {
library_name = target_name
if (defined(invoker.name)) {
library_name = invoker.name
}
forward_variables_from(invoker,
[
"deps",
"public_deps",
"testonly",
"visibility",
])
fidl_c_target(target_name) {
name = library_name
type = "client"
}
}
template("fidl_c_server") {
library_name = target_name
if (defined(invoker.name)) {
library_name = invoker.name
}
forward_variables_from(invoker,
[
"deps",
"public_deps",
"testonly",
"visibility",
])
fidl_c_target(target_name) {
name = library_name
type = "server"
}
}