| # Copyright 2019 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("//zircon/public/gn/host_tool_action.gni") |
| import("//zircon/public/gn/subtarget_aliases.gni") |
| |
| # This is the $fidl_support module for "low-level" C++ bindings. |
| # See fidl_library() for details. This file should not normally be |
| # imported by other code. |
| |
| # This tells fidl_library() to invoke fidl_llcpp_library(). |
| fidl_support_templates = [ |
| { |
| import = "//zircon/public/gn/fidl/llcpp.gni" |
| target = "fidl_llcpp_library" |
| fidlc = "json" |
| }, |
| ] |
| |
| # Provide LLCPP bindings for fidl_library(). **Do not use directly!** |
| # |
| # This is never used directly, but only indirectly by fidl_library(). |
| # See there for details. |
| template("fidl_llcpp_library") { |
| fidl_target = target_name |
| not_needed(invoker, "*") |
| |
| generator_target = "_fidl_llcpp_library.generate.$fidl_target" |
| generator_include_dir = "${invoker.fidlc_gen_dir}/include" |
| generator_header_file = |
| "$generator_include_dir/${invoker.fidl_path}/llcpp/fidl.h" |
| generator_source_file = "${invoker.fidlc_gen_dir}/fidl.cc" |
| |
| fidlgen_outputs = [ |
| generator_header_file, |
| generator_source_file, |
| ] |
| |
| if (current_toolchain == default_toolchain) { |
| fidlc_outputs = invoker.fidlc_outputs |
| fidl_json = fidlc_outputs[0] |
| assert(fidlc_outputs == [ fidl_json ]) |
| |
| host_tool_action(generator_target) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| visibility = [ ":*" ] |
| |
| tool = "//zircon/tools/fidl:fidlgen_llcpp" |
| |
| deps = invoker.fidlc_deps |
| |
| inputs = [ fidl_json ] |
| outputs = fidlgen_outputs |
| |
| args = [ |
| "-json", |
| rebase_path(fidl_json, root_build_dir), |
| "-source", |
| rebase_path(generator_source_file, root_build_dir), |
| "-header", |
| rebase_path(generator_header_file, root_build_dir), |
| ] |
| |
| metadata = { |
| generated_sources = rebase_path(outputs, root_build_dir) |
| } |
| } |
| } else { |
| library_target = "$fidl_target.llcpp" |
| |
| config("_fidl_llcpp_library.config.$library_target") { |
| visibility = [ |
| ":$library_target.headers", |
| ":$library_target.static", |
| ] |
| include_dirs = [ generator_include_dir ] |
| } |
| |
| library(library_target) { |
| forward_variables_from(invoker, |
| [ |
| "visibility", |
| "testonly", |
| ]) |
| |
| # Depend on the fidlc generation step and compile what it produces. |
| deps = [ ":$generator_target($default_toolchain)" ] |
| sources = fidlgen_outputs |
| |
| # Users of the bindings library need the generated headers. |
| public_configs = [ ":_fidl_llcpp_library.config.$library_target" ] |
| |
| # The `.headers` subtarget of a library() only depends on its |
| # public_deps. But all users of the headers need to depend on the |
| # generation step too, so put it in public_deps as well. |
| public_deps = [ ":$generator_target($default_toolchain)" ] |
| |
| # The generated headers of a dependent fidl_library() will #include the |
| # generated headers for its dependencies' bindings libraries, so those |
| # headers are needed in public_deps. The generated bindings code may |
| # call into its dependencies' bindings code, so the libraries |
| # themselves are needed in deps too. |
| foreach(dep, invoker.fidl_deps) { |
| deps += [ "$dep.llcpp" ] |
| public_deps += [ "$dep.llcpp.headers" ] |
| } |
| |
| # The generated code uses these. |
| public_deps += [ |
| "//zircon/system/ulib/fidl:fidl-llcpp.headers", |
| "//zircon/system/ulib/fit:fit.headers", |
| ] |
| deps += [ |
| ":$fidl_target.tables", |
| "//zircon/system/ulib/fidl:fidl-llcpp", |
| "//zircon/system/ulib/fit", |
| ] |
| } |
| |
| # Things normally depend on "fidl/foo:llcpp" rather than |
| # "fidl/foo:foo.llcpp". |
| subtarget_aliases(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "visibility", |
| "testonly", |
| ]) |
| outputs = [ |
| "llcpp", |
| "llcpp.headers", |
| "llcpp.static", |
| ] |
| } |
| } |
| } |