blob: b727f86b6197529f56e0abf64751dc341dfa29f4 [file] [log] [blame]
%YAML 1.2
--- |
# Copyright 2017 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.
# This file was created in two steps:
# First we ran tools/buildgen/generate_projects.sh which generates a BUILD.gn
# file based on the template in templates/BUILD.gn.template. Then we
# hand-edited the resulting file for Fuchsia.
config("grpc_config") {
include_dirs = [
".",
"include/",
]
defines = [
"GRPC_USE_PROTO_LITE",
]
}
<%!
def get_deps(target_dict):
deps = []
if target_dict.get("secure", False):
deps = [
"//third_party/boringssl",
]
if target_dict.get("build", None) == "protoc":
deps.append("//third_party/protobuf:protoc_lib")
name = target_dict.get("name", None)
if name in ("grpc++", "grpc++_codegen_lib"):
deps.append("//third_party/protobuf:protobuf_lite")
elif name in ("grpc", "grpc_unsecure"):
deps.append("//third_party/zlib")
for d in target_dict.get("deps", []):
# TODO(xyzzyz): grpc++_unsecure mistakenly depends on both grpc and
# grpc_unsecure. Remove when it's fixed.
# See https://github.com/grpc/grpc/issues/7739
if name == "grpc++_unsecure" and d == "grpc":
# Ignore.
continue
if d.startswith(("//", ":")):
deps.append(d)
else:
deps.append(":%s" % d)
return deps
def get_extra_configs(target_dict):
if target_dict.get("name", "") == "grpc_cpp_plugin":
return ["//third_party/protobuf:protobuf_config"]
return []
def uses_nanopb_or_protofull(f):
return (f.startswith("third_party/nanopb")
or f.endswith(".pb.h")
or f.endswith(".pb.c")
or f.endswith(".pb.cc")
or f.endswith("load_balancer_api.h")
or f.endswith("load_balancer_api.c"))
def wanted_lib(lib):
wanted_libs = ("gpr", "grpc", "grpc++", "grpc_plugin_support")
return lib.build in ("all", "protoc") and lib.get("name", "") in wanted_libs
def wanted_binary(tgt):
wanted_binaries = ("grpc_cpp_plugin",)
return tgt.build == "protoc" and tgt.get("name", "") in wanted_binaries
def only_on_host_toolchain(tgt):
return tgt.get("name", "") in ("grpc_plugin_support", "grpc_cpp_plugin")
%>
% for lib in libs:
% if wanted_lib(lib):
% if only_on_host_toolchain(lib):
# Only compile the plugin for the host architecture.
if (current_toolchain == host_toolchain) {
${cc_library(lib)}
}
% else:
${cc_library(lib)}
% endif
% endif
% endfor
% for tgt in targets:
% if wanted_binary(tgt):
% if only_on_host_toolchain(tgt):
# Only compile the plugin for the host architecture.
if (current_toolchain == host_toolchain) {
${cc_binary(tgt)}
}
% else:
${cc_binary(tgt)}
% endif
% endif
% endfor
<%def name="cc_library(lib)">
<%
lib_hdrs = [h for h in lib.get("headers", [])
if not uses_nanopb_or_protofull(h)]
lib_srcs = [s for s in lib.src if not uses_nanopb_or_protofull(s)]
lib_pub = lib.get("public_headers", [])
sources = lib_pub + lib_hdrs + lib_srcs
sources.sort()
%>
source_set("${lib.name}") {
sources = [
% for src in sources:
"${src}",
% endfor
]
deps = [
% for dep in get_deps(lib):
"${dep}",
% endfor
]
<% extra_configs = get_extra_configs(lib) %>
% if extra_configs:
configs += [
% for config in extra_configs:
"${config}",
% endfor
]
% endif
public_configs = [
":grpc_config",
]
}
</%def>
<%def name="cc_binary(tgt)">
executable("${tgt.name}") {
sources = [
% for src in tgt.src:
"${src}",
% endfor
]
deps = [
% for dep in get_deps(tgt):
"${dep}",
% endfor
]
<% extra_configs = get_extra_configs(tgt) %>
% if extra_configs:
configs += [
% for config in extra_configs:
"${config}",
% endfor
]
% endif
public_configs = [ ":grpc_config" ]
}
</%def>