Jan Tattermusch | 4d5c310 | 2017-06-07 10:23:56 +0200 | [diff] [blame] | 1 | # Copyright 2016 gRPC authors. |
Craig Tiller | 423ecff | 2016-10-20 09:45:09 -0700 | [diff] [blame] | 2 | # |
Jan Tattermusch | 4d5c310 | 2017-06-07 10:23:56 +0200 | [diff] [blame] | 3 | # 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 Tiller | 423ecff | 2016-10-20 09:45:09 -0700 | [diff] [blame] | 6 | # |
Jan Tattermusch | 4d5c310 | 2017-06-07 10:23:56 +0200 | [diff] [blame] | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
Craig Tiller | 423ecff | 2016-10-20 09:45:09 -0700 | [diff] [blame] | 8 | # |
Jan Tattermusch | 4d5c310 | 2017-06-07 10:23:56 +0200 | [diff] [blame] | 9 | # 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 Tiller | 423ecff | 2016-10-20 09:45:09 -0700 | [diff] [blame] | 14 | |
Nicolas "Pixel" Noble | e8dbd8a | 2016-10-20 18:54:36 +0200 | [diff] [blame] | 15 | # |
| 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 Tiller | f66de6e | 2017-05-15 08:29:10 -0700 | [diff] [blame] | 20 | # 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" Noble | e8dbd8a | 2016-10-20 18:54:36 +0200 | [diff] [blame] | 25 | |
Craig Tiller | 360712f | 2017-10-18 10:05:21 -0700 | [diff] [blame] | 26 | # The set of pollers to test against if a test exercises polling |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 27 | POLLERS = ["epollex", "epollsig", "epoll1", "poll", "poll-cv"] |
Craig Tiller | 360712f | 2017-10-18 10:05:21 -0700 | [diff] [blame] | 28 | |
Loo Rong Jie | e97c230 | 2018-01-10 17:35:34 +0800 | [diff] [blame] | 29 | def if_not_windows(a): |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 30 | return select({ |
| 31 | "//:windows": [], |
| 32 | "//:windows_msvc": [], |
| 33 | "//conditions:default": a, |
| 34 | }) |
Loo Rong Jie | e97c230 | 2018-01-10 17:35:34 +0800 | [diff] [blame] | 35 | |
Alexander Polcyn | 54a7040 | 2017-11-29 17:06:16 -0800 | [diff] [blame] | 36 | def _get_external_deps(external_deps): |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 37 | 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 Polcyn | 54a7040 | 2017-11-29 17:06:16 -0800 | [diff] [blame] | 49 | |
| 50 | def _maybe_update_cc_library_hdrs(hdrs): |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 51 | 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 Polcyn | 54a7040 | 2017-11-29 17:06:16 -0800 | [diff] [blame] | 61 | |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 62 | def 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" Noble | 4dc6431 | 2016-10-20 23:07:37 +0200 | [diff] [blame] | 106 | |
Vijay Pai | 4fdb08a | 2017-11-14 16:48:45 -0800 | [diff] [blame] | 107 | def grpc_proto_plugin(name, srcs = [], deps = []): |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 108 | native.cc_binary( |
| 109 | name = name, |
| 110 | srcs = srcs, |
| 111 | deps = deps, |
| 112 | ) |
Nicolas "Pixel" Noble | 799bd5e | 2016-10-21 01:54:32 +0200 | [diff] [blame] | 113 | |
| 114 | load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library") |
| 115 | |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 116 | def 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" Noble | 799bd5e | 2016-10-21 01:54:32 +0200 | [diff] [blame] | 133 | |
Adele Zhou | ff1d1b3 | 2018-06-11 14:46:36 -0700 | [diff] [blame] | 134 | def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data = [], uses_polling = True, language = "C++", size = "medium", timeout = "moderate", tags = []): |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 135 | 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" Noble | 7c26eed | 2017-04-13 01:40:54 +0200 | [diff] [blame] | 168 | |
Vijay Pai | 4280725 | 2017-07-28 15:08:24 -0700 | [diff] [blame] | 169 | def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++", testonly = False, linkshared = False, linkopts = []): |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 170 | 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" Noble | 2b0f001 | 2017-04-24 19:59:19 +0200 | [diff] [blame] | 184 | |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 185 | def grpc_generate_one_off_targets(): |
| 186 | pass |
David Garcia Quintas | 3351fe3 | 2018-05-31 17:20:56 -0700 | [diff] [blame] | 187 | |
Nicolas "Pixel" Noble | 3bd8177 | 2017-04-25 22:23:40 +0200 | [diff] [blame] | 188 | def grpc_sh_test(name, srcs, args = [], data = []): |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 189 | native.sh_test( |
| 190 | name = name, |
| 191 | srcs = srcs, |
| 192 | args = args, |
| 193 | data = data, |
| 194 | ) |
Nicolas "Pixel" Noble | 2bc5e3a | 2017-08-15 22:32:52 +0200 | [diff] [blame] | 195 | |
Alexander Polcyn | 27bf05d | 2017-08-07 18:09:11 -0700 | [diff] [blame] | 196 | def grpc_sh_binary(name, srcs, data = []): |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 197 | native.sh_binary( |
| 198 | name = name, |
| 199 | srcs = srcs, |
| 200 | data = data, |
| 201 | ) |
Alexander Polcyn | 27bf05d | 2017-08-07 18:09:11 -0700 | [diff] [blame] | 202 | |
Alexander Polcyn | 092f199 | 2018-03-06 10:28:35 -0800 | [diff] [blame] | 203 | def grpc_py_binary(name, srcs, data = [], deps = [], external_deps = [], testonly = False): |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 204 | 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 Polcyn | 27bf05d | 2017-08-07 18:09:11 -0700 | [diff] [blame] | 211 | |
yang-g | 109040f | 2017-08-30 21:33:31 -0700 | [diff] [blame] | 212 | def grpc_package(name, visibility = "private", features = []): |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 213 | 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" Noble | 2bc5e3a | 2017-08-15 22:32:52 +0200 | [diff] [blame] | 221 | |
Bill Feng | 2fa4d43 | 2018-08-27 10:03:03 -0700 | [diff] [blame] | 222 | if len(visibility) != 0: |
| 223 | native.package( |
| 224 | default_visibility = visibility, |
| 225 | features = features, |
| 226 | ) |