Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Thirdparty] Upgrade protobuf to 3.9.2. #817

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ build --announce_rc
# Other build flags.
build --define=grpc_no_ares=true

build --incompatible_remove_legacy_whole_archive

# Modular TF build options
build:dynamic_kernels --define=dynamic_loaded_kernels=true
build:dynamic_kernels --copt=-DAUTOLOAD_DYNAMIC_KERNELS
Expand Down
2 changes: 2 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ http_archive(
name = "io_bazel_rules_closure",
sha256 = "5b00383d08dd71f28503736db0500b6fb4dda47489ff5fc6bed42557c07c6ba9",
strip_prefix = "rules_closure-308b05b2419edb5c8ee0471b67a40403df940149",
patch_args = ["-p1"],
patches = ["//third_party:io_bazel_rules_closure.patch"],
urls = [
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz",
"https://github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz", # 2019-06-13
Expand Down
1 change: 1 addition & 0 deletions serving/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def write_config():
bazel_rc.write('build --define grpc_no_ares=true\n')

bazel_rc.write('build --define open_source_build=true\n')
bazel_rc.write('build --spawn_strategy=standalone\n')
bazel_rc.write('build --cxxopt="-std=c++14"\n')
bazel_rc.write('build --host_cxxopt=-std=c++14\n')
bazel_rc.write('build --action_env TF_USE_CCACHE="0"\n')
Expand Down
28 changes: 28 additions & 0 deletions tensorflow/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,18 @@ tf_cc_shared_object(
] + tf_additional_binary_deps(),
)

# This is intended to be the same as tf_binary_additional_srcs:
# https://github.com/tensorflow/tensorflow/blob/cd67f4f3723f9165aabedd0171aaadc6290636e5/tensorflow/tensorflow.bzl#L396-L425
# And is usable in the "deps" attribute instead of the "srcs" attribute
# as a workaround for https://github.com/tensorflow/tensorflow/issues/34117
cc_import(
name = "libtensorflow_framework_import_lib",
shared_library = select({
"//tensorflow:macos": ":libtensorflow_framework.dylib",
"//conditions:default": ":libtensorflow_framework.so",
}),
)

# -------------------------------------------
# New rules should be added above this target.
# -------------------------------------------
Expand Down Expand Up @@ -684,6 +696,7 @@ tf_cc_shared_object(
per_os_targets = True,
soversion = VERSION,
visibility = ["//visibility:public"],
linkstatic = 1,
# add win_def_file for tensorflow_cc
win_def_file = select({
# We need this DEF file to properly export symbols on Windows
Expand All @@ -706,6 +719,21 @@ tf_cc_shared_object(
"//tensorflow/contrib/tensor_forest:model_ops_lib",
"//tensorflow/contrib/tensor_forest:forest_proto_impl",
"//tensorflow/contrib/tensor_forest/kernels/v4:decision-tree-resource_impl",
"//tensorflow/core:lib",
"//tensorflow/core:lib_internal",
"//tensorflow/core:lib_internal_impl",
"//tensorflow/core:core_cpu_impl",
"//tensorflow/core:framework_internal",
"//tensorflow/core:framework_internal_impl",
"//tensorflow/core:gpu_runtime_impl",
"//tensorflow/cc/saved_model:loader",
"//tensorflow/cc/saved_model:loader_lite",
"//tensorflow/cc/saved_model:loader_lite_impl",
"//tensorflow/stream_executor:dnn_proto_cc",
"//tensorflow/stream_executor:dnn_proto_cc_impl",
"//tensorflow/core/platform:tensor_float_32_utils",
"//tensorflow/core/grappler/optimizers:custom_graph_optimizer_registry_impl",
"@nsync//:nsync_cpp",
] + if_ngraph(["@ngraph_tf//:ngraph_tf"]),
)

Expand Down
6 changes: 6 additions & 0 deletions tensorflow/c/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ tf_cuda_library(
":tf_status_internal",
":tf_tensor_internal",
],
alwayslink = 1,
)

cc_library(
Expand All @@ -110,13 +111,16 @@ tf_cuda_library(
":c_api_internal",
":tf_attrtype",
":tf_status_internal",
":tf_status",
"@com_google_protobuf//:protobuf",
] + select({
"//tensorflow:with_xla_support": [
"//tensorflow/compiler/tf2xla:xla_compiler",
"//tensorflow/compiler/jit",
],
"//conditions:default": [],
}),
alwayslink = 1,
)

tf_cuda_library(
Expand Down Expand Up @@ -176,6 +180,7 @@ tf_cuda_library(
"//tensorflow/core:lib",
],
}),
alwayslink = 1,
)

