• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Platform-specific build configurations.
2
3load("@com_google_protobuf//:protobuf.bzl", "proto_gen")
4load("//tensorflow:tensorflow.bzl", "clean_dep", "if_libtpu", "if_not_windows")
5load("//tensorflow/core/platform:build_config_root.bzl", "if_static")
6load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda")
7load("@local_config_rocm//rocm:build_defs.bzl", "if_rocm")
8load(
9    "//third_party/mkl:build_defs.bzl",
10    "if_mkl_ml",
11)
12
13def well_known_proto_libs():
14    """Set of standard protobuf protos, like Any and Timestamp.
15
16    This list should be provided by protobuf.bzl, but it's not.
17    """
18    return [
19        "@com_google_protobuf//:any_proto",
20        "@com_google_protobuf//:api_proto",
21        "@com_google_protobuf//:compiler_plugin_proto",
22        "@com_google_protobuf//:descriptor_proto",
23        "@com_google_protobuf//:duration_proto",
24        "@com_google_protobuf//:empty_proto",
25        "@com_google_protobuf//:field_mask_proto",
26        "@com_google_protobuf//:source_context_proto",
27        "@com_google_protobuf//:struct_proto",
28        "@com_google_protobuf//:timestamp_proto",
29        "@com_google_protobuf//:type_proto",
30        "@com_google_protobuf//:wrappers_proto",
31    ]
32
33# Appends a suffix to a list of deps.
34def tf_deps(deps, suffix):
35    tf_deps = []
36
37    # If the package name is in shorthand form (ie: does not contain a ':'),
38    # expand it to the full name.
39    for dep in deps:
40        tf_dep = dep
41
42        if not ":" in dep:
43            dep_pieces = dep.split("/")
44            tf_dep += ":" + dep_pieces[len(dep_pieces) - 1]
45
46        tf_deps += [tf_dep + suffix]
47
48    return tf_deps
49
50# Modified from @cython//:Tools/rules.bzl
51def pyx_library(
52        name,
53        deps = [],
54        py_deps = [],
55        srcs = [],
56        testonly = None,
57        srcs_version = "PY3",
58        **kwargs):
59    """Compiles a group of .pyx / .pxd / .py files.
60
61    First runs Cython to create .cpp files for each input .pyx or .py + .pxd
62    pair. Then builds a shared object for each, passing "deps" to each cc_binary
63    rule (includes Python headers by default). Finally, creates a py_library rule
64    with the shared objects and any pure Python "srcs", with py_deps as its
65    dependencies; the shared objects can be imported like normal Python files.
66
67    Args:
68      name: Name for the rule.
69      deps: C/C++ dependencies of the Cython (e.g. Numpy headers).
70      py_deps: Pure Python dependencies of the final library.
71      srcs: .py, .pyx, or .pxd files to either compile or pass through.
72      **kwargs: Extra keyword arguments passed to the py_library.
73    """
74
75    # First filter out files that should be run compiled vs. passed through.
76    py_srcs = []
77    pyx_srcs = []
78    pxd_srcs = []
79    for src in srcs:
80        if src.endswith(".pyx") or (src.endswith(".py") and
81                                    src[:-3] + ".pxd" in srcs):
82            pyx_srcs.append(src)
83        elif src.endswith(".py"):
84            py_srcs.append(src)
85        else:
86            pxd_srcs.append(src)
87        if src.endswith("__init__.py"):
88            pxd_srcs.append(src)
89
90    # Invoke cython to produce the shared object libraries.
91    for filename in pyx_srcs:
92        native.genrule(
93            name = filename + "_cython_translation",
94            srcs = [filename],
95            outs = [filename.split(".")[0] + ".cpp"],
96            # Optionally use PYTHON_BIN_PATH on Linux platforms so that python 3
97            # works. Windows has issues with cython_binary so skip PYTHON_BIN_PATH.
98            cmd = "PYTHONHASHSEED=0 $(location @cython//:cython_binary) --cplus $(SRCS) --output-file $(OUTS)",
99            testonly = testonly,
100            tools = ["@cython//:cython_binary"] + pxd_srcs,
101        )
102
103    shared_objects = []
104    for src in pyx_srcs:
105        stem = src.split(".")[0]
106        shared_object_name = stem + ".so"
107        native.cc_binary(
108            name = shared_object_name,
109            srcs = [stem + ".cpp"],
110            deps = deps + ["@org_tensorflow//third_party/python_runtime:headers"],
111            linkshared = 1,
112            testonly = testonly,
113        )
114        shared_objects.append(shared_object_name)
115
116    # Now create a py_library with these shared objects as data.
117    native.py_library(
118        name = name,
119        srcs = py_srcs,
120        deps = py_deps,
121        srcs_version = srcs_version,
122        data = shared_objects,
123        testonly = testonly,
124        **kwargs
125    )
126
127def _proto_cc_hdrs(srcs, use_grpc_plugin = False):
128    ret = [s[:-len(".proto")] + ".pb.h" for s in srcs]
129    if use_grpc_plugin:
130        ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs]
131    return ret
132
133def _proto_cc_srcs(srcs, use_grpc_plugin = False):
134    ret = [s[:-len(".proto")] + ".pb.cc" for s in srcs]
135    if use_grpc_plugin:
136        ret += [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs]
137    return ret
138
139def _proto_py_outs(srcs, use_grpc_plugin = False):
140    ret = [s[:-len(".proto")] + "_pb2.py" for s in srcs]
141    if use_grpc_plugin:
142        ret += [s[:-len(".proto")] + "_pb2_grpc.py" for s in srcs]
143    return ret
144
145# Re-defined protocol buffer rule to allow building "header only" protocol
146# buffers, to avoid duplicate registrations. Also allows non-iterable cc_libs
147# containing select() statements.
148def cc_proto_library(
149        name,
150        srcs = [],
151        deps = [],
152        cc_libs = [],
153        include = None,
154        protoc = "@com_google_protobuf//:protoc",
155        internal_bootstrap_hack = False,
156        use_grpc_plugin = False,
157        use_grpc_namespace = False,
158        make_default_target_header_only = False,
159        protolib_name = None,
160        protolib_deps = [],
161        **kwargs):
162    """Bazel rule to create a C++ protobuf library from proto source files.
163
164    Args:
165      name: the name of the cc_proto_library.
166      srcs: the .proto files of the cc_proto_library.
167      deps: a list of dependency labels; must be cc_proto_library.
168      cc_libs: a list of other cc_library targets depended by the generated
169          cc_library.
170      include: a string indicating the include path of the .proto files.
171      protoc: the label of the protocol compiler to generate the sources.
172      internal_bootstrap_hack: a flag indicating if the cc_proto_library is used only
173          for bootstrapping. When it is set to True, no files will be generated.
174          The rule will simply be a provider for .proto files, so that other
175          cc_proto_library can depend on it.
176      use_grpc_plugin: a flag to indicate whether to call the grpc C++ plugin
177          when processing the proto files.
178      use_grpc_namespace: the namespace for the grpc services.
179      make_default_target_header_only: Controls the naming of generated
180          rules. If True, the `name` rule will be header-only, and an _impl rule
181          will contain the implementation. Otherwise the header-only rule (name
182          + "_headers_only") must be referred to explicitly.
183      protolib_name: the name for the proto library generated by this rule.
184      protolib_deps: the dependencies to proto libraries.
185      **kwargs: other keyword arguments that are passed to cc_library.
186    """
187
188    wkt_deps = ["@com_google_protobuf//:cc_wkt_protos"]
189    all_protolib_deps = protolib_deps + wkt_deps
190
191    includes = []
192    if include != None:
193        includes = [include]
194    if protolib_name == None:
195        protolib_name = name
196
197    if internal_bootstrap_hack:
198        # For pre-checked-in generated files, we add the internal_bootstrap_hack
199        # which will skip the codegen action.
200        proto_gen(
201            name = protolib_name + "_genproto",
202            srcs = srcs,
203            includes = includes,
204            protoc = protoc,
205            visibility = ["//visibility:public"],
206            deps = [s + "_genproto" for s in all_protolib_deps],
207        )
208
209        # An empty cc_library to make rule dependency consistent.
210        native.cc_library(
211            name = name,
212            **kwargs
213        )
214        return
215
216    grpc_cpp_plugin = None
217    plugin_options = []
218    if use_grpc_plugin:
219        grpc_cpp_plugin = "//external:grpc_cpp_plugin"
220        if use_grpc_namespace:
221            plugin_options = ["services_namespace=grpc"]
222
223    gen_srcs = _proto_cc_srcs(srcs, use_grpc_plugin)
224    gen_hdrs = _proto_cc_hdrs(srcs, use_grpc_plugin)
225    outs = gen_srcs + gen_hdrs
226
227    proto_gen(
228        name = protolib_name + "_genproto",
229        srcs = srcs,
230        outs = outs,
231        gen_cc = 1,
232        includes = includes,
233        plugin = grpc_cpp_plugin,
234        plugin_language = "grpc",
235        plugin_options = plugin_options,
236        protoc = protoc,
237        visibility = ["//visibility:public"],
238        deps = [s + "_genproto" for s in all_protolib_deps],
239    )
240
241    if use_grpc_plugin:
242        cc_libs += select({
243            clean_dep("//tensorflow:linux_s390x"): ["//external:grpc_lib_unsecure"],
244            "//conditions:default": ["//external:grpc_lib"],
245        })
246
247    impl_name = name + "_impl"
248    header_only_name = name + "_headers_only"
249    header_only_deps = tf_deps(protolib_deps, "_cc_headers_only")
250
251    if make_default_target_header_only:
252        native.alias(
253            name = name,
254            actual = header_only_name,
255            visibility = kwargs["visibility"],
256        )
257    else:
258        native.alias(
259            name = name,
260            actual = impl_name,
261            visibility = kwargs["visibility"],
262        )
263
264    native.cc_library(
265        name = impl_name,
266        srcs = gen_srcs,
267        hdrs = gen_hdrs,
268        deps = cc_libs + deps,
269        includes = includes,
270        alwayslink = 1,
271        **kwargs
272    )
273    native.cc_library(
274        name = header_only_name,
275        deps = [
276            "@com_google_protobuf//:protobuf_headers",
277        ] + header_only_deps + if_static([impl_name]),
278        hdrs = gen_hdrs,
279        **kwargs
280    )
281
282# Re-defined protocol buffer rule to bring in the change introduced in commit
283# https://github.com/google/protobuf/commit/294b5758c373cbab4b72f35f4cb62dc1d8332b68
284# which was not part of a stable protobuf release in 04/2018.
285# TODO(jsimsa): Remove this once the protobuf dependency version is updated
286# to include the above commit.
287def py_proto_library(
288        name,
289        srcs = [],
290        deps = [],
291        py_libs = [],
292        py_extra_srcs = [],
293        include = None,
294        default_runtime = "@com_google_protobuf//:protobuf_python",
295        protoc = "@com_google_protobuf//:protoc",
296        use_grpc_plugin = False,
297        **kwargs):
298    """Bazel rule to create a Python protobuf library from proto source files
299
300    NOTE: the rule is only an internal workaround to generate protos. The
301    interface may change and the rule may be removed when bazel has introduced
302    the native rule.
303
304    Args:
305      name: the name of the py_proto_library.
306      srcs: the .proto files of the py_proto_library.
307      deps: a list of dependency labels; must be py_proto_library.
308      py_libs: a list of other py_library targets depended by the generated
309          py_library.
310      py_extra_srcs: extra source files that will be added to the output
311          py_library. This attribute is used for internal bootstrapping.
312      include: a string indicating the include path of the .proto files.
313      default_runtime: the implicitly default runtime which will be depended on by
314          the generated py_library target.
315      protoc: the label of the protocol compiler to generate the sources.
316      use_grpc_plugin: a flag to indicate whether to call the Python C++ plugin
317          when processing the proto files.
318      **kwargs: other keyword arguments that are passed to py_library.
319    """
320    outs = _proto_py_outs(srcs, use_grpc_plugin)
321
322    includes = []
323    if include != None:
324        includes = [include]
325
326    grpc_python_plugin = None
327    if use_grpc_plugin:
328        grpc_python_plugin = "//external:grpc_python_plugin"
329        # Note: Generated grpc code depends on Python grpc module. This dependency
330        # is not explicitly listed in py_libs. Instead, host system is assumed to
331        # have grpc installed.
332
333    proto_gen(
334        name = name + "_genproto",
335        srcs = srcs,
336        outs = outs,
337        gen_py = 1,
338        includes = includes,
339        plugin = grpc_python_plugin,
340        plugin_language = "grpc",
341        protoc = protoc,
342        visibility = ["//visibility:public"],
343        deps = [s + "_genproto" for s in deps],
344    )
345
346    if default_runtime and not default_runtime in py_libs + deps:
347        py_libs = py_libs + [default_runtime]
348
349    native.py_library(
350        name = name,
351        srcs = outs + py_extra_srcs,
352        deps = py_libs + deps,
353        imports = includes,
354        **kwargs
355    )
356
357def tf_proto_library_cc(
358        name,
359        srcs = [],
360        has_services = None,
361        protodeps = [],
362        visibility = None,
363        testonly = 0,
364        cc_libs = [],
365        cc_stubby_versions = None,
366        cc_grpc_version = None,
367        use_grpc_namespace = False,
368        j2objc_api_version = 1,
369        cc_api_version = 2,
370        js_codegen = "jspb",
371        create_service = False,
372        create_java_proto = False,
373        make_default_target_header_only = False):
374    js_codegen = js_codegen  # unused argument
375    native.filegroup(
376        name = name + "_proto_srcs",
377        srcs = srcs + tf_deps(protodeps, "_proto_srcs"),
378        testonly = testonly,
379        visibility = visibility,
380    )
381    _ignore = (create_service, create_java_proto)
382
383    use_grpc_plugin = None
384    if cc_grpc_version:
385        use_grpc_plugin = True
386
387    protolib_deps = tf_deps(protodeps, "")
388    cc_deps = tf_deps(protodeps, "_cc")
389    cc_name = name + "_cc"
390    if not srcs:
391        # This is a collection of sub-libraries. Build header-only and impl
392        # libraries containing all the sources.
393        proto_gen(
394            name = name + "_genproto",
395            protoc = "@com_google_protobuf//:protoc",
396            visibility = ["//visibility:public"],
397            deps = [s + "_genproto" for s in protolib_deps],
398        )
399
400        native.alias(
401            name = cc_name + "_genproto",
402            actual = name + "_genproto",
403            testonly = testonly,
404            visibility = visibility,
405        )
406
407        native.alias(
408            name = cc_name + "_headers_only",
409            actual = cc_name,
410            testonly = testonly,
411            visibility = visibility,
412        )
413
414        native.cc_library(
415            name = cc_name,
416            deps = cc_deps + ["@com_google_protobuf//:protobuf_headers"] + if_static([name + "_cc_impl"]),
417            testonly = testonly,
418            visibility = visibility,
419        )
420        native.cc_library(
421            name = cc_name + "_impl",
422            deps = [s + "_impl" for s in cc_deps] + ["@com_google_protobuf//:cc_wkt_protos"],
423        )
424
425        return
426
427    cc_proto_library(
428        name = cc_name,
429        protolib_name = name,
430        testonly = testonly,
431        srcs = srcs,
432        cc_libs = cc_libs + if_static(
433            ["@com_google_protobuf//:protobuf"],
434            ["@com_google_protobuf//:protobuf_headers"],
435        ),
436        copts = if_not_windows([
437            "-Wno-unknown-warning-option",
438            "-Wno-unused-but-set-variable",
439            "-Wno-sign-compare",
440        ]),
441        make_default_target_header_only = make_default_target_header_only,
442        protoc = "@com_google_protobuf//:protoc",
443        use_grpc_plugin = use_grpc_plugin,
444        use_grpc_namespace = use_grpc_namespace,
445        visibility = visibility,
446        deps = cc_deps + ["@com_google_protobuf//:cc_wkt_protos"],
447        protolib_deps = protolib_deps,
448    )
449
450def tf_proto_library_py(
451        name,
452        srcs = [],
453        protodeps = [],
454        deps = [],
455        visibility = None,
456        testonly = 0,
457        srcs_version = "PY3",
458        use_grpc_plugin = False):
459    py_deps = tf_deps(protodeps, "_py")
460    py_name = name + "_py"
461    if not srcs:
462        # This is a collection of sub-libraries. Build header-only and impl
463        # libraries containing all the sources.
464        proto_gen(
465            name = py_name + "_genproto",
466            protoc = "@com_google_protobuf//:protoc",
467            visibility = ["//visibility:public"],
468            deps = [s + "_genproto" for s in py_deps],
469        )
470        native.py_library(
471            name = py_name,
472            deps = py_deps + [clean_dep("@com_google_protobuf//:protobuf_python")],
473            testonly = testonly,
474            visibility = visibility,
475        )
476        return
477
478    py_proto_library(
479        name = py_name,
480        testonly = testonly,
481        srcs = srcs,
482        default_runtime = clean_dep("@com_google_protobuf//:protobuf_python"),
483        protoc = "@com_google_protobuf//:protoc",
484        srcs_version = srcs_version,
485        use_grpc_plugin = use_grpc_plugin,
486        visibility = visibility,
487        deps = deps + py_deps + [clean_dep("@com_google_protobuf//:protobuf_python")],
488    )
489
490def tf_jspb_proto_library(**kwargs):
491    pass
492
493def tf_proto_library(
494        name,
495        srcs = [],
496        has_services = None,
497        protodeps = [],
498        visibility = None,
499        testonly = 0,
500        cc_libs = [],
501        cc_stubby_versions = None,
502        cc_api_version = 2,
503        cc_grpc_version = None,
504        use_grpc_namespace = False,
505        j2objc_api_version = 1,
506        js_codegen = "jspb",
507        create_service = False,
508        create_java_proto = False,
509        create_go_proto = False,
510        create_grpc_library = False,
511        make_default_target_header_only = False,
512        exports = [],
513        tags = []):
514    """Make a proto library, possibly depending on other proto libraries."""
515
516    # TODO(b/145545130): Add docstring explaining what rules this creates and how
517    # opensource projects importing TF in bazel can use them safely (i.e. w/o ODR or
518    # ABI violations).
519    _ignore = (
520        js_codegen,
521        exports,
522        create_service,
523        create_java_proto,
524        create_grpc_library,
525        cc_stubby_versions,
526        create_go_proto,
527    )
528
529    native.proto_library(
530        name = name,
531        srcs = srcs,
532        deps = protodeps + well_known_proto_libs(),
533        visibility = visibility,
534        testonly = testonly,
535        tags = tags,
536    )
537
538    tf_proto_library_cc(
539        name = name,
540        testonly = testonly,
541        srcs = srcs,
542        cc_grpc_version = cc_grpc_version,
543        use_grpc_namespace = use_grpc_namespace,
544        cc_libs = cc_libs,
545        make_default_target_header_only = make_default_target_header_only,
546        protodeps = protodeps,
547        visibility = visibility,
548    )
549
550    tf_proto_library_py(
551        name = name,
552        testonly = testonly,
553        srcs = srcs,
554        protodeps = protodeps,
555        srcs_version = "PY3",
556        use_grpc_plugin = has_services,
557        visibility = visibility,
558    )
559
560def tf_additional_lib_hdrs():
561    return [
562        "//tensorflow/core/platform/default:casts.h",
563        "//tensorflow/core/platform/default:context.h",
564        "//tensorflow/core/platform/default:cord.h",
565        "//tensorflow/core/platform/default:dynamic_annotations.h",
566        "//tensorflow/core/platform/default:integral_types.h",
567        "//tensorflow/core/platform/default:logging.h",
568        "//tensorflow/core/platform/default:mutex.h",
569        "//tensorflow/core/platform/default:mutex_data.h",
570        "//tensorflow/core/platform/default:notification.h",
571        "//tensorflow/core/platform/default:stacktrace.h",
572        "//tensorflow/core/platform/default:test_benchmark.h",
573        "//tensorflow/core/platform/default:tracing_impl.h",
574        "//tensorflow/core/platform/default:unbounded_work_queue.h",
575    ] + select({
576        "//tensorflow:windows": [
577            "//tensorflow/core/platform/windows:intrinsics_port.h",
578            "//tensorflow/core/platform/windows:stacktrace.h",
579            "//tensorflow/core/platform/windows:subprocess.h",
580            "//tensorflow/core/platform/windows:wide_char.h",
581            "//tensorflow/core/platform/windows:windows_file_system.h",
582        ],
583        "//conditions:default": [
584            "//tensorflow/core/platform/default:posix_file_system.h",
585            "//tensorflow/core/platform/default:subprocess.h",
586        ],
587    })
588
589def tf_additional_all_protos():
590    return [clean_dep("//tensorflow/core:protos_all")]
591
592def tf_protos_all_impl():
593    return [
594        clean_dep("//tensorflow/core/protobuf:autotuning_proto_cc_impl"),
595        clean_dep("//tensorflow/core/protobuf:conv_autotuning_proto_cc_impl"),
596        clean_dep("//tensorflow/core:protos_all_cc_impl"),
597    ]
598
599def tf_protos_all():
600    return if_static(
601        extra_deps = tf_protos_all_impl(),
602        otherwise = [clean_dep("//tensorflow/core:protos_all_cc")],
603    )
604
605def tf_protos_profiler_impl():
606    return [
607        clean_dep("//tensorflow/core/profiler/protobuf:xplane_proto_cc_impl"),
608        clean_dep("//tensorflow/core/profiler:profiler_options_proto_cc_impl"),
609    ]
610
611def tf_protos_profiler_service():
612    return [
613        clean_dep("//tensorflow/core/profiler:profiler_analysis_proto_cc_impl"),
614        clean_dep("//tensorflow/core/profiler:profiler_service_proto_cc_impl"),
615        clean_dep("//tensorflow/core/profiler:profiler_service_monitor_result_proto_cc_impl"),
616    ]
617
618def tf_protos_grappler_impl():
619    return [clean_dep("//tensorflow/core/grappler/costs:op_performance_data_cc_impl")]
620
621def tf_protos_grappler():
622    return if_static(
623        extra_deps = tf_protos_grappler_impl(),
624        otherwise = [clean_dep("//tensorflow/core/grappler/costs:op_performance_data_cc")],
625    )
626
627def tf_additional_device_tracer_srcs():
628    return [
629        "device_tracer_cuda.cc",
630        "device_tracer_rocm.cc",
631    ]
632
633def tf_additional_cupti_utils_cuda_deps():
634    return []
635
636def tf_additional_test_deps():
637    return []
638
639def tf_additional_test_srcs():
640    return [
641        "//tensorflow/core/platform/default:test.cc",
642        "//tensorflow/core/platform/default:test_benchmark.cc",
643    ]
644
645def tf_kernel_tests_linkstatic():
646    return 0
647
648def tf_additional_lib_deps():
649    """Additional dependencies needed to build TF libraries."""
650    return [
651        "@com_google_absl//absl/base:base",
652        "@com_google_absl//absl/container:inlined_vector",
653        "@com_google_absl//absl/types:span",
654        "@com_google_absl//absl/types:optional",
655    ] + if_static(
656        [clean_dep("@nsync//:nsync_cpp")],
657        [clean_dep("@nsync//:nsync_headers")],
658    )
659
660def tf_additional_core_deps():
661    return select({
662        clean_dep("//tensorflow:android"): [],
663        clean_dep("//tensorflow:ios"): [],
664        clean_dep("//tensorflow:linux_s390x"): [],
665        clean_dep("//tensorflow:no_gcp_support"): [],
666        "//conditions:default": [
667            "//tensorflow/core/platform/cloud:gcs_file_system",
668        ],
669    }) + select({
670        clean_dep("//tensorflow:no_hdfs_support"): [],
671        "//conditions:default": [
672            clean_dep("//tensorflow/core/platform/hadoop:hadoop_file_system"),
673        ],
674    }) + select({
675        clean_dep("//tensorflow:no_aws_support"): [],
676        "//conditions:default": [
677            clean_dep("//tensorflow/core/platform/s3:s3_file_system"),
678        ],
679    })
680
681def tf_lib_proto_parsing_deps():
682    return [
683        ":protos_all_cc",
684        clean_dep("//third_party/eigen3"),
685        clean_dep("//tensorflow/core/platform/default/build_config:proto_parsing"),
686    ]
687
688def tf_py_clif_cc(name, visibility = None, **kwargs):
689    pass
690
691def tf_pyclif_proto_library(
692        name,
693        proto_lib,
694        proto_srcfile = "",
695        visibility = None,
696        **kwargs):
697    native.filegroup(name = name)
698    native.filegroup(name = name + "_pb2")
699
700def tf_additional_binary_deps():
701    return [clean_dep("@nsync//:nsync_cpp")] + if_cuda(
702        [
703            clean_dep("//tensorflow/stream_executor:cuda_platform"),
704        ],
705    ) + if_rocm(
706        [
707            clean_dep("//tensorflow/stream_executor:rocm_platform"),
708            clean_dep("//tensorflow/core/platform/default/build_config:rocm"),
709        ],
710    ) + [
711        # TODO(allenl): Split these out into their own shared objects (they are
712        # here because they are shared between contrib/ op shared objects and
713        # core).
714        clean_dep("//tensorflow/core/kernels:lookup_util"),
715        clean_dep("//tensorflow/core/util/tensor_bundle"),
716    ] + if_mkl_ml(
717        [
718            clean_dep("//third_party/mkl:intel_binary_blob"),
719        ],
720    )
721
722def tf_additional_rpc_deps():
723    return []
724
725def tf_additional_tensor_coding_deps():
726    return []
727
728def tf_fingerprint_deps():
729    return [
730        "@farmhash_archive//:farmhash",
731    ]
732
733def tf_protobuf_deps():
734    return if_static(
735        [
736            clean_dep("@com_google_protobuf//:protobuf"),
737        ],
738        otherwise = [clean_dep("@com_google_protobuf//:protobuf_headers")],
739    )
740
741def tf_portable_proto_lib():
742    return ["//tensorflow/core:protos_all_cc_impl"]
743
744def tf_protobuf_compiler_deps():
745    return if_static(
746        [
747            clean_dep("@com_google_protobuf//:protobuf"),
748        ],
749        otherwise = [clean_dep("@com_google_protobuf//:protobuf_headers")],
750    )
751
752def tf_windows_aware_platform_deps(name):
753    return select({
754        "//tensorflow:windows": [
755            "//tensorflow/core/platform/windows:" + name,
756        ],
757        "//conditions:default": [
758            "//tensorflow/core/platform/default:" + name,
759        ],
760    })
761
762def tf_platform_deps(name, platform_dir = "//tensorflow/core/platform/"):
763    return [platform_dir + "default:" + name]
764
765def tf_testing_deps(name, platform_dir = "//tensorflow/core/platform/"):
766    return tf_platform_deps(name, platform_dir)
767
768def tf_stream_executor_deps(name, platform_dir = "//tensorflow/core/platform/"):
769    return tf_platform_deps(name, platform_dir)
770
771def tf_platform_alias(name, platform_dir = "//tensorflow/core/platform/"):
772    return [platform_dir + "default:" + name]
773
774def tf_logging_deps():
775    return ["//tensorflow/core/platform/default:logging"]
776
777def tf_resource_deps():
778    return ["//tensorflow/core/platform/default:resource"]
779
780def tf_portable_deps_no_runtime():
781    return [
782        "//third_party/eigen3",
783        "@double_conversion//:double-conversion",
784        "@nsync//:nsync_cpp",
785        "@com_googlesource_code_re2//:re2",
786        "@farmhash_archive//:farmhash",
787    ]
788
789def tf_google_mobile_srcs_no_runtime():
790    return []
791
792def tf_google_mobile_srcs_only_runtime():
793    return []
794
795def if_llvm_aarch64_available(then, otherwise = []):
796    return then
797
798def if_llvm_system_z_available(then, otherwise = []):
799    return select({
800        "//tensorflow:linux_s390x": then,
801        "//conditions:default": otherwise,
802    })
803
804def tf_tpu_dependencies():
805    return if_libtpu(["//tensorflow/core/tpu/kernels"])
806