blob: b3f97650e8cf1a3832b3f4d2f2eda59134c9192b [file] [log] [blame]
Jan Tattermusch4d5c3102017-06-07 10:23:56 +02001# Copyright 2016 gRPC authors.
Craig Tiller423ecff2016-10-20 09:45:09 -07002#
Jan Tattermusch4d5c3102017-06-07 10:23:56 +02003# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
Craig Tiller423ecff2016-10-20 09:45:09 -07006#
Jan Tattermusch4d5c3102017-06-07 10:23:56 +02007# http://www.apache.org/licenses/LICENSE-2.0
Craig Tiller423ecff2016-10-20 09:45:09 -07008#
Jan Tattermusch4d5c3102017-06-07 10:23:56 +02009# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
Craig Tiller423ecff2016-10-20 09:45:09 -070014
Nicolas "Pixel" Noblee8dbd8a2016-10-20 18:54:36 +020015#
16# This is for the gRPC build system. This isn't intended to be used outsite of
17# the BUILD file for gRPC. It contains the mapping for the template system we
18# use to generate other platform's build system files.
19#
Craig Tillerf66de6e2017-05-15 08:29:10 -070020# Please consider that there should be a high bar for additions and changes to
21# this file.
22# Each rule listed must be re-written for Google's internal build system, and
23# each change must be ported from one to the other.
24#
Nicolas "Pixel" Noblee8dbd8a2016-10-20 18:54:36 +020025
Craig Tiller360712f2017-10-18 10:05:21 -070026# The set of pollers to test against if a test exercises polling
Bill Feng2fa4d432018-08-27 10:03:03 -070027POLLERS = ["epollex", "epollsig", "epoll1", "poll", "poll-cv"]
Craig Tiller360712f2017-10-18 10:05:21 -070028
Loo Rong Jiee97c2302018-01-10 17:35:34 +080029def if_not_windows(a):
Bill Feng2fa4d432018-08-27 10:03:03 -070030 return select({
31 "//:windows": [],
32 "//:windows_msvc": [],
33 "//conditions:default": a,
34 })
Loo Rong Jiee97c2302018-01-10 17:35:34 +080035
Alexander Polcyn54a70402017-11-29 17:06:16 -080036def _get_external_deps(external_deps):
Bill Feng2fa4d432018-08-27 10:03:03 -070037 ret = []
38 for dep in external_deps:
39 if dep == "address_sorting":
40 ret += ["//third_party/address_sorting"]
41 elif dep == "cares":
42 ret += select({
43 "//:grpc_no_ares": [],
44 "//conditions:default": ["//external:cares"],
45 })
46 else:
47 ret += ["//external:" + dep]
48 return ret
Alexander Polcyn54a70402017-11-29 17:06:16 -080049
50def _maybe_update_cc_library_hdrs(hdrs):
Bill Feng2fa4d432018-08-27 10:03:03 -070051 ret = []
52 hdrs_to_update = {
53 "third_party/objective_c/Cronet/bidirectional_stream_c.h": "//third_party:objective_c/Cronet/bidirectional_stream_c.h",
54 }
55 for h in hdrs:
56 if h in hdrs_to_update.keys():
57 ret.append(hdrs_to_update[h])
58 else:
59 ret.append(h)
60 return ret
Alexander Polcyn54a70402017-11-29 17:06:16 -080061
Bill Feng2fa4d432018-08-27 10:03:03 -070062def grpc_cc_library(
63 name,
64 srcs = [],
65 public_hdrs = [],
66 hdrs = [],
67 external_deps = [],
68 deps = [],
69 standalone = False,
70 language = "C++",
71 testonly = False,
72 visibility = None,
73 alwayslink = 0,
74 data = []):
75 copts = []
76 if language.upper() == "C":
77 copts = if_not_windows(["-std=c99"])
78 native.cc_library(
79 name = name,
80 srcs = srcs,
81 defines = select({
82 "//:grpc_no_ares": ["GRPC_ARES=0"],
83 "//conditions:default": [],
84 }) +
85 select({
86 "//:remote_execution": ["GRPC_PORT_ISOLATED_RUNTIME=1"],
87 "//conditions:default": [],
88 }) +
89 select({
90 "//:grpc_allow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=1"],
91 "//:grpc_disallow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=0"],
92 "//conditions:default": [],
93 }),
94 hdrs = _maybe_update_cc_library_hdrs(hdrs + public_hdrs),
95 deps = deps + _get_external_deps(external_deps),
96 copts = copts,
97 visibility = visibility,
98 testonly = testonly,
99 linkopts = if_not_windows(["-pthread"]),
100 includes = [
101 "include",
102 ],
103 alwayslink = alwayslink,
104 data = data,
105 )
Nicolas "Pixel" Noble4dc64312016-10-20 23:07:37 +0200106
Vijay Pai4fdb08a2017-11-14 16:48:45 -0800107def grpc_proto_plugin(name, srcs = [], deps = []):
Bill Feng2fa4d432018-08-27 10:03:03 -0700108 native.cc_binary(
109 name = name,
110 srcs = srcs,
111 deps = deps,
112 )
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +0200113
114load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library")
115
Bill Feng2fa4d432018-08-27 10:03:03 -0700116def grpc_proto_library(
117 name,
118 srcs = [],
119 deps = [],
120 well_known_protos = False,
121 has_services = True,
122 use_external = False,
123 generate_mocks = False):
124 cc_grpc_library(
125 name = name,
126 srcs = srcs,
127 deps = deps,
128 well_known_protos = well_known_protos,
129 proto_only = not has_services,
130 use_external = use_external,
131 generate_mocks = generate_mocks,
132 )
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +0200133
Adele Zhouff1d1b32018-06-11 14:46:36 -0700134def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data = [], uses_polling = True, language = "C++", size = "medium", timeout = "moderate", tags = []):
Bill Feng2fa4d432018-08-27 10:03:03 -0700135 copts = []
136 if language.upper() == "C":
137 copts = if_not_windows(["-std=c99"])
138 args = {
139 "name": name,
140 "srcs": srcs,
141 "args": args,
142 "data": data,
143 "deps": deps + _get_external_deps(external_deps),
144 "copts": copts,
145 "linkopts": if_not_windows(["-pthread"]),
146 "size": size,
147 "timeout": timeout,
148 }
149 if uses_polling:
150 native.cc_test(testonly = True, tags = ["manual"], **args)
151 for poller in POLLERS:
152 native.sh_test(
153 name = name + "@poller=" + poller,
154 data = [name] + data,
155 srcs = [
156 "//test/core/util:run_with_poller_sh",
157 ],
158 size = size,
159 timeout = timeout,
160 args = [
161 poller,
162 "$(location %s)" % name,
163 ] + args["args"],
164 tags = tags,
165 )
166 else:
167 native.cc_test(**args)
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +0200168
Vijay Pai42807252017-07-28 15:08:24 -0700169def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++", testonly = False, linkshared = False, linkopts = []):
Bill Feng2fa4d432018-08-27 10:03:03 -0700170 copts = []
171 if language.upper() == "C":
172 copts = ["-std=c99"]
173 native.cc_binary(
174 name = name,
175 srcs = srcs,
176 args = args,
177 data = data,
178 testonly = testonly,
179 linkshared = linkshared,
180 deps = deps + _get_external_deps(external_deps),
181 copts = copts,
182 linkopts = if_not_windows(["-pthread"]) + linkopts,
183 )
Nicolas "Pixel" Noble2b0f0012017-04-24 19:59:19 +0200184
Bill Feng2fa4d432018-08-27 10:03:03 -0700185def grpc_generate_one_off_targets():
186 pass
David Garcia Quintas3351fe32018-05-31 17:20:56 -0700187
Nicolas "Pixel" Noble3bd81772017-04-25 22:23:40 +0200188def grpc_sh_test(name, srcs, args = [], data = []):
Bill Feng2fa4d432018-08-27 10:03:03 -0700189 native.sh_test(
190 name = name,
191 srcs = srcs,
192 args = args,
193 data = data,
194 )
Nicolas "Pixel" Noble2bc5e3a2017-08-15 22:32:52 +0200195
Alexander Polcyn27bf05d2017-08-07 18:09:11 -0700196def grpc_sh_binary(name, srcs, data = []):
Bill Feng2fa4d432018-08-27 10:03:03 -0700197 native.sh_binary(
198 name = name,
199 srcs = srcs,
200 data = data,
201 )
Alexander Polcyn27bf05d2017-08-07 18:09:11 -0700202
Alexander Polcyn092f1992018-03-06 10:28:35 -0800203def grpc_py_binary(name, srcs, data = [], deps = [], external_deps = [], testonly = False):
Bill Feng2fa4d432018-08-27 10:03:03 -0700204 native.py_binary(
205 name = name,
206 srcs = srcs,
207 testonly = testonly,
208 data = data,
209 deps = deps + _get_external_deps(external_deps),
210 )
Alexander Polcyn27bf05d2017-08-07 18:09:11 -0700211
yang-g109040f2017-08-30 21:33:31 -0700212def grpc_package(name, visibility = "private", features = []):
Bill Feng2fa4d432018-08-27 10:03:03 -0700213 if visibility == "tests":
214 visibility = ["//test:__subpackages__"]
215 elif visibility == "public":
216 visibility = ["//visibility:public"]
217 elif visibility == "private":
218 visibility = []
219 else:
220 fail("Unknown visibility " + visibility)
Nicolas "Pixel" Noble2bc5e3a2017-08-15 22:32:52 +0200221
Bill Feng2fa4d432018-08-27 10:03:03 -0700222 if len(visibility) != 0:
223 native.package(
224 default_visibility = visibility,
225 features = features,
226 )