• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1%YAML 1.2
2--- |
3  # GRPC Fuchsia GN build file
4
5  # This file has been automatically generated from a template file.
6  # Please look at the templates directory instead.
7  # This file can be regenerated from the template by running
8  # tools/buildgen/generate_projects.sh
9
10  # Copyright 2019 gRPC authors.
11  #
12  # Licensed under the Apache License, Version 2.0 (the "License");
13  # you may not use this file except in compliance with the License.
14  # You may obtain a copy of the License at
15  #
16  #     http://www.apache.org/licenses/LICENSE-2.0
17  #
18  # Unless required by applicable law or agreed to in writing, software
19  # distributed under the License is distributed on an "AS IS" BASIS,
20  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  # See the License for the specific language governing permissions and
22  # limitations under the License.
23
24  config("grpc_config") {
25    include_dirs = [
26      ".",
27      "include/",
28    ]
29    defines = [
30      "GRPC_USE_PROTO_LITE",
31      "GPR_SUPPORT_CHANNELS_FROM_FD",
32      "PB_FIELD_16BIT",
33    ]
34  }
35  <%!
36  def get_deps(target_dict):
37    deps = []
38    if target_dict.get("secure", False):
39      deps = ["//third_party/boringssl"]
40    if target_dict.get("build", None) == "protoc":
41      deps.append("//third_party/protobuf:protoc_lib")
42    name = target_dict.get("name", None)
43    if name in ("grpc++", "grpc++_codegen_lib"):
44      deps.append("//third_party/protobuf:protobuf_lite")
45    elif name in ("grpc", "grpc_unsecure"):
46      deps.append("//third_party/zlib")
47    for d in target_dict.get("deps", []):
48      if d.startswith(("//", ":")):
49        deps.append(d)
50      else:
51        deps.append(":%s" % d)
52    if needs_ares(target_dict.src):
53      deps.append("//third_party/cares")
54      deps.append(":address_sorting")
55    if needs_health_proto(target_dict.src) and target_dict.name != "health_proto":
56      deps.append(":health_proto")
57    return deps
58
59  %><%!
60  def needs_ares(srcs):
61    return any("/c_ares/" in f for f in srcs) if srcs else False
62
63  %><%!
64  def needs_address_sorting(sources):
65    return needs_ares(sources) or any("address_sorting" in s for s in sources)
66
67  %><%!
68  def needs_health_proto(srcs):
69    return any("health.pb" in f for f in srcs)
70
71  %><%!
72  def get_include_dirs(sources):
73    dirs = []
74    if needs_ares(sources):
75      dirs = ["third_party/cares"]
76    if needs_address_sorting(sources):
77      dirs.append("third_party/address_sorting/include")
78    return dirs
79
80  %><%!
81  def strip_sources(sources, name):
82    return [f for f in sources
83            if "ruby_generator" not in f
84            and ("health.pb" not in f or name == "health_proto")]
85
86  %><%!
87  def get_sources(target):
88    return ((target.public_headers or []) +
89            (target.headers or []) +
90            (target.src or []))
91
92  %><%!
93  def get_extra_configs(target_dict):
94    if target_dict.get("name", "") == "grpc_cpp_plugin":
95      return ["//third_party/protobuf:protobuf_config"]
96    return []
97
98  %><%!
99  def wanted_lib(lib):
100    wanted_libs = ("gpr", "grpc", "grpc++", "grpc_plugin_support", "address_sorting")
101    return lib.build in ("all", "protoc") and lib.get("name", "") in wanted_libs
102
103  %><%!
104  def wanted_binary(tgt):
105    wanted_binaries = ("grpc_cpp_plugin",)
106    return tgt.build == "protoc" and tgt.get("name", "") in wanted_binaries
107
108  %><%!
109  def only_on_host_toolchain(tgt):
110    return tgt.get("name", "") in ("grpc_plugin_support", "grpc_cpp_plugin")
111
112  %>
113  % for lib in filegroups:
114    % if lib.name in ("health_proto"):
115      ${cc_library(lib)}
116    %endif
117  %endfor
118  % for lib in libs:
119    % if wanted_lib(lib):
120      % if only_on_host_toolchain(lib):
121        # Only compile the plugin for the host architecture.
122        if (current_toolchain == host_toolchain) {
123          ${cc_library(lib)}
124        }
125      % else:
126        ${cc_library(lib)}
127      % endif
128    % endif
129  % endfor
130  % for tgt in targets:
131    % if wanted_binary(tgt):
132      % if only_on_host_toolchain(tgt):
133        # Only compile the plugin for the host architecture.
134        if (current_toolchain == host_toolchain) {
135          ${cc_binary(tgt)}
136        }
137      % else:
138        ${cc_binary(tgt)}
139      % endif
140    % endif
141  % endfor
142  <%def name="cc_library(lib)">
143    <%
144      sources = get_sources(lib)
145      include_dirs = get_include_dirs(sources)
146      sources = strip_sources(sources, lib.name)
147      sources.sort()
148    %>
149    source_set("${lib.name}") {
150      %if sources:
151      sources = [
152        % for src in sources:
153          "${src}",
154        % endfor
155      ]
156      %endif
157      deps = [
158        % for dep in get_deps(lib):
159          "${dep}",
160        % endfor
161      ]
162      <% extra_configs = get_extra_configs(lib) %>
163      % if extra_configs:
164        configs += [
165          % for config in extra_configs:
166            "${config}",
167          % endfor
168        ]
169      % endif
170      public_configs = [
171        ":grpc_config",
172      ]
173      %if include_dirs:
174      include_dirs = [
175        %for d in include_dirs:
176          "${d}",
177        %endfor
178      ]
179      %endif
180    }
181  </%def>
182  <%def name="cc_binary(tgt)">
183    executable("${tgt.name}") {
184      sources = [
185        % for src in tgt.src:
186          "${src}",
187        % endfor
188      ]
189      deps = [
190        % for dep in get_deps(tgt):
191          "${dep}",
192        % endfor
193      ]
194      <% extra_configs = get_extra_configs(tgt) %>
195      % if extra_configs:
196        configs += [
197          % for config in extra_configs:
198            "${config}",
199          % endfor
200        ]
201      % endif
202      public_configs = [ ":grpc_config" ]
203    }
204  </%def>
205  ## vim: set ft=mako:ts=2:et:sw=2
206