1 # Copyright 2016 gRPC authors.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
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.
20 # Please consider that there should be a high bar for additions and changes to
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.
26 load("//bazel:cc_grpc_library.bzl", "cc_grpc_library")
27 load("//bazel:copts.bzl", "GRPC_DEFAULT_COPTS")
28 load("@upb//bazel:upb_proto_library.bzl", "upb_proto_library")
29 load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test")
31 # The set of pollers to test against if a test exercises polling
32 POLLERS = ["epollex", "epoll1", "poll"]
34 def if_not_windows(a):
37 "//:windows_msvc": [],
38 "//conditions:default": a,
44 "//conditions:default": [],
47 def _get_external_deps(external_deps):
49 for dep in external_deps:
50 if dep == "address_sorting":
51 ret += ["//third_party/address_sorting"]
54 "//:grpc_no_ares": [],
55 "//conditions:default": ["//external:cares"],
57 elif dep == "cronet_c_for_grpc":
58 ret += ["//third_party/objective_c/Cronet:cronet_c_for_grpc"]
59 elif dep.startswith("absl/"):
60 ret += ["@com_google_absl//" + dep]
62 ret += ["//external:" + dep]
84 copts = if_mac(["-DGRPC_CFSTREAM"])
85 if language.upper() == "C":
86 copts = copts + if_not_windows(["-std=c99"])
87 linkopts = if_not_windows(["-pthread"])
89 linkopts = linkopts + if_mac(["-framework CoreFoundation"])
92 deps += select(select_deps)
99 "//:grpc_no_ares": ["GRPC_ARES=0"],
100 "//conditions:default": [],
103 "//:remote_execution": ["GRPC_PORT_ISOLATED_RUNTIME=1"],
104 "//conditions:default": [],
107 "//:grpc_allow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=1"],
108 "//:grpc_disallow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=0"],
109 "//conditions:default": [],
111 hdrs = hdrs + public_hdrs,
112 deps = deps + _get_external_deps(external_deps),
113 copts = GRPC_DEFAULT_COPTS + copts,
114 visibility = visibility,
119 "src/core/ext/upb-generated", # Once upb code-gen issue is resolved, remove this.
120 "src/core/ext/upbdefs-generated", # Once upb code-gen issue is resolved, remove this.
122 alwayslink = alwayslink,
127 def grpc_proto_plugin(name, srcs = [], deps = []):
134 def grpc_proto_library(
138 well_known_protos = False,
140 use_external = False,
141 generate_mocks = False):
146 well_known_protos = well_known_protos,
147 proto_only = not has_services,
148 use_external = use_external,
149 generate_mocks = generate_mocks,
156 ios_test_adapter = "//third_party/objective_c/google_toolbox_for_mac:GTM_GoogleTestRunner_GTM_USING_XCTEST"
158 test_lib_ios = name + "_test_lib_ios"
159 ios_tags = tags + ["manual", "ios_cc_test"]
160 if not any([t for t in tags if t.startswith("no_test_ios")]):
163 srcs = kwargs.get("srcs"),
164 deps = kwargs.get("deps"),
165 copts = kwargs.get("copts"),
170 ios_test_deps = [ios_test_adapter, ":" + test_lib_ios]
172 name = name + "_on_ios",
173 size = kwargs.get("size"),
175 minimum_os_version = "9.0",
176 deps = ios_test_deps,
179 def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data = [], uses_polling = True, language = "C++", size = "medium", timeout = None, tags = [], exec_compatible_with = [], exec_properties = {}, shard_count = None, flaky = None):
180 copts = if_mac(["-DGRPC_CFSTREAM"])
181 if language.upper() == "C":
182 copts = copts + if_not_windows(["-std=c99"])
184 # NOTE: these attributes won't be used for the poller-specific versions of a test
185 # automatically, you need to set them explicitly (if applicable)
190 "deps": deps + _get_external_deps(external_deps),
191 "copts": GRPC_DEFAULT_COPTS + copts,
192 "linkopts": if_not_windows(["-pthread"]),
195 "exec_compatible_with": exec_compatible_with,
196 "exec_properties": exec_properties,
197 "shard_count": shard_count,
201 # the vanilla version of the test should run on platforms that only
202 # support a single poller
207 "no_linux", # linux supports multiple pollers
212 # on linux we run the same test multiple times, once for each poller
213 for poller in POLLERS:
215 name = name + "@poller=" + poller,
216 data = [name] + data,
218 "//test/core/util:run_with_poller_sh",
224 "$(location %s)" % name,
226 tags = (tags + ["no_windows", "no_mac"]),
227 exec_compatible_with = exec_compatible_with,
228 exec_properties = exec_properties,
229 shard_count = shard_count,
233 # the test behavior doesn't depend on polling, just generate the test
234 native.cc_test(name = name, tags = tags + ["no_uses_polling"], **args)
241 def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++", testonly = False, linkshared = False, linkopts = [], tags = [], features = []):
243 if language.upper() == "C":
251 linkshared = linkshared,
252 deps = deps + _get_external_deps(external_deps),
253 copts = GRPC_DEFAULT_COPTS + copts,
254 linkopts = if_not_windows(["-pthread"]) + linkopts,
259 def grpc_generate_one_off_targets():
260 # In open-source, grpc_objc* libraries depend directly on //:grpc
266 def grpc_generate_objc_one_off_targets():
269 def grpc_sh_test(name, srcs, args = [], data = []):
277 def grpc_sh_binary(name, srcs, data = []):
291 python_version = "PY2",
298 deps = deps + _get_external_deps(external_deps),
299 python_version = python_version,
303 def grpc_package(name, visibility = "private", features = []):
304 if visibility == "tests":
305 visibility = ["//test:__subpackages__"]
306 elif visibility == "public":
307 visibility = ["//visibility:public"]
308 elif visibility == "private":
311 fail("Unknown visibility " + visibility)
313 if len(visibility) != 0:
315 default_visibility = visibility,
319 def grpc_objc_library(
328 visibility = ["//visibility:public"]):
329 """The grpc version of objc_library, only used for the Objective-C library compilation
334 srcs: all source files (.m)
335 textual_hdrs: private headers
336 data: any other bundle resources
337 defines: preprocessors
338 includes: added to search path, always [the path to objc directory]
340 visibility: visibility, default to public
347 textual_hdrs = textual_hdrs,
352 visibility = visibility,
355 def grpc_upb_proto_library(name, deps):
356 upb_proto_library(name = name, deps = deps)
358 def python_config_settings():
359 native.config_setting(
361 flag_values = {"@bazel_tools//tools/python:python_version": "PY3"},