blob: 9a3b76134455a464b7c0511a9aacdb8e82a11e5e [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
27POLLERS = ['epollex', 'epollsig', 'epoll1', 'poll', 'poll-cv']
28
Alexander Polcyn54a70402017-11-29 17:06:16 -080029def _get_external_deps(external_deps):
30 ret = []
31 for dep in external_deps:
32 if dep == "nanopb":
33 ret.append("//third_party/nanopb")
Alexander Polcynf1b933c2018-01-11 09:47:18 -080034 elif dep == "cares":
35 ret += select({"//:grpc_no_ares": [],
36 "//conditions:default": ["//external:cares"],})
Alexander Polcyn54a70402017-11-29 17:06:16 -080037 else:
38 ret.append("//external:" + dep)
39 return ret
40
41def _maybe_update_cc_library_hdrs(hdrs):
42 ret = []
43 hdrs_to_update = {
44 "third_party/objective_c/Cronet/bidirectional_stream_c.h": "//third_party:objective_c/Cronet/bidirectional_stream_c.h",
45 }
46 for h in hdrs:
47 if h in hdrs_to_update.keys():
48 ret.append(hdrs_to_update[h])
49 else:
50 ret.append(h)
51 return ret
52
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020053def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [],
54 external_deps = [], deps = [], standalone = False,
Ian Coolidge6b08cf42017-06-16 12:56:23 -070055 language = "C++", testonly = False, visibility = None,
Adele Zhoue5df91f2017-11-29 14:37:18 -080056 alwayslink = 0):
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020057 copts = []
Craig Tiller674c66c2016-10-20 13:08:52 -070058 if language.upper() == "C":
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020059 copts = ["-std=c99"]
60 native.cc_library(
61 name = name,
62 srcs = srcs,
Adele Zhoue5df91f2017-11-29 14:37:18 -080063 defines = select({"//:grpc_no_ares": ["GRPC_ARES=0"],
64 "//conditions:default": [],}) +
Adele Zhou5b7cdef2017-11-29 16:25:17 -080065 select({"//:remote_execution": ["GRPC_PORT_ISOLATED_RUNTIME=1"],
Adele Zhoue5df91f2017-11-29 14:37:18 -080066 "//conditions:default": [],}),
Alexander Polcyn54a70402017-11-29 17:06:16 -080067 hdrs = _maybe_update_cc_library_hdrs(hdrs + public_hdrs),
68 deps = deps + _get_external_deps(external_deps),
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020069 copts = copts,
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020070 visibility = visibility,
71 testonly = testonly,
Nicolas "Pixel" Noble60ca22f2016-10-20 10:23:53 +020072 linkopts = ["-pthread"],
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020073 includes = [
74 "include"
Ian Coolidge6b08cf42017-06-16 12:56:23 -070075 ],
76 alwayslink = alwayslink,
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020077 )
Nicolas "Pixel" Noble4dc64312016-10-20 23:07:37 +020078
Vijay Pai4fdb08a2017-11-14 16:48:45 -080079def grpc_proto_plugin(name, srcs = [], deps = []):
Nicolas "Pixel" Noble4dc64312016-10-20 23:07:37 +020080 native.cc_binary(
81 name = name,
Vijay Pai4fdb08a2017-11-14 16:48:45 -080082 srcs = srcs,
Nicolas "Pixel" Noble4dc64312016-10-20 23:07:37 +020083 deps = deps,
84 )
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020085
86load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library")
87
Craig Tillera7533712017-05-16 13:09:33 -070088def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = False,
Mahak Mukhi443a75d2017-04-14 15:33:55 -070089 has_services = True, use_external = False, generate_mock = False):
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020090 cc_grpc_library(
91 name = name,
92 srcs = srcs,
93 deps = deps,
Makarand Dharmapurikare3e3b2a2017-03-07 16:12:56 -080094 well_known_protos = well_known_protos,
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020095 proto_only = not has_services,
Makarand Dharmapurikar9098fcc2017-03-02 17:13:10 -080096 use_external = use_external,
Mahak Mukhi443a75d2017-04-14 15:33:55 -070097 generate_mock = generate_mock,
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020098 )
99
Craig Tiller360712f2017-10-18 10:05:21 -0700100def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data = [], uses_polling = True, language = "C++"):
Craig Tillerf66de6e2017-05-15 08:29:10 -0700101 copts = []
102 if language.upper() == "C":
103 copts = ["-std=c99"]
Craig Tiller360712f2017-10-18 10:05:21 -0700104 args = {
105 'name': name,
106 'srcs': srcs,
107 'args': args,
108 'data': data,
Alexander Polcyn54a70402017-11-29 17:06:16 -0800109 'deps': deps + _get_external_deps(external_deps),
Craig Tiller360712f2017-10-18 10:05:21 -0700110 'copts': copts,
111 'linkopts': ["-pthread"],
112 }
113 if uses_polling:
Craig Tillere55fb8a2017-12-07 11:40:18 -0800114 native.cc_test(testonly=True, tags=['manual'], **args)
Craig Tiller360712f2017-10-18 10:05:21 -0700115 for poller in POLLERS:
116 native.sh_test(
117 name = name + '@poller=' + poller,
118 data = [name],
119 srcs = [
120 '//test/core/util:run_with_poller_sh',
121 ],
122 args = [
123 poller,
124 '$(location %s)' % name
Alexander Polcynb94346f2017-12-11 16:03:40 -0800125 ] + args['args'],
Craig Tiller360712f2017-10-18 10:05:21 -0700126 )
127 else:
128 native.cc_test(**args)
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +0200129
Vijay Pai42807252017-07-28 15:08:24 -0700130def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++", testonly = False, linkshared = False, linkopts = []):
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +0200131 copts = []
132 if language.upper() == "C":
133 copts = ["-std=c99"]
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +0200134 native.cc_binary(
135 name = name,
136 srcs = srcs,
137 args = args,
138 data = data,
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +0200139 testonly = testonly,
Nicolas "Pixel" Nobled69f7762017-05-12 17:10:13 +0200140 linkshared = linkshared,
Alexander Polcyn54a70402017-11-29 17:06:16 -0800141 deps = deps + _get_external_deps(external_deps),
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +0200142 copts = copts,
Vijay Pai42807252017-07-28 15:08:24 -0700143 linkopts = ["-pthread"] + linkopts,
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +0200144 )
Nicolas "Pixel" Noble2b0f0012017-04-24 19:59:19 +0200145
146def grpc_generate_one_off_targets():
Nicolas "Pixel" Noble3dedf652017-05-24 02:29:02 +0200147 pass
Nicolas "Pixel" Noble3bd81772017-04-25 22:23:40 +0200148
149def grpc_sh_test(name, srcs, args = [], data = []):
Nicolas "Pixel" Noble3dedf652017-05-24 02:29:02 +0200150 native.sh_test(
151 name = name,
152 srcs = srcs,
153 args = args,
154 data = data)
Nicolas "Pixel" Noble2bc5e3a2017-08-15 22:32:52 +0200155
Alexander Polcyn27bf05d2017-08-07 18:09:11 -0700156def grpc_sh_binary(name, srcs, data = []):
157 native.sh_test(
158 name = name,
159 srcs = srcs,
160 data = data)
161
162def grpc_py_binary(name, srcs, data = [], deps = []):
163 if name == "test_dns_server":
164 # TODO: allow running test_dns_server in oss bazel test suite
165 deps = []
166 native.py_binary(
167 name = name,
168 srcs = srcs,
169 data = data,
170 deps = deps)
171
yang-g109040f2017-08-30 21:33:31 -0700172def grpc_package(name, visibility = "private", features = []):
Nicolas "Pixel" Noble2bc5e3a2017-08-15 22:32:52 +0200173 if visibility == "tests":
174 visibility = ["//test:__subpackages__"]
175 elif visibility == "public":
176 visibility = ["//visibility:public"]
177 elif visibility == "private":
178 visibility = []
179 else:
180 fail("Unknown visibility " + visibility)
181
182 if len(visibility) != 0:
183 native.package(
yang-g109040f2017-08-30 21:33:31 -0700184 default_visibility = visibility,
185 features = features
Nicolas "Pixel" Noble2bc5e3a2017-08-15 22:32:52 +0200186 )