xref: /aosp_15_r20/external/grpc-grpc/bazel/grpc_build_system.bzl (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1# Copyright 2016 gRPC authors.
2#
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
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
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.
14
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#
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#
25
26"""
27Contains macros used throughout the repo.
28"""
29
30load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test")
31load("@build_bazel_rules_apple//apple/testing/default_runner:ios_test_runner.bzl", "ios_test_runner")
32load("@com_google_protobuf//bazel:upb_proto_library.bzl", "upb_proto_library", "upb_proto_reflection_library")
33load("//bazel:cc_grpc_library.bzl", "cc_grpc_library")
34load("//bazel:copts.bzl", "GRPC_DEFAULT_COPTS")
35load("//bazel:experiments.bzl", "EXPERIMENTS", "EXPERIMENT_ENABLES", "EXPERIMENT_POLLERS")
36load("//bazel:test_experiments.bzl", "TEST_EXPERIMENTS", "TEST_EXPERIMENT_ENABLES", "TEST_EXPERIMENT_POLLERS")
37
38# The set of pollers to test against if a test exercises polling
39POLLERS = ["epoll1", "poll"]
40
41# The set of known EventEngines to test
42EVENT_ENGINES = {"default": {"tags": []}}
43
44def if_not_windows(a):
45    return select({
46        "//:windows": [],
47        "//:windows_msvc": [],
48        "//conditions:default": a,
49    })
50
51def if_windows(a):
52    return select({
53        "//:windows": a,
54        "//:windows_msvc": a,
55        "//conditions:default": [],
56    })
57
58def _get_external_deps(external_deps):
59    ret = []
60    for dep in external_deps:
61        if dep == "address_sorting":
62            ret.append("//third_party/address_sorting")
63        elif dep == "xxhash":
64            ret.append("//third_party/xxhash")
65        elif dep == "cares":
66            ret += select({
67                "//:grpc_no_ares": [],
68                "//conditions:default": ["//external:cares"],
69            })
70        elif dep == "cronet_c_for_grpc":
71            ret.append("//third_party/objective_c/Cronet:cronet_c_for_grpc")
72        elif dep.startswith("absl/"):
73            ret.append("@com_google_absl//" + dep)
74        elif dep.startswith("google/"):
75            ret.append("@com_google_googleapis//" + dep)
76        elif dep.startswith("otel/"):
77            ret.append(dep.replace("otel/", "@io_opentelemetry_cpp//"))
78        elif dep.startswith("google_cloud_cpp"):
79            ret.append(dep.replace("google_cloud_cpp", "@google_cloud_cpp//"))
80        elif dep == "libprotobuf_mutator":
81            ret.append("@com_google_libprotobuf_mutator//:libprotobuf_mutator")
82        else:
83            ret.append("//external:" + dep)
84    return ret
85
86def _update_visibility(visibility):
87    if visibility == None:
88        return None
89
90    # Visibility rules prefixed with '@grpc:' are used to flag different visibility rule
91    # classes upstream.
92    PUBLIC = ["//visibility:public"]
93    PRIVATE = ["//:__subpackages__"]
94    VISIBILITY_TARGETS = {
95        "alt_grpc++_base_legacy": PRIVATE,
96        "alt_grpc_base_legacy": PRIVATE,
97        "alt_grpc++_base_unsecure_legacy": PRIVATE,
98        "alts_frame_protector": PRIVATE,
99        "channelz": PRIVATE,
100        "chaotic_good": PRIVATE,
101        "client_channel": PRIVATE,
102        "cli": PRIVATE,
103        "debug_location": PRIVATE,
104        "endpoint_tests": PRIVATE,
105        "exec_ctx": PRIVATE,
106        "grpclb": PRIVATE,
107        "grpc_experiments": PRIVATE,
108        "grpc_opencensus_plugin": PUBLIC,
109        "grpcpp_gcp_observability": PUBLIC,
110        "grpc_resolver_fake": PRIVATE,
111        "grpc++_test": PRIVATE,
112        "http": PRIVATE,
113        "httpcli": PRIVATE,
114        "iomgr_internal_errqueue": PRIVATE,
115        "iomgr_buffer_list": PRIVATE,
116        "json_reader_legacy": PRIVATE,
117        "public": PUBLIC,
118        "ref_counted_ptr": PRIVATE,
119        "tcp_tracer": PRIVATE,
120        "trace": PRIVATE,
121        "tsi_interface": PRIVATE,
122        "tsi": PRIVATE,
123        "xds": PRIVATE,
124        "xds_client_core": PRIVATE,
125        "xds_end2end_test_utils": PRIVATE,
126        "grpc_python_observability": PRIVATE,
127        "event_engine_base_hdrs": PRIVATE,
128        "useful": PRIVATE,
129    }
130    final_visibility = []
131    for rule in visibility:
132        if rule.startswith("@grpc:"):
133            for replacement in VISIBILITY_TARGETS[rule[len("@grpc:"):]]:
134                final_visibility.append(replacement)
135        else:
136            final_visibility.append(rule)
137    return [x for x in final_visibility]
138
139def grpc_cc_library(
140        name,
141        srcs = [],
142        public_hdrs = [],
143        hdrs = [],
144        external_deps = [],
145        defines = [],
146        deps = [],
147        select_deps = None,
148        standalone = False,
149        language = "C++",
150        testonly = False,
151        visibility = None,
152        alwayslink = 0,
153        data = [],
154        tags = [],
155        linkopts = [],
156        linkstatic = False):
157    """An internal wrapper around cc_library.
158
159    Args:
160      name: The name of the library.
161      srcs: The source files.
162      public_hdrs: The public headers.
163      hdrs: The headers.
164      external_deps: External depdendencies to be resolved.
165      defines: Build defines to use.
166      deps: cc_library deps.
167      select_deps: deps included conditionally.
168      standalone: Unused.
169      language: The language of the library, e.g. C, C++.
170      testonly: Whether the target is for tests only.
171      visibility: The visibility of the target.
172      alwayslink: Whether to enable alwayslink on the cc_library.
173      data: Data dependencies.
174      tags: Tags to apply to the rule.
175      linkopts: Extra libraries to link.
176      linkstatic: Whether to enable linkstatic on the cc_library.
177    """
178    visibility = _update_visibility(visibility)
179    copts = []
180    if language.upper() == "C":
181        copts = copts + if_not_windows(["-std=c11"])
182    linkopts = linkopts + if_not_windows(["-pthread"]) + if_windows(["-defaultlib:ws2_32.lib"])
183    if select_deps:
184        for select_deps_entry in select_deps:
185            deps += select(select_deps_entry)
186    native.cc_library(
187        name = name,
188        srcs = srcs,
189        defines = defines +
190                  select({
191                      "//:grpc_no_ares": ["GRPC_ARES=0"],
192                      "//conditions:default": [],
193                  }) +
194                  select({
195                      "//:remote_execution": ["GRPC_PORT_ISOLATED_RUNTIME=1"],
196                      "//conditions:default": [],
197                  }) +
198                  select({
199                      "//:grpc_allow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=1"],
200                      "//:grpc_disallow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=0"],
201                      "//conditions:default": [],
202                  }),
203        hdrs = hdrs + public_hdrs,
204        deps = deps + _get_external_deps(external_deps),
205        copts = GRPC_DEFAULT_COPTS + copts,
206        visibility = visibility,
207        testonly = testonly,
208        linkopts = linkopts,
209        includes = [
210            "include",
211            "src/core/ext/upb-gen",  # Once upb code-gen issue is resolved, remove this.
212            "src/core/ext/upbdefs-gen",  # Once upb code-gen issue is resolved, remove this.
213        ],
214        alwayslink = alwayslink,
215        data = data,
216        tags = tags,
217        linkstatic = linkstatic,
218    )
219
220def grpc_proto_plugin(name, srcs = [], deps = []):
221    native.cc_binary(
222        name = name,
223        srcs = srcs,
224        deps = deps,
225    )
226
227def grpc_proto_library(
228        name,
229        srcs = [],
230        deps = [],
231        well_known_protos = False,
232        has_services = True,
233        use_external = False,
234        generate_mocks = False):
235    cc_grpc_library(
236        name = name,
237        srcs = srcs,
238        deps = deps,
239        well_known_protos = well_known_protos,
240        proto_only = not has_services,
241        use_external = use_external,
242        generate_mocks = generate_mocks,
243    )
244
245def ios_cc_test(
246        name,
247        tags = [],
248        **kwargs):
249    """An ios C++ test target.
250
251    Args:
252      name: The name of the test.
253      tags: The tags to apply to the test.
254      **kwargs: All other arguments to apply.
255    """
256    test_lib_ios = name + "_test_lib_ios"
257    ios_tags = tags + ["manual", "ios_cc_test"]
258    test_runner = "ios_x86_64_sim_runner_" + name
259    ios_test_runner(
260        name = test_runner,
261        device_type = "iPhone X",
262    )
263    if not any([t for t in tags if t.startswith("no_test_ios")]):
264        native.objc_library(
265            name = test_lib_ios,
266            srcs = kwargs.get("srcs"),
267            deps = kwargs.get("deps"),
268            copts = kwargs.get("copts"),
269            data = kwargs.get("data"),
270            tags = ios_tags,
271            alwayslink = 1,
272            testonly = 1,
273        )
274        ios_test_deps = [":" + test_lib_ios]
275        ios_unit_test(
276            name = name + "_on_ios",
277            size = kwargs.get("size"),
278            data = kwargs.get("data"),
279            tags = ios_tags,
280            minimum_os_version = "9.0",
281            runner = test_runner,
282            deps = ios_test_deps,
283        )
284
285def expand_poller_config(name, srcs, deps, tags, args, exclude_pollers, uses_polling, uses_event_engine, flaky):
286    """Common logic used to parameterize tests for every poller and EventEngine.
287
288    Used by expand_tests (repeatedly) to form base lists of pollers for each experiment.
289
290    Args:
291        name: base name of the test
292        srcs: source files
293        deps: base deps
294        tags: base tags
295        args: base args
296        flaky: base flaky
297        exclude_pollers: list of poller names to exclude for this set of tests.
298        uses_polling: set to False if the test is not sensitive to polling methodology.
299        uses_event_engine: set to False if the test is not sensitive to
300            EventEngine implementation differences
301
302    Returns:
303        A list of dictionaries containing modified values of name, srcs, deps, tags, and args.
304    """
305
306    poller_config = []
307
308    # See work_stealing_thread_pool.cc for details.
309    default_env = {"GRPC_THREAD_POOL_VERBOSE_FAILURES": "true"}
310
311    if not uses_polling:
312        tags = tags + ["no_uses_polling"]
313
314        poller_config.append({
315            "name": name,
316            "srcs": srcs,
317            "deps": deps,
318            "tags": tags,
319            "args": args,
320            "flaky": flaky,
321            "env": default_env,
322        })
323    else:
324        # On linux we run the same test with the default EventEngine, once for each
325        # poller
326        for poller in POLLERS:
327            if poller in exclude_pollers:
328                continue
329            poller_config.append({
330                "name": name + "@poller=" + poller,
331                "srcs": srcs,
332                "deps": deps,
333                "tags": (tags + EVENT_ENGINES["default"]["tags"] + [
334                    "no_windows",
335                    "no_mac",
336                    "bazel_only",
337                ]),
338                "args": args,
339                "env": {
340                    "GRPC_POLL_STRATEGY": poller,
341                } | default_env,
342                "flaky": flaky,
343            })
344
345        # Now generate one test for each subsequent EventEngine, all using the
346        # default poller. These tests will have `@engine=<name>` appended to the
347        # test target name. If a test target name has no `@engine=<name>` component,
348        # that indicates that the default EventEngine is being used.
349        if not uses_event_engine:
350            # The poller tests exercise the default engine on Linux. This test
351            # handles other platforms.
352            poller_config.append({
353                "name": name,
354                "srcs": srcs,
355                "deps": deps,
356                "tags": tags + ["no_linux"],
357                "args": args,
358                "env": default_env,
359                "flaky": flaky,
360            })
361        else:
362            for engine_name, engine in EVENT_ENGINES.items():
363                test_name = name + "@engine=" + engine_name
364                test_tags = tags + engine["tags"] + ["bazel_only"]
365                test_args = args + ["--engine=" + engine_name]
366                if engine_name == "default":
367                    # The poller tests exercise the default engine on Linux.
368                    # This test handles other platforms.
369                    test_name = name
370                    test_tags = tags + engine["tags"] + ["no_linux"]
371                    test_args = args
372                poller_config.append({
373                    "name": test_name,
374                    "srcs": srcs,
375                    "deps": deps,
376                    "tags": test_tags,
377                    "args": test_args,
378                    "env": default_env,
379                    "flaky": flaky,
380                })
381
382    return poller_config
383
384def expand_tests(name, srcs, deps, tags, args, exclude_pollers, uses_polling, uses_event_engine, flaky):
385    """Common logic used to parameterize tests for every poller and EventEngine and experiment.
386
387    Args:
388        name: base name of the test
389        srcs: source files
390        deps: base deps
391        tags: base tags
392        args: base args
393        flaky: base flaky
394        exclude_pollers: list of poller names to exclude for this set of tests.
395        uses_polling: set to False if the test is not sensitive to polling methodology.
396        uses_event_engine: set to False if the test is not sensitive to
397            EventEngine implementation differences
398
399    Returns:
400        A list of dictionaries containing modified values of name, srcs, deps, tags, and args.
401    """
402
403    experiments = {}
404
405    # buildifier: disable=uninitialized
406    def _populate_experiments_platform_config(config, platform_experiments_map):
407        for platform, experiments_on_platform in platform_experiments_map.items():
408            for mode, tag_to_experiments in experiments_on_platform.items():
409                if mode not in config:
410                    config[mode] = {}
411                for tag in tags:
412                    if tag not in tag_to_experiments:
413                        continue
414                    for experiment in tag_to_experiments[tag]:
415                        if experiment not in config[mode]:
416                            config[mode][experiment] = []
417                        config[mode][experiment].append(platform)
418
419    _populate_experiments_platform_config(experiments, EXPERIMENTS)
420    _populate_experiments_platform_config(experiments, TEST_EXPERIMENTS)
421
422    mode_config = {
423        # format: <mode>: (enabled_target_tags, disabled_target_tags)
424        "on": (None, []),
425        "off": ([], None),
426    }
427
428    must_have_tags = [
429        # We don't run experiments on cmake builds
430        "bazel_only",
431        # Nor on mac
432        "no_mac",
433        # Nor on arm64
434        "no_arm64",
435    ]
436
437    def _update_experiments_platform_test_tags(tags, platforms):
438        if "posix" not in platforms:
439            if "no_linux" not in tags:
440                tags.append("no_linux")
441            if "no_mac" not in tags:
442                tags.append("no_mac")
443        if "windows" not in platforms:
444            if "no_windows" not in tags:
445                tags.append("no_windows")
446        if "ios" not in platforms:
447            if "no_test_ios" not in tags:
448                tags.append("no_test_ios")
449        return tags
450
451    base_params = {
452        "name": name,
453        "srcs": srcs,
454        "deps": deps,
455        "tags": tags,
456        "args": args,
457        "exclude_pollers": exclude_pollers,
458        "uses_polling": uses_polling,
459        "uses_event_engine": uses_event_engine,
460        "flaky": flaky,
461    }
462
463    experiment_config = expand_poller_config(**base_params)
464    experiment_enables = {k: v for k, v in EXPERIMENT_ENABLES.items() + TEST_EXPERIMENT_ENABLES.items()}
465    experiment_pollers = EXPERIMENT_POLLERS + TEST_EXPERIMENT_POLLERS
466    for mode, config in mode_config.items():
467        enabled_tags, disabled_tags = config
468        if enabled_tags != None:
469            for experiment in experiments[mode].keys():
470                experiment_params = dict(base_params)
471                experiment_params["uses_polling"] = uses_polling and (experiment in experiment_pollers)
472                for config in expand_poller_config(**experiment_params):
473                    config = dict(config)
474                    config["name"] = config["name"] + "@experiment=" + experiment
475                    env = dict(config["env"])
476                    env["GRPC_EXPERIMENTS"] = experiment_enables[experiment]
477                    env["GRPC_CI_EXPERIMENTS"] = "1"
478                    config["env"] = env
479                    tags = config["tags"] + ["experiment_variation"]
480                    for tag in must_have_tags + enabled_tags:
481                        if tag not in tags:
482                            tags = tags + [tag]
483                    config["tags"] = _update_experiments_platform_test_tags(tags, experiments[mode][experiment])
484                    config["flaky"] = True
485                    experiment_config.append(config)
486        if disabled_tags != None:
487            for experiment in experiments[mode].keys():
488                experiment_params = dict(base_params)
489                experiment_params["uses_polling"] = uses_polling and (experiment in experiment_pollers)
490                for config in expand_poller_config(**experiment_params):
491                    config = dict(config)
492                    config["name"] = config["name"] + "@experiment=no_" + experiment
493                    env = dict(config["env"])
494                    env["GRPC_EXPERIMENTS"] = "-" + experiment
495                    env["GRPC_CI_EXPERIMENTS"] = "1"
496                    config["env"] = env
497                    tags = config["tags"] + ["experiment_variation"]
498                    for tag in must_have_tags + disabled_tags:
499                        if tag not in tags:
500                            tags = tags + [tag]
501                    config["tags"] = _update_experiments_platform_test_tags(tags, experiments[mode][experiment])
502                    experiment_config.append(config)
503    return experiment_config
504
505def 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, copts = [], linkstatic = None, exclude_pollers = [], uses_event_engine = True):
506    """A cc_test target for use in the gRPC repo.
507
508    Args:
509        name: The name of the test.
510        srcs: The source files.
511        deps: The target deps.
512        external_deps: The external deps.
513        args: The args to supply to the test binary.
514        data: Data dependencies.
515        uses_polling: Whether the test uses polling.
516        language: The language of the test, e.g C, C++.
517        size: The size of the test.
518        timeout: The test timeout.
519        tags: The tags for the test.
520        exec_compatible_with: A list of constraint values that must be
521            satisifed for the platform.
522        exec_properties: A dictionary of strings that will be added to the
523            exec_properties of a platform selected for this target.
524        shard_count: The number of shards for this test.
525        flaky: Whether this test is flaky.
526        copts: Add these to the compiler invocation.
527        linkstatic: link the binary in static mode
528        exclude_pollers: list of poller names to exclude for this set of tests.
529        uses_event_engine: set to False if the test is not sensitive to
530            EventEngine implementation differences
531    """
532    if language.upper() == "C":
533        copts = copts + if_not_windows(["-std=c11"])
534
535    core_deps = deps + _get_external_deps(external_deps) + ["//test/core/util:grpc_suppressions"]
536
537    # Test args for all tests
538    test_args = {
539        "data": data,
540        "copts": GRPC_DEFAULT_COPTS + copts,
541        "linkopts": if_not_windows(["-pthread"]) + if_windows(["-defaultlib:ws2_32.lib"]),
542        "size": size,
543        "timeout": timeout,
544        "exec_compatible_with": exec_compatible_with,
545        "exec_properties": exec_properties,
546        "shard_count": shard_count,
547        "linkstatic": linkstatic,
548    }
549
550    if "grpc-fuzzer" not in tags and "no_test_ios" not in tags:
551        ios_cc_test(
552            name = name,
553            srcs = srcs,
554            tags = tags,
555            deps = core_deps,
556            args = args,
557            flaky = True,
558            **test_args
559        )
560
561    native.cc_library(
562        name = "%s_TEST_LIBRARY" % name,
563        testonly = 1,
564        srcs = srcs,
565        deps = core_deps,
566        tags = tags,
567    )
568
569    for poller_config in expand_tests(name, srcs, core_deps, tags, args, exclude_pollers, uses_polling, uses_event_engine, flaky):
570        if poller_config["srcs"] != srcs:
571            fail("srcs changed")
572        if poller_config["deps"] != core_deps:
573            fail("deps changed: %r --> %r" % (deps, poller_config["deps"]))
574        native.cc_test(
575            name = poller_config["name"],
576            deps = ["%s_TEST_LIBRARY" % name],
577            tags = poller_config["tags"],
578            args = poller_config["args"],
579            env = poller_config["env"],
580            flaky = poller_config["flaky"],
581            **test_args
582        )
583
584def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++", testonly = False, linkshared = False, linkopts = [], tags = [], features = [], visibility = None):
585    """Generates a cc_binary for use in the gRPC repo.
586
587    Args:
588      name: The name of the target.
589      srcs: The source files.
590      deps: The dependencies.
591      external_deps: The external dependencies.
592      args: The arguments to supply to the binary.
593      data: The data dependencies.
594      language: The language of the binary, e.g. C, C++.
595      testonly: Whether the binary is for tests only.
596      linkshared: Enables linkshared on the binary.
597      linkopts: linkopts to supply to the cc_binary.
598      tags: Tags to apply to the target.
599      features: features to be supplied to the cc_binary.
600      visibility: The visibility of the target.
601    """
602    visibility = _update_visibility(visibility)
603    copts = []
604    if language.upper() == "C":
605        copts = ["-std=c11"]
606    native.cc_binary(
607        name = name,
608        srcs = srcs,
609        args = args,
610        data = data,
611        testonly = testonly,
612        linkshared = linkshared,
613        deps = deps + _get_external_deps(external_deps) + ["//test/core/util:grpc_suppressions"],
614        copts = GRPC_DEFAULT_COPTS + copts,
615        linkopts = if_not_windows(["-pthread"]) + linkopts,
616        tags = tags,
617        features = features,
618    )
619
620# buildifier: disable=unnamed-macro
621def grpc_generate_one_off_targets():
622    # In open-source, grpc_objc* libraries depend directly on //:grpc
623    native.alias(
624        name = "grpc_objc",
625        actual = "//:grpc",
626    )
627    native.config_setting(
628        name = "windows_other",
629        values = {"define": "GRPC_WINDOWS_OTHER=1"},
630    )
631
632def grpc_generate_objc_one_off_targets():
633    pass
634
635def grpc_generate_one_off_internal_targets():
636    pass
637
638def grpc_sh_test(name, srcs = [], args = [], data = [], uses_polling = True, size = "medium", timeout = None, tags = [], exec_compatible_with = [], exec_properties = {}, shard_count = None, flaky = None, exclude_pollers = [], uses_event_engine = True):
639    """Execute an sh_test for every <poller> x <EventEngine> combination
640
641    Args:
642        name: The name of the test.
643        srcs: The source files.
644        args: The args to supply to the test binary.
645        data: Data dependencies.
646        uses_polling: Whether the test uses polling.
647        size: The size of the test.
648        timeout: The test timeout.
649        tags: The tags for the test.
650        exec_compatible_with: A list of constraint values that must be
651            satisifed for the platform.
652        exec_properties: A dictionary of strings that will be added to the
653            exec_properties of a platform selected for this target.
654        shard_count: The number of shards for this test.
655        flaky: Whether this test is flaky.
656        exclude_pollers: list of poller names to exclude for this set of tests.
657        uses_event_engine: set to False if the test is not sensitive to
658            EventEngine implementation differences
659    """
660    test_args = {
661        "data": data,
662        "size": size,
663        "timeout": timeout,
664        "exec_compatible_with": exec_compatible_with,
665        "exec_properties": exec_properties,
666        "shard_count": shard_count,
667    }
668
669    for poller_config in expand_tests(name, srcs, [], tags, args, exclude_pollers, uses_polling, uses_event_engine, flaky):
670        native.sh_test(
671            name = poller_config["name"],
672            srcs = poller_config["srcs"],
673            deps = poller_config["deps"],
674            tags = poller_config["tags"],
675            args = poller_config["args"],
676            env = poller_config["env"],
677            flaky = poller_config["flaky"],
678            **test_args
679        )
680
681def grpc_sh_binary(name, srcs, data = []):
682    native.sh_binary(
683        name = name,
684        srcs = srcs,
685        data = data,
686    )
687
688def grpc_py_binary(
689        name,
690        srcs,
691        data = [],
692        deps = [],
693        external_deps = [],
694        testonly = False,
695        python_version = "PY2",
696        **kwargs):
697    native.py_binary(
698        name = name,
699        srcs = srcs,
700        testonly = testonly,
701        data = data,
702        deps = deps + _get_external_deps(external_deps),
703        python_version = python_version,
704        **kwargs
705    )
706
707def grpc_package(name, visibility = "private", features = []):
708    """Creates a package.
709
710    Args:
711        name: The name of the target
712        visibility: The visibility of the target.
713        features: The features to enable.
714    """
715    if visibility == "tests":
716        visibility = ["//test:__subpackages__"]
717    elif visibility == "public":
718        visibility = ["//visibility:public"]
719    elif visibility == "private":
720        visibility = []
721    else:
722        fail("Unknown visibility " + visibility)
723
724    if len(visibility) != 0:
725        # buildifier: disable=native-package
726        native.package(
727            default_visibility = visibility,
728            features = features,
729        )
730
731def grpc_objc_library(
732        name,
733        srcs = [],
734        hdrs = [],
735        non_arc_srcs = [],
736        textual_hdrs = [],
737        testonly = False,
738        data = [],
739        deps = [],
740        defines = [],
741        sdk_frameworks = [],
742        includes = [],
743        visibility = ["//visibility:public"]):
744    """The grpc version of objc_library, only used for the Objective-C library compilation
745
746    Args:
747        name: name of target
748        hdrs: public headers
749        srcs: all source files (.m)
750        non_arc_srcs: list of Objective-C files that DO NOT use ARC.
751        textual_hdrs: private headers
752        testonly: Whether the binary is for tests only.
753        data: any other bundle resources
754        defines: preprocessors
755        sdk_frameworks: sdks
756        includes: added to search path, always [the path to objc directory]
757        deps: dependencies
758        visibility: visibility, default to public
759    """
760
761    native.objc_library(
762        name = name,
763        hdrs = hdrs,
764        srcs = srcs,
765        non_arc_srcs = non_arc_srcs,
766        textual_hdrs = textual_hdrs,
767        copts = GRPC_DEFAULT_COPTS + ["-ObjC++", "-std=gnu++14"],
768        testonly = testonly,
769        data = data,
770        deps = deps,
771        defines = defines,
772        includes = includes,
773        sdk_frameworks = sdk_frameworks,
774        visibility = visibility,
775    )
776
777def grpc_upb_proto_library(name, deps):
778    upb_proto_library(name = name, deps = deps)
779
780def grpc_upb_proto_reflection_library(name, deps):
781    upb_proto_reflection_library(name = name, deps = deps)
782
783# buildifier: disable=unnamed-macro
784def python_config_settings():
785    native.config_setting(
786        name = "python3",
787        flag_values = {"@bazel_tools//tools/python:python_version": "PY3"},
788    )
789