diff --git a/WORKSPACE b/WORKSPACE index ad645add449..021ed6d2542 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -138,3 +138,7 @@ load("@upb//bazel:repository_defs.bzl", "bazel_version_repository") bazel_version_repository(name = "bazel_version") +load("//third_party/googleapis:repository_rules.bzl", "config_googleapis") + +config_googleapis() + diff --git a/tensorflow/opensource_only.files b/tensorflow/opensource_only.files index 6807e2b340c..fdb1b66943b 100644 --- a/tensorflow/opensource_only.files +++ b/tensorflow/opensource_only.files @@ -78,7 +78,10 @@ tensorflow/third_party/gif_fix_strtok_r.patch tensorflow/third_party/git/BUILD tensorflow/third_party/git/BUILD.tpl tensorflow/third_party/git/git_configure.bzl -tensorflow/third_party/googleapis.BUILD +tensorflow/third_party/googleapis/BUILD +tensorflow/third_party/googleapis/build_rules.bzl +tensorflow/third_party/googleapis/googleapis.BUILD +tensorflow/third_party/googleapis/repository_rules.bzl tensorflow/third_party/gpus/BUILD tensorflow/third_party/gpus/crosstool/BUILD tensorflow/third_party/gpus/crosstool/BUILD.rocm.tpl @@ -174,7 +177,6 @@ tensorflow/third_party/systemlibs/gast.BUILD tensorflow/third_party/systemlibs/gif.BUILD tensorflow/third_party/systemlibs/google_cloud_cpp.BUILD tensorflow/third_party/systemlibs/google_cloud_cpp.google.cloud.bigtable.BUILD -tensorflow/third_party/systemlibs/googleapis.BUILD tensorflow/third_party/systemlibs/grpc.BUILD tensorflow/third_party/systemlibs/jsoncpp.BUILD tensorflow/third_party/systemlibs/lmdb.BUILD diff --git a/tensorflow/workspace.bzl b/tensorflow/workspace.bzl index 10f5eb3dd63..8c4c8473faa 100755 --- a/tensorflow/workspace.bzl +++ b/tensorflow/workspace.bzl @@ -257,14 +257,13 @@ def tf_repositories(path_prefix = "", tf_repo_name = ""): ) tf_http_archive( - name = "com_github_googleapis_googleapis", - build_file = clean_dep("//third_party:googleapis.BUILD"), - sha256 = "824870d87a176f26bcef663e92051f532fac756d1a06b404055dc078425f4378", - strip_prefix = "googleapis-f81082ea1e2f85c43649bee26e0d9871d4b41cdb", - system_build_file = clean_dep("//third_party/systemlibs:googleapis.BUILD"), + name = "com_google_googleapis", + build_file = clean_dep("//third_party/googleapis:googleapis.BUILD"), + sha256 = "7ebab01b06c555f4b6514453dc3e1667f810ef91d1d4d2d3aa29bb9fcb40a900", + strip_prefix = "googleapis-541b1ded4abadcc38e8178680b0677f65594ea6f", urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/github.com/googleapis/googleapis/archive/f81082ea1e2f85c43649bee26e0d9871d4b41cdb.zip", - "https://github.com/googleapis/googleapis/archive/f81082ea1e2f85c43649bee26e0d9871d4b41cdb.zip", + "https://storage.googleapis.com/mirror.tensorflow.org/github.com/googleapis/googleapis/archive/541b1ded4abadcc38e8178680b0677f65594ea6f.zip", + "https://github.com/googleapis/googleapis/archive/541b1ded4abadcc38e8178680b0677f65594ea6f.zip", ], ) diff --git a/third_party/googleapis.BUILD b/third_party/googleapis.BUILD deleted file mode 100644 index 59a5758e3cf..00000000000 --- a/third_party/googleapis.BUILD +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2018 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -package(default_visibility = ["//visibility:public"]) - -licenses(["notice"]) # Apache 2.0 - -exports_files(["LICENSE"]) - -load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library") - -cc_proto_library( - name = "bigtable_protos", - srcs = [ - "google/api/annotations.proto", - "google/api/auth.proto", - "google/api/http.proto", - "google/bigtable/admin/v2/bigtable_instance_admin.proto", - "google/bigtable/admin/v2/bigtable_table_admin.proto", - "google/bigtable/admin/v2/common.proto", - "google/bigtable/admin/v2/instance.proto", - "google/bigtable/admin/v2/table.proto", - "google/bigtable/v2/bigtable.proto", - "google/bigtable/v2/data.proto", - "google/iam/v1/iam_policy.proto", - "google/iam/v1/policy.proto", - "google/longrunning/operations.proto", - "google/rpc/error_details.proto", - "google/rpc/status.proto", - ], - include = ".", - default_runtime = "@com_google_protobuf//:protobuf", - protoc = "@com_google_protobuf//:protoc", - use_grpc_plugin = True, - deps = ["@com_google_protobuf//:cc_wkt_protos"], -) diff --git a/third_party/googleapis/BUILD b/third_party/googleapis/BUILD new file mode 100644 index 00000000000..09983eb515d --- /dev/null +++ b/third_party/googleapis/BUILD @@ -0,0 +1,39 @@ +# Copyright 2020 The TensorFlow Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +licenses(["notice"]) + +cc_library( + name = "grpc_all_cc", + visibility = ["//tensorflow/core/platform/cloud:__pkg__"], + deps = [ + "@com_google_googleapis//google/monitoring/v3:monitoring_cc_grpc", + ], +) + +cc_library( + name = "protos_all_cc", + visibility = ["//tensorflow/core/platform/cloud:__pkg__"], + deps = [ + "@com_google_googleapis//google/monitoring/v3:monitoring_cc_proto_headers_only", + ], +) + +cc_library( + name = "protos_all_cc_impl", + visibility = ["//tensorflow/core/platform/cloud:__pkg__"], + deps = [ + "@com_google_googleapis//google/monitoring/v3:monitoring_cc_proto", + ], +) diff --git a/third_party/googleapis/build_rules.bzl b/third_party/googleapis/build_rules.bzl new file mode 100644 index 00000000000..d92ed1c5a13 --- /dev/null +++ b/third_party/googleapis/build_rules.bzl @@ -0,0 +1,87 @@ +# Copyright 2020 The TensorFlow Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Utilities for building grpc and proto libraries from googleapis. +""" + +load("@rules_cc//cc:defs.bzl", native_cc_proto_library = "cc_proto_library") +load("@com_github_grpc_grpc//bazel:generate_cc.bzl", "generate_cc") + +def _tf_cc_headers(ctx): + if len(ctx.attr.deps) != 1: + fail("deps must have exactly 1 photo_library") + return [ + CcInfo( + compilation_context = ctx.attr.deps[0][CcInfo].compilation_context, + ), + DefaultInfo( + files = ctx.attr.deps[0][CcInfo].compilation_context.headers, + ), + ] + +tf_cc_headers = rule( + implementation = _tf_cc_headers, + attrs = { + "deps": attr.label_list(providers = [CcInfo]), + }, +) + +def cc_proto_library(name, deps): + """Generates a cc library and a header only cc library from a proto library + + Args: + name: the name of the cc_library + deps: a list that contains exactly one proto_library + """ + native_cc_proto_library( + name = name, + deps = deps, + visibility = ["//visibility:public"], + ) + tf_cc_headers( + name = name + "_headers_only", + deps = [":" + name], + visibility = ["//visibility:public"], + ) + +def cc_grpc_library(name, srcs, deps, **kwargs): + """Generates a cc library with grpc implementation and cc proto headers + + Args: + name: the name of the cc_grpc_library to be created + srcs: the proto_libraries used to generate the cc_grpc_library + deps: the dependencies used to link into this cc_grpc_library, defined by + cc_proto_library + **kwargs: other args not used, for compatibility only + """ + if len(srcs) != 1: + fail("srcs must have exactly 1 photo_library", "srcs") + codegen_grpc_target = "_" + name + "_grpc_codegen" + generate_cc( + name = codegen_grpc_target, + srcs = srcs, + plugin = "@com_github_grpc_grpc//src/compiler:grpc_cpp_plugin", + well_known_protos = True, + generate_mocks = True, + ) + + grpc_proto_dep = "@com_github_grpc_grpc//:grpc++_codegen_proto" + native.cc_library( + name = name, + srcs = [":" + codegen_grpc_target], + hdrs = [":" + codegen_grpc_target], + deps = [dep + "_headers_only" for dep in deps] + [grpc_proto_dep], + visibility = ["//visibility:public"], + ) diff --git a/third_party/googleapis/googleapis.BUILD b/third_party/googleapis/googleapis.BUILD new file mode 100644 index 00000000000..d1b86f4cecc --- /dev/null +++ b/third_party/googleapis/googleapis.BUILD @@ -0,0 +1,19 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) # Apache 2.0 + +exports_files(["LICENSE"]) diff --git a/third_party/googleapis/repository_rules.bzl b/third_party/googleapis/repository_rules.bzl new file mode 100644 index 00000000000..b178437fae5 --- /dev/null +++ b/third_party/googleapis/repository_rules.bzl @@ -0,0 +1,47 @@ +# Copyright 2020 The TensorFlow Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Utilities for configuring googleapis in workspace external dependency. +""" + +load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language") + +def config_googleapis(): + """Configures external dependency googleapis to use Google's C++ gRPC APIs + + To avoid ODR violation, the cc proto libraries (*.pb.cc) must be + statically linked to libtensorflow_framework.so, whereas cc grpc libraries + (*.grpc.pb.cc) must be statically linked to _pywrap_tensorflow.so. + + To achieve this, Bazel rules are overridden to + (1) generate headers-only proto library, and + (2) build grpc library depending on the cc headers instead of the cc proto + library. + """ + switched_rules_by_language( + name = "com_google_googleapis_imports", + cc = True, + grpc = True, + rules_override = { + "cc_proto_library": [ + "@org_tensorflow//third_party/googleapis:build_rules.bzl", + "", + ], + "cc_grpc_library": [ + "@org_tensorflow//third_party/googleapis:build_rules.bzl", + "", + ], + }, + ) diff --git a/third_party/systemlibs/googleapis.BUILD b/third_party/systemlibs/googleapis.BUILD deleted file mode 100644 index 7687745df9a..00000000000 --- a/third_party/systemlibs/googleapis.BUILD +++ /dev/null @@ -1,12 +0,0 @@ -licenses(["notice"]) # Apache 2.0 - -filegroup( - name = "LICENSE", - visibility = ["//visibility:public"], -) - -cc_library( - name = "bigtable_protos", - linkopts = ["-lbigtable_protos"], - visibility = ["//visibility:public"], -)