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