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 |
| 27 | POLLERS = ['epollex', 'epollsig', 'epoll1', 'poll', 'poll-cv'] |
| 28 | |
Loo Rong Jie | e97c230 | 2018-01-10 17:35:34 +0800 | [diff] [blame^] | 29 | def if_not_windows(a): |
| 30 | return select({ |
| 31 | "//:windows": [], |
| 32 | "//:windows_msvc": [], |
| 33 | "//conditions:default": a, |
| 34 | }) |
| 35 | |
Alexander Polcyn | 54a7040 | 2017-11-29 17:06:16 -0800 | [diff] [blame] | 36 | def _get_external_deps(external_deps): |
| 37 | ret = [] |
| 38 | for dep in external_deps: |
| 39 | if dep == "nanopb": |
Alexander Polcyn | 9df154c | 2018-01-12 11:44:08 -0800 | [diff] [blame] | 40 | ret += ["//third_party/nanopb"] |
Alexander Polcyn | f1b933c | 2018-01-11 09:47:18 -0800 | [diff] [blame] | 41 | elif dep == "cares": |
| 42 | ret += select({"//:grpc_no_ares": [], |
| 43 | "//conditions:default": ["//external:cares"],}) |
Alexander Polcyn | 54a7040 | 2017-11-29 17:06:16 -0800 | [diff] [blame] | 44 | else: |
Alexander Polcyn | 9df154c | 2018-01-12 11:44:08 -0800 | [diff] [blame] | 45 | ret += ["//external:" + dep] |
Alexander Polcyn | 54a7040 | 2017-11-29 17:06:16 -0800 | [diff] [blame] | 46 | return ret |
| 47 | |
| 48 | def _maybe_update_cc_library_hdrs(hdrs): |
| 49 | ret = [] |
| 50 | hdrs_to_update = { |
| 51 | "third_party/objective_c/Cronet/bidirectional_stream_c.h": "//third_party:objective_c/Cronet/bidirectional_stream_c.h", |
| 52 | } |
| 53 | for h in hdrs: |
| 54 | if h in hdrs_to_update.keys(): |
| 55 | ret.append(hdrs_to_update[h]) |
| 56 | else: |
| 57 | ret.append(h) |
| 58 | return ret |
| 59 | |
Nicolas "Pixel" Noble | 15cd5ce | 2017-04-18 06:32:11 +0200 | [diff] [blame] | 60 | def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [], |
| 61 | external_deps = [], deps = [], standalone = False, |
Ian Coolidge | 6b08cf4 | 2017-06-16 12:56:23 -0700 | [diff] [blame] | 62 | language = "C++", testonly = False, visibility = None, |
Adele Zhou | e5df91f | 2017-11-29 14:37:18 -0800 | [diff] [blame] | 63 | alwayslink = 0): |
Nicolas "Pixel" Noble | 31d11db | 2016-10-20 09:29:46 +0200 | [diff] [blame] | 64 | copts = [] |
Craig Tiller | 674c66c | 2016-10-20 13:08:52 -0700 | [diff] [blame] | 65 | if language.upper() == "C": |
Loo Rong Jie | e97c230 | 2018-01-10 17:35:34 +0800 | [diff] [blame^] | 66 | copts = if_not_windows(["-std=c99"]) |
Nicolas "Pixel" Noble | 31d11db | 2016-10-20 09:29:46 +0200 | [diff] [blame] | 67 | native.cc_library( |
| 68 | name = name, |
| 69 | srcs = srcs, |
Adele Zhou | e5df91f | 2017-11-29 14:37:18 -0800 | [diff] [blame] | 70 | defines = select({"//:grpc_no_ares": ["GRPC_ARES=0"], |
| 71 | "//conditions:default": [],}) + |
Adele Zhou | 5b7cdef | 2017-11-29 16:25:17 -0800 | [diff] [blame] | 72 | select({"//:remote_execution": ["GRPC_PORT_ISOLATED_RUNTIME=1"], |
Vijay Pai | 37abc4a | 2017-12-19 09:20:50 -0800 | [diff] [blame] | 73 | "//conditions:default": [],}) + |
Vijay Pai | 9809ce3 | 2017-12-19 09:09:52 -0800 | [diff] [blame] | 74 | select({"//:grpc_allow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=1"], |
| 75 | "//:grpc_disallow_exceptions": |
| 76 | ["GRPC_ALLOW_EXCEPTIONS=0"], |
Adele Zhou | e5df91f | 2017-11-29 14:37:18 -0800 | [diff] [blame] | 77 | "//conditions:default": [],}), |
Alexander Polcyn | 54a7040 | 2017-11-29 17:06:16 -0800 | [diff] [blame] | 78 | hdrs = _maybe_update_cc_library_hdrs(hdrs + public_hdrs), |
| 79 | deps = deps + _get_external_deps(external_deps), |
Nicolas "Pixel" Noble | 31d11db | 2016-10-20 09:29:46 +0200 | [diff] [blame] | 80 | copts = copts, |
Nicolas "Pixel" Noble | 15cd5ce | 2017-04-18 06:32:11 +0200 | [diff] [blame] | 81 | visibility = visibility, |
| 82 | testonly = testonly, |
Loo Rong Jie | e97c230 | 2018-01-10 17:35:34 +0800 | [diff] [blame^] | 83 | linkopts = if_not_windows(["-pthread"]), |
Nicolas "Pixel" Noble | 31d11db | 2016-10-20 09:29:46 +0200 | [diff] [blame] | 84 | includes = [ |
| 85 | "include" |
Ian Coolidge | 6b08cf4 | 2017-06-16 12:56:23 -0700 | [diff] [blame] | 86 | ], |
| 87 | alwayslink = alwayslink, |
Nicolas "Pixel" Noble | 31d11db | 2016-10-20 09:29:46 +0200 | [diff] [blame] | 88 | ) |
Nicolas "Pixel" Noble | 4dc6431 | 2016-10-20 23:07:37 +0200 | [diff] [blame] | 89 | |
Vijay Pai | 4fdb08a | 2017-11-14 16:48:45 -0800 | [diff] [blame] | 90 | def grpc_proto_plugin(name, srcs = [], deps = []): |
Nicolas "Pixel" Noble | 4dc6431 | 2016-10-20 23:07:37 +0200 | [diff] [blame] | 91 | native.cc_binary( |
| 92 | name = name, |
Vijay Pai | 4fdb08a | 2017-11-14 16:48:45 -0800 | [diff] [blame] | 93 | srcs = srcs, |
Nicolas "Pixel" Noble | 4dc6431 | 2016-10-20 23:07:37 +0200 | [diff] [blame] | 94 | deps = deps, |
| 95 | ) |
Nicolas "Pixel" Noble | 799bd5e | 2016-10-21 01:54:32 +0200 | [diff] [blame] | 96 | |
| 97 | load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library") |
| 98 | |
Craig Tiller | a753371 | 2017-05-16 13:09:33 -0700 | [diff] [blame] | 99 | def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = False, |
Mahak Mukhi | 443a75d | 2017-04-14 15:33:55 -0700 | [diff] [blame] | 100 | has_services = True, use_external = False, generate_mock = False): |
Nicolas "Pixel" Noble | 799bd5e | 2016-10-21 01:54:32 +0200 | [diff] [blame] | 101 | cc_grpc_library( |
| 102 | name = name, |
| 103 | srcs = srcs, |
| 104 | deps = deps, |
Makarand Dharmapurikar | e3e3b2a | 2017-03-07 16:12:56 -0800 | [diff] [blame] | 105 | well_known_protos = well_known_protos, |
Nicolas "Pixel" Noble | 799bd5e | 2016-10-21 01:54:32 +0200 | [diff] [blame] | 106 | proto_only = not has_services, |
Makarand Dharmapurikar | 9098fcc | 2017-03-02 17:13:10 -0800 | [diff] [blame] | 107 | use_external = use_external, |
Mahak Mukhi | 443a75d | 2017-04-14 15:33:55 -0700 | [diff] [blame] | 108 | generate_mock = generate_mock, |
Nicolas "Pixel" Noble | 799bd5e | 2016-10-21 01:54:32 +0200 | [diff] [blame] | 109 | ) |
| 110 | |
Craig Tiller | 360712f | 2017-10-18 10:05:21 -0700 | [diff] [blame] | 111 | def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data = [], uses_polling = True, language = "C++"): |
Craig Tiller | f66de6e | 2017-05-15 08:29:10 -0700 | [diff] [blame] | 112 | copts = [] |
| 113 | if language.upper() == "C": |
Loo Rong Jie | e97c230 | 2018-01-10 17:35:34 +0800 | [diff] [blame^] | 114 | copts = if_not_windows(["-std=c99"]) |
Craig Tiller | 360712f | 2017-10-18 10:05:21 -0700 | [diff] [blame] | 115 | args = { |
| 116 | 'name': name, |
| 117 | 'srcs': srcs, |
| 118 | 'args': args, |
| 119 | 'data': data, |
Alexander Polcyn | 54a7040 | 2017-11-29 17:06:16 -0800 | [diff] [blame] | 120 | 'deps': deps + _get_external_deps(external_deps), |
Craig Tiller | 360712f | 2017-10-18 10:05:21 -0700 | [diff] [blame] | 121 | 'copts': copts, |
Loo Rong Jie | e97c230 | 2018-01-10 17:35:34 +0800 | [diff] [blame^] | 122 | 'linkopts': if_not_windows(["-pthread"]), |
Craig Tiller | 360712f | 2017-10-18 10:05:21 -0700 | [diff] [blame] | 123 | } |
| 124 | if uses_polling: |
Craig Tiller | e55fb8a | 2017-12-07 11:40:18 -0800 | [diff] [blame] | 125 | native.cc_test(testonly=True, tags=['manual'], **args) |
Craig Tiller | 360712f | 2017-10-18 10:05:21 -0700 | [diff] [blame] | 126 | for poller in POLLERS: |
| 127 | native.sh_test( |
| 128 | name = name + '@poller=' + poller, |
| 129 | data = [name], |
| 130 | srcs = [ |
| 131 | '//test/core/util:run_with_poller_sh', |
| 132 | ], |
| 133 | args = [ |
| 134 | poller, |
| 135 | '$(location %s)' % name |
Alexander Polcyn | b94346f | 2017-12-11 16:03:40 -0800 | [diff] [blame] | 136 | ] + args['args'], |
Craig Tiller | 360712f | 2017-10-18 10:05:21 -0700 | [diff] [blame] | 137 | ) |
| 138 | else: |
| 139 | native.cc_test(**args) |
Nicolas "Pixel" Noble | 7c26eed | 2017-04-13 01:40:54 +0200 | [diff] [blame] | 140 | |
Vijay Pai | 4280725 | 2017-07-28 15:08:24 -0700 | [diff] [blame] | 141 | def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++", testonly = False, linkshared = False, linkopts = []): |
Nicolas "Pixel" Noble | 15cd5ce | 2017-04-18 06:32:11 +0200 | [diff] [blame] | 142 | copts = [] |
| 143 | if language.upper() == "C": |
| 144 | copts = ["-std=c99"] |
Nicolas "Pixel" Noble | 7c26eed | 2017-04-13 01:40:54 +0200 | [diff] [blame] | 145 | native.cc_binary( |
| 146 | name = name, |
| 147 | srcs = srcs, |
| 148 | args = args, |
| 149 | data = data, |
Nicolas "Pixel" Noble | 15cd5ce | 2017-04-18 06:32:11 +0200 | [diff] [blame] | 150 | testonly = testonly, |
Nicolas "Pixel" Noble | d69f776 | 2017-05-12 17:10:13 +0200 | [diff] [blame] | 151 | linkshared = linkshared, |
Alexander Polcyn | 54a7040 | 2017-11-29 17:06:16 -0800 | [diff] [blame] | 152 | deps = deps + _get_external_deps(external_deps), |
Nicolas "Pixel" Noble | 15cd5ce | 2017-04-18 06:32:11 +0200 | [diff] [blame] | 153 | copts = copts, |
Loo Rong Jie | e97c230 | 2018-01-10 17:35:34 +0800 | [diff] [blame^] | 154 | linkopts = if_not_windows(["-pthread"]) + linkopts, |
Nicolas "Pixel" Noble | 7c26eed | 2017-04-13 01:40:54 +0200 | [diff] [blame] | 155 | ) |
Nicolas "Pixel" Noble | 2b0f001 | 2017-04-24 19:59:19 +0200 | [diff] [blame] | 156 | |
| 157 | def grpc_generate_one_off_targets(): |
Nicolas "Pixel" Noble | 3dedf65 | 2017-05-24 02:29:02 +0200 | [diff] [blame] | 158 | pass |
Nicolas "Pixel" Noble | 3bd8177 | 2017-04-25 22:23:40 +0200 | [diff] [blame] | 159 | |
| 160 | def grpc_sh_test(name, srcs, args = [], data = []): |
Nicolas "Pixel" Noble | 3dedf65 | 2017-05-24 02:29:02 +0200 | [diff] [blame] | 161 | native.sh_test( |
| 162 | name = name, |
| 163 | srcs = srcs, |
| 164 | args = args, |
| 165 | data = data) |
Nicolas "Pixel" Noble | 2bc5e3a | 2017-08-15 22:32:52 +0200 | [diff] [blame] | 166 | |
Alexander Polcyn | 27bf05d | 2017-08-07 18:09:11 -0700 | [diff] [blame] | 167 | def grpc_sh_binary(name, srcs, data = []): |
Adele Zhou | 8fe2531 | 2018-01-30 16:08:03 -0800 | [diff] [blame] | 168 | native.sh_binary( |
Alexander Polcyn | 27bf05d | 2017-08-07 18:09:11 -0700 | [diff] [blame] | 169 | name = name, |
| 170 | srcs = srcs, |
| 171 | data = data) |
| 172 | |
| 173 | def grpc_py_binary(name, srcs, data = [], deps = []): |
| 174 | if name == "test_dns_server": |
| 175 | # TODO: allow running test_dns_server in oss bazel test suite |
| 176 | deps = [] |
| 177 | native.py_binary( |
| 178 | name = name, |
| 179 | srcs = srcs, |
| 180 | data = data, |
| 181 | deps = deps) |
| 182 | |
yang-g | 109040f | 2017-08-30 21:33:31 -0700 | [diff] [blame] | 183 | def grpc_package(name, visibility = "private", features = []): |
Nicolas "Pixel" Noble | 2bc5e3a | 2017-08-15 22:32:52 +0200 | [diff] [blame] | 184 | if visibility == "tests": |
| 185 | visibility = ["//test:__subpackages__"] |
| 186 | elif visibility == "public": |
| 187 | visibility = ["//visibility:public"] |
| 188 | elif visibility == "private": |
| 189 | visibility = [] |
| 190 | else: |
| 191 | fail("Unknown visibility " + visibility) |
| 192 | |
| 193 | if len(visibility) != 0: |
| 194 | native.package( |
yang-g | 109040f | 2017-08-30 21:33:31 -0700 | [diff] [blame] | 195 | default_visibility = visibility, |
| 196 | features = features |
Nicolas "Pixel" Noble | 2bc5e3a | 2017-08-15 22:32:52 +0200 | [diff] [blame] | 197 | ) |