| # 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 |
| # |
| # * fidl_target |
| # - Required: The name of the associated fidl() target. |
| # - Type: string |
| # |
| # * testonly, visibility |
| # - Optional: Usual GN meanings. |
| # |
| template("fidl_tables") { |
| forward_variables_from(invoker, [ "fidl_target" ]) |
| coding_tables_target = ":${fidl_target}($fidl_toolchain)" |
| coding_tables = get_label_info(coding_tables_target, "target_gen_dir") + |
| "/${fidl_target}/c/$fidl_target.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(target_name) { |
| 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.") |
| |
| forward_variables_from(invoker, |
| [ |
| "library_name", |
| "fidl_target", |
| "fidl_gen_dir", |
| "type", |
| ]) |
| main_target = target_name |
| config_target = "${target_name}_config" |
| |
| c_stem = string_replace(library_name, ".", "/") + "/c/fidl" |
| generated_binding_dir = fidl_gen_dir |
| c_header = "$generated_binding_dir/$c_stem.h" |
| |
| config(config_target) { |
| 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) { |
| 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" ] |
| |
| deps = [ |
| ":${fidl_target}($fidl_toolchain)", |
| ":${fidl_target}_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 |
| # |
| # * library_name |
| # - Required: The name of the FIDL library. |
| # - Type: string |
| # |
| # * fidl_target |
| # - Required: The name of the associated fidl() target. |
| # - Type: string |
| # |
| # * fidl_gen_dir |
| # - Required: The directory under which bindings should be generated. |
| # - Type: path |
| # |
| # * testonly, visibility, public_deps |
| # - Optional: Usual GN meanings. |
| # |
| template("fidl_c") { |
| assert(defined(invoker.library_name), |
| "fidl_c(\"$target_name\") requires `library_name`") |
| assert(defined(invoker.fidl_target), |
| "fidl_c(\"$target_name\") requires `fidl_target`") |
| assert(defined(invoker.fidl_gen_dir), |
| "fidl_c(\"$target_name\") requires `fidl_gen_dir`") |
| |
| # TODO(fxbug.dev/99732): Evaluate whether we really need this. |
| _fidl_c_target("${target_name}_header") { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| "public_deps", |
| "library_name", |
| "fidl_target", |
| "fidl_gen_dir", |
| ]) |
| type = "header" |
| } |
| |
| _fidl_c_target("${target_name}_client") { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| "public_deps", |
| "library_name", |
| "fidl_target", |
| "fidl_gen_dir", |
| ]) |
| type = "client" |
| } |
| |
| _fidl_c_target("${target_name}_server") { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| "public_deps", |
| "library_name", |
| "fidl_target", |
| "fidl_gen_dir", |
| ]) |
| type = "server" |
| } |
| |
| group(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| |
| public_deps = [ |
| ":${target_name}_client", |
| ":${target_name}_header", |
| ":${target_name}_server", |
| ] |
| } |
| } |