cc_library(
Expand All @@ -192,6 +197,7 @@ cc_library(
"//tensorflow/core:lib",
],
}),
alwayslink = 1,
)

cc_library(
Expand Down
2 changes: 2 additions & 0 deletions tensorflow/core/platform/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ cc_library(
":platform",
":types",
],
alwayslink = 1,
)

cc_library(
Expand Down Expand Up @@ -176,6 +177,7 @@ cc_library(
"platform_strings_computed.h",
],
hdrs = ["platform_strings.h"],
alwayslink = 1,
)

cc_library(
Expand Down
5 changes: 5 additions & 0 deletions tensorflow/tensorflow.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,11 @@ def tf_cc_binary(
[
clean_dep("//third_party/mkl:intel_binary_blob"),
],
) + if_static(
extra_deps = [],
otherwise = [
clean_dep("//tensorflow:libtensorflow_framework_import_lib"),
],
),
data = depset(data + added_data_deps),
linkopts = linkopts + _rpath_linkopts(name_os),
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/tools/pip_package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
'numpy >= 1.16.0, < 1.19.0',
'opt_einsum >= 2.3.2',
'six >= 1.10.0',
'protobuf >= 3.6.1',
'protobuf >= 3.9.2',
'tensorboard >= 1.15.0, < 1.16.0',
'tensorflow-estimator >= 1.15.1, < 1.15.5',
'termcolor >= 1.1.0',
Expand Down
23 changes: 7 additions & 16 deletions tensorflow/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -511,28 +511,19 @@ def tf_repositories(path_prefix = "", tf_repo_name = ""):
},
)

# 310ba5ee72661c081129eb878c1bbcec936b20f0 is based on 3.8.0 with a fix for protobuf.bzl.
PROTOBUF_URLS = [
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/protocolbuffers/protobuf/archive/310ba5ee72661c081129eb878c1bbcec936b20f0.tar.gz",
"https://github.com/protocolbuffers/protobuf/archive/310ba5ee72661c081129eb878c1bbcec936b20f0.tar.gz",
]
PROTOBUF_SHA256 = "b9e92f9af8819bbbc514e2902aec860415b70209f31dfc8c4fa72515a5df9d59"
PROTOBUF_STRIP_PREFIX = "protobuf-310ba5ee72661c081129eb878c1bbcec936b20f0"

# protobuf depends on @zlib, it has to be renamed to @zlib_archive because "zlib" is already
# defined using bind for grpc.
PROTOBUF_PATCH = "//third_party/protobuf:protobuf.patch"

tf_http_archive(
name = "com_google_protobuf", # MIT license
patch_file = [clean_dep(PROTOBUF_PATCH)],
sha256 = PROTOBUF_SHA256,
strip_prefix = PROTOBUF_STRIP_PREFIX,
patch_file = [clean_dep("//third_party/protobuf:protobuf.patch")],
sha256 = "cfcba2df10feec52a84208693937c17a4b5df7775e1635c1e3baffc487b24c9b",
strip_prefix = "protobuf-3.9.2",
system_build_file = clean_dep("//third_party/systemlibs:protobuf.BUILD"),
system_link_files = {
"//third_party/systemlibs:protobuf.bzl": "protobuf.bzl",
},
urls = PROTOBUF_URLS,
urls = [
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/protocolbuffers/protobuf/archive/v3.9.2.zip",
"https://github.com/protocolbuffers/protobuf/archive/v3.9.2.zip",
],
)

