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