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 | |
Nicolas "Pixel" Noble | 15cd5ce | 2017-04-18 06:32:11 +0200 | [diff] [blame] | 29 | def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [], |
| 30 | external_deps = [], deps = [], standalone = False, |
Ian Coolidge | 6b08cf4 | 2017-06-16 12:56:23 -0700 | [diff] [blame] | 31 | language = "C++", testonly = False, visibility = None, |
Adele Zhou | e5df91f | 2017-11-29 14:37:18 -0800 | [diff] [blame] | 32 | alwayslink = 0): |
Nicolas "Pixel" Noble | 31d11db | 2016-10-20 09:29:46 +0200 | [diff] [blame] | 33 | copts = [] |
Craig Tiller | 674c66c | 2016-10-20 13:08:52 -0700 | [diff] [blame] | 34 | if language.upper() == "C": |
Nicolas "Pixel" Noble | 31d11db | 2016-10-20 09:29:46 +0200 | [diff] [blame] | 35 | copts = ["-std=c99"] |
| 36 | native.cc_library( |
| 37 | name = name, |
| 38 | srcs = srcs, |
Adele Zhou | e5df91f | 2017-11-29 14:37:18 -0800 | [diff] [blame] | 39 | defines = select({"//:grpc_no_ares": ["GRPC_ARES=0"], |
| 40 | "//conditions:default": [],}) + |
Adele Zhou | 5b7cdef | 2017-11-29 16:25:17 -0800 | [diff] [blame] | 41 | select({"//:remote_execution": ["GRPC_PORT_ISOLATED_RUNTIME=1"], |
Adele Zhou | e5df91f | 2017-11-29 14:37:18 -0800 | [diff] [blame] | 42 | "//conditions:default": [],}), |
Nicolas "Pixel" Noble | e8dbd8a | 2016-10-20 18:54:36 +0200 | [diff] [blame] | 43 | hdrs = hdrs + public_hdrs, |
| 44 | deps = deps + ["//external:" + dep for dep in external_deps], |
Nicolas "Pixel" Noble | 31d11db | 2016-10-20 09:29:46 +0200 | [diff] [blame] | 45 | copts = copts, |
Nicolas "Pixel" Noble | 15cd5ce | 2017-04-18 06:32:11 +0200 | [diff] [blame] | 46 | visibility = visibility, |
| 47 | testonly = testonly, |
Nicolas "Pixel" Noble | 60ca22f | 2016-10-20 10:23:53 +0200 | [diff] [blame] | 48 | linkopts = ["-pthread"], |
Nicolas "Pixel" Noble | 31d11db | 2016-10-20 09:29:46 +0200 | [diff] [blame] | 49 | includes = [ |
| 50 | "include" |
Ian Coolidge | 6b08cf4 | 2017-06-16 12:56:23 -0700 | [diff] [blame] | 51 | ], |
| 52 | alwayslink = alwayslink, |
Nicolas "Pixel" Noble | 31d11db | 2016-10-20 09:29:46 +0200 | [diff] [blame] | 53 | ) |
Nicolas "Pixel" Noble | 4dc6431 | 2016-10-20 23:07:37 +0200 | [diff] [blame] | 54 | |
Vijay Pai | 4fdb08a | 2017-11-14 16:48:45 -0800 | [diff] [blame] | 55 | def grpc_proto_plugin(name, srcs = [], deps = []): |
Nicolas "Pixel" Noble | 4dc6431 | 2016-10-20 23:07:37 +0200 | [diff] [blame] | 56 | native.cc_binary( |
| 57 | name = name, |
Vijay Pai | 4fdb08a | 2017-11-14 16:48:45 -0800 | [diff] [blame] | 58 | srcs = srcs, |
Nicolas "Pixel" Noble | 4dc6431 | 2016-10-20 23:07:37 +0200 | [diff] [blame] | 59 | deps = deps, |
| 60 | ) |
Nicolas "Pixel" Noble | 799bd5e | 2016-10-21 01:54:32 +0200 | [diff] [blame] | 61 | |
| 62 | load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library") |
| 63 | |
Craig Tiller | a753371 | 2017-05-16 13:09:33 -0700 | [diff] [blame] | 64 | def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = False, |
Mahak Mukhi | 443a75d | 2017-04-14 15:33:55 -0700 | [diff] [blame] | 65 | has_services = True, use_external = False, generate_mock = False): |
Nicolas "Pixel" Noble | 799bd5e | 2016-10-21 01:54:32 +0200 | [diff] [blame] | 66 | cc_grpc_library( |
| 67 | name = name, |
| 68 | srcs = srcs, |
| 69 | deps = deps, |
Makarand Dharmapurikar | e3e3b2a | 2017-03-07 16:12:56 -0800 | [diff] [blame] | 70 | well_known_protos = well_known_protos, |
Nicolas "Pixel" Noble | 799bd5e | 2016-10-21 01:54:32 +0200 | [diff] [blame] | 71 | proto_only = not has_services, |
Makarand Dharmapurikar | 9098fcc | 2017-03-02 17:13:10 -0800 | [diff] [blame] | 72 | use_external = use_external, |
Mahak Mukhi | 443a75d | 2017-04-14 15:33:55 -0700 | [diff] [blame] | 73 | generate_mock = generate_mock, |
Nicolas "Pixel" Noble | 799bd5e | 2016-10-21 01:54:32 +0200 | [diff] [blame] | 74 | ) |
| 75 | |
Craig Tiller | 360712f | 2017-10-18 10:05:21 -0700 | [diff] [blame] | 76 | 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] | 77 | copts = [] |
| 78 | if language.upper() == "C": |
| 79 | copts = ["-std=c99"] |
Craig Tiller | 360712f | 2017-10-18 10:05:21 -0700 | [diff] [blame] | 80 | args = { |
| 81 | 'name': name, |
| 82 | 'srcs': srcs, |
| 83 | 'args': args, |
| 84 | 'data': data, |
| 85 | 'deps': deps + ["//external:" + dep for dep in external_deps], |
| 86 | 'copts': copts, |
| 87 | 'linkopts': ["-pthread"], |
| 88 | } |
| 89 | if uses_polling: |
| 90 | native.cc_binary(testonly=True, **args) |
| 91 | for poller in POLLERS: |
| 92 | native.sh_test( |
| 93 | name = name + '@poller=' + poller, |
| 94 | data = [name], |
| 95 | srcs = [ |
| 96 | '//test/core/util:run_with_poller_sh', |
| 97 | ], |
| 98 | args = [ |
| 99 | poller, |
| 100 | '$(location %s)' % name |
| 101 | ], |
| 102 | ) |
| 103 | else: |
| 104 | native.cc_test(**args) |
Nicolas "Pixel" Noble | 7c26eed | 2017-04-13 01:40:54 +0200 | [diff] [blame] | 105 | |
Vijay Pai | 4280725 | 2017-07-28 15:08:24 -0700 | [diff] [blame] | 106 | 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] | 107 | copts = [] |
| 108 | if language.upper() == "C": |
| 109 | copts = ["-std=c99"] |
Nicolas "Pixel" Noble | 7c26eed | 2017-04-13 01:40:54 +0200 | [diff] [blame] | 110 | native.cc_binary( |
| 111 | name = name, |
| 112 | srcs = srcs, |
| 113 | args = args, |
| 114 | data = data, |
Nicolas "Pixel" Noble | 15cd5ce | 2017-04-18 06:32:11 +0200 | [diff] [blame] | 115 | testonly = testonly, |
Nicolas "Pixel" Noble | d69f776 | 2017-05-12 17:10:13 +0200 | [diff] [blame] | 116 | linkshared = linkshared, |
Nicolas "Pixel" Noble | 7c26eed | 2017-04-13 01:40:54 +0200 | [diff] [blame] | 117 | deps = deps + ["//external:" + dep for dep in external_deps], |
Nicolas "Pixel" Noble | 15cd5ce | 2017-04-18 06:32:11 +0200 | [diff] [blame] | 118 | copts = copts, |
Vijay Pai | 4280725 | 2017-07-28 15:08:24 -0700 | [diff] [blame] | 119 | linkopts = ["-pthread"] + linkopts, |
Nicolas "Pixel" Noble | 7c26eed | 2017-04-13 01:40:54 +0200 | [diff] [blame] | 120 | ) |
Nicolas "Pixel" Noble | 2b0f001 | 2017-04-24 19:59:19 +0200 | [diff] [blame] | 121 | |
| 122 | def grpc_generate_one_off_targets(): |
Nicolas "Pixel" Noble | 3dedf65 | 2017-05-24 02:29:02 +0200 | [diff] [blame] | 123 | pass |
Nicolas "Pixel" Noble | 3bd8177 | 2017-04-25 22:23:40 +0200 | [diff] [blame] | 124 | |
| 125 | def grpc_sh_test(name, srcs, args = [], data = []): |
Nicolas "Pixel" Noble | 3dedf65 | 2017-05-24 02:29:02 +0200 | [diff] [blame] | 126 | native.sh_test( |
| 127 | name = name, |
| 128 | srcs = srcs, |
| 129 | args = args, |
| 130 | data = data) |
Nicolas "Pixel" Noble | 2bc5e3a | 2017-08-15 22:32:52 +0200 | [diff] [blame] | 131 | |
Alexander Polcyn | 27bf05d | 2017-08-07 18:09:11 -0700 | [diff] [blame] | 132 | def grpc_sh_binary(name, srcs, data = []): |
| 133 | native.sh_test( |
| 134 | name = name, |
| 135 | srcs = srcs, |
| 136 | data = data) |
| 137 | |
| 138 | def grpc_py_binary(name, srcs, data = [], deps = []): |
| 139 | if name == "test_dns_server": |
| 140 | # TODO: allow running test_dns_server in oss bazel test suite |
| 141 | deps = [] |
| 142 | native.py_binary( |
| 143 | name = name, |
| 144 | srcs = srcs, |
| 145 | data = data, |
| 146 | deps = deps) |
| 147 | |
yang-g | 109040f | 2017-08-30 21:33:31 -0700 | [diff] [blame] | 148 | def grpc_package(name, visibility = "private", features = []): |
Nicolas "Pixel" Noble | 2bc5e3a | 2017-08-15 22:32:52 +0200 | [diff] [blame] | 149 | if visibility == "tests": |
| 150 | visibility = ["//test:__subpackages__"] |
| 151 | elif visibility == "public": |
| 152 | visibility = ["//visibility:public"] |
| 153 | elif visibility == "private": |
| 154 | visibility = [] |
| 155 | else: |
| 156 | fail("Unknown visibility " + visibility) |
| 157 | |
| 158 | if len(visibility) != 0: |
| 159 | native.package( |
yang-g | 109040f | 2017-08-30 21:33:31 -0700 | [diff] [blame] | 160 | default_visibility = visibility, |
| 161 | features = features |
Nicolas "Pixel" Noble | 2bc5e3a | 2017-08-15 22:32:52 +0200 | [diff] [blame] | 162 | ) |