tf_http_archive(
Expand Down
37 changes: 37 additions & 0 deletions third_party/io_bazel_rules_closure.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
From 18efd193ad8e10e2ea95bcf1754459fe34f6e96a Mon Sep 17 00:00:00 2001
From: Tongxuan Liu <[email protected]>
Date: Thu, 27 Apr 2023 16:10:04 +0800
Subject: [PATCH] update zlib urls.

---
WORKSPACE | 2 +-
closure/repositories.bzl | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/WORKSPACE b/WORKSPACE
index cb9eee5..1b03da7 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -11,7 +11,7 @@ http_archive(
build_file = "//:third_party/zlib.BUILD",
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
strip_prefix = "zlib-1.2.11",
- urls = ["https://zlib.net/zlib-1.2.11.tar.gz"],
+ urls = ["https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz"],
)

http_archive(
diff --git a/closure/repositories.bzl b/closure/repositories.bzl
index f21ff2b..dee10ba 100644
--- a/closure/repositories.bzl
+++ b/closure/repositories.bzl
@@ -1005,5 +1005,5 @@ def zlib():
build_file = "@io_bazel_rules_closure//:third_party/zlib.BUILD",
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
strip_prefix = "zlib-1.2.11",
- urls = ["https://zlib.net/zlib-1.2.11.tar.gz"],
+ urls = ["https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz"],
)
--
2.37.1

61 changes: 50 additions & 11 deletions third_party/protobuf/protobuf.patch
Original file line number Diff line number Diff line change
@@ -1,30 +1,69 @@
From 92fc8b1f8fe8bc095708f200fa59e7808ef55fc0 Mon Sep 17 00:00:00 2001
From: Tongxuan Liu <[email protected]>
Date: Thu, 20 Apr 2023 19:11:22 +0800
Subject: [PATCH] Protobuf patch for DeepRec.

---
BUILD | 4 +++-
protobuf.bzl | 2 ++
protobuf_deps.bzl | 2 +-
3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/BUILD b/BUILD
index 2fb26050..c2744d5b 100644
index dbae719..87dc384 100644
--- a/BUILD
+++ b/BUILD
@@ -19,7 +19,7 @@ config_setting(
@@ -23,7 +23,7 @@ config_setting(
# ZLIB configuration
################################################################################

-ZLIB_DEPS = ["@zlib//:zlib"]
+ZLIB_DEPS = ["@zlib_archive//:zlib"]
+ZLIB_DEPS = ["@zlib"]

################################################################################
# Protobuf Runtime Library
@@ -209,6 +209,7 @@ cc_library(
@@ -143,6 +143,7 @@ cc_library(
copts = COPTS,
includes = ["src/"],
linkopts = LINK_OPTS,
+ alwayslink = 1,
visibility = ["//visibility:public"],
deps = [":protobuf_lite"] + PROTOBUF_DEPS,
)
@@ -219,7 +220,7 @@ cc_library(
# TODO(keveman): Remove this target once the support gets added to Bazel.
cc_library(
name = "protobuf_headers",
- hdrs = glob(["src/**/*.h"]),
+ hdrs = glob(["src/**/*.h", "src/**/*.inc"]),

@@ -213,6 +214,7 @@ cc_library(
copts = COPTS,
includes = ["src/"],
linkopts = LINK_OPTS,
+ alwayslink = 1,
visibility = ["//visibility:public"],
deps = [":protobuf_lite"] + PROTOBUF_DEPS,
)
diff --git a/protobuf.bzl b/protobuf.bzl
index e065332..92ae3b4 100644
--- a/protobuf.bzl
+++ b/protobuf.bzl
@@ -85,6 +85,8 @@ def _proto_gen_impl(ctx):
for dep in ctx.attr.deps:
import_flags += dep.proto.import_flags
deps += dep.proto.deps
+ import_flags = depset(import_flags).to_list()
+ deps = depset(deps).to_list()

if not ctx.attr.gen_cc and not ctx.attr.gen_py and not ctx.executable.plugin:
return struct(
diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl
index 57509ee..00325aa 100644
--- a/protobuf_deps.bzl
+++ b/protobuf_deps.bzl
@@ -11,7 +11,7 @@ def protobuf_deps():
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
strip_prefix = "zlib-1.2.11",
- urls = ["https://zlib.net/zlib-1.2.11.tar.gz"],
+ urls = ["https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz"],
)

if not native.existing_rule("six"):
--
2.37.1