Skip to content

Commit a507457

Browse files
authored
Upgrade bazel to v6.5.0, upgrade protobuf, tensorflow and dependent deps (#2290)
Summary: Upgrade Bazel from 6.2.0 to 6.5.0 along with protobuf, tensorflow, and related dependencies. This is a coordinated upgrade since these dependencies have hard interdependencies that make incremental upgrades difficult. Key changes - Upgrade Bazel from 6.2.0 to 6.5.0 (required by these new dependencies) - Protobuf upgrade with compatibility patches for text format handling and JavaScript generation - TensorFlow upgrade with patches to disable GPU/LLVM/Python features. The GPU disable patch will not be necessary as TensorFlow's fallback logic will work with Bazel 7 - gRPC-web upgrade to 2.0.2 and replacement of the vendored `protoc-gen-grpc-web` with a Bazel repository - Flatbuffers patched to remove rules_js dependency (this upgrade is required by TensorFlow v2.20.0) - absl upgrade (causes transitive header changes) - Regenerated TypeScript protobuf bindings for the UI I attempted to split this into a smaller change in #2296. TensorFlow has a tight dependency on protobuf, which prevented that attempt from working. I'm open to other ideas on how to split this up, but so far this seemed like the best balance with #2293 and #2297 to follow to complete the Bazel 7 migration. Relevant Issues: #2282 Type of change: /kind cleanup Test Plan: Build passes --------- Signed-off-by: Dom Del Nano <[email protected]>
1 parent 521c0e2 commit a507457

33 files changed

+1462
-2629
lines changed

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.2.0
1+
6.5.0
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
diff --git a/BUILD.bazel b/BUILD.bazel
2+
index b4f015a0..70848962 100644
3+
--- a/BUILD.bazel
4+
+++ b/BUILD.bazel
5+
@@ -1,5 +1,3 @@
6+
-load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
7+
-load("@npm//:defs.bzl", "npm_link_all_packages")
8+
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
9+
10+
licenses(["notice"])
11+
@@ -8,12 +6,7 @@ package(
12+
default_visibility = ["//visibility:public"],
13+
)
14+
15+
-npm_link_all_packages(name = "node_modules")
16+
17+
-npm_link_package(
18+
- name = "node_modules/flatbuffers",
19+
- src = "//ts:flatbuffers",
20+
-)
21+
22+
exports_files([
23+
"LICENSE",
24+
@@ -40,11 +33,9 @@ filegroup(
25+
"BUILD.bazel",
26+
"WORKSPACE",
27+
"build_defs.bzl",
28+
- "typescript.bzl",
29+
"//grpc/src/compiler:distribution",
30+
"//reflection:distribution",
31+
"//src:distribution",
32+
- "//ts:distribution",
33+
] + glob([
34+
"include/flatbuffers/*.h",
35+
]),

bazel/external/grpc-web_protobuf_v30_support.patch

Lines changed: 409 additions & 0 deletions
Large diffs are not rendered by default.

bazel/external/grpc_go_toolchain.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ diff --git a/bazel/grpc_extra_deps.bzl b/bazel/grpc_extra_deps.bzl
22
index 4d8afa3131..514189f9a5 100644
33
--- a/bazel/grpc_extra_deps.bzl
44
+++ b/bazel/grpc_extra_deps.bzl
5-
@@ -53,7 +53,7 @@ def grpc_extra_deps(ignore_version_differences = False):
5+
@@ -63,7 +63,7 @@ def grpc_extra_deps(ignore_version_differences = False):
66
api_dependencies()
7-
7+
88
go_rules_dependencies()
9-
- go_register_toolchains(version = "1.18")
9+
- go_register_toolchains(version = "1.22.5")
1010
+ go_register_toolchains()
1111
gazelle_dependencies()
12-
12+
1313
# Pull-in the go 3rd party dependencies for protoc_gen_validate, which is

bazel/external/grpc_test_visibility.patch

Lines changed: 0 additions & 13 deletions
This file was deleted.

bazel/external/protobuf_javascript.patch

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
diff --git a/generator/BUILD.bazel b/generator/BUILD.bazel
2+
index ac7756d..a3480c8 100644
3+
--- a/generator/BUILD.bazel
4+
+++ b/generator/BUILD.bazel
5+
@@ -2,7 +2,7 @@ genrule(
6+
name = "generate_version_header",
7+
srcs = ["//:package.json"],
8+
outs = ["version.h"],
9+
- cmd = "node $(location //:generate-version-header.js) $(OUTS)",
10+
+ cmd = "/opt/px_dev/tools/node/bin/node $(location //:generate-version-header.js) $(OUTS)",
11+
tools = ["//:generate-version-header.js"],
12+
)
13+
114
diff --git a/generator/js_generator.cc b/generator/js_generator.cc
2-
index 97b5844..1351a54 100644
15+
index 7ba8bf0..09b1391 100644
316
--- a/generator/js_generator.cc
417
+++ b/generator/js_generator.cc
5-
@@ -3650,6 +3650,9 @@ void Generator::GenerateFile(const GeneratorOptions& options,
18+
@@ -3647,6 +3647,9 @@ void Generator::GenerateFile(const GeneratorOptions& options,
619

720
for (int i = 0; i < file->dependency_count(); i++) {
8-
const std::string& name = file->dependency(i)->name();
21+
const std::string name = std::string(file->dependency(i)->name());
922
+ if (ModuleAlias(name) == "gogoproto_gogo_pb") {
1023
+ continue;
1124
+ }

bazel/external/protobuf_text_format.patch

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,13 @@
1-
diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc
2-
index 594c8eac6..c7ef9437b 100644
3-
--- a/src/google/protobuf/stubs/strutil.cc
4-
+++ b/src/google/protobuf/stubs/strutil.cc
5-
@@ -592,7 +592,7 @@ void CEscapeAndAppend(StringPiece src, std::string *dest) {
6-
}
7-
}
8-
9-
-std::string CEscape(const std::string &src) {
10-
+std::string CEscape(StringPiece src) {
11-
std::string dest;
12-
CEscapeAndAppend(src, &dest);
13-
return dest;
14-
diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h
15-
index 9658abf90..9cf9cae83 100644
16-
--- a/src/google/protobuf/stubs/strutil.h
17-
+++ b/src/google/protobuf/stubs/strutil.h
18-
@@ -328,7 +328,7 @@ PROTOBUF_EXPORT std::string UnescapeCEscapeString(const std::string& src);
19-
//
20-
// Escaped chars: \n, \r, \t, ", ', \, and !isprint().
21-
// ----------------------------------------------------------------------
22-
-PROTOBUF_EXPORT std::string CEscape(const std::string& src);
23-
+PROTOBUF_EXPORT std::string CEscape(StringPiece src);
24-
25-
// ----------------------------------------------------------------------
26-
// CEscapeAndAppend()
271
diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc
28-
index 19110499d..0d116ee7e 100644
2+
index 2c0a95d..1234567 100644
293
--- a/src/google/protobuf/text_format.cc
304
+++ b/src/google/protobuf/text_format.cc
31-
@@ -81,6 +81,18 @@ inline bool IsOctNumber(const std::string& str) {
5+
@@ -82,6 +82,18 @@ inline bool IsOctNumber(const std::string& str) {
326
(str[1] >= '0' && str[1] < '8'));
337
}
34-
35-
+// Returns true if truncatation occurred.
36-
+bool TruncateString(int64_t max_length, StringPiece* s) {
8+
9+
+// Returns true if truncation occurred.
10+
+bool TruncateString(int64_t max_length, absl::string_view* s) {
3711
+ if (max_length > 0) {
3812
+ int64_t excess = static_cast<int64_t>(s->size()) - max_length;
3913
+ if (excess > 0) {
@@ -44,10 +18,10 @@ index 19110499d..0d116ee7e 100644
4418
+ return false;
4519
+}
4620
+
47-
} // namespace
48-
49-
namespace internal {
50-
@@ -2555,20 +2567,22 @@ void TextFormat::Printer::PrintFieldValue(const Message& message,
21+
// The number of fields that are redacted in AbslStringify.
22+
std::atomic<int64_t> num_redacted_field{0};
23+
24+
@@ -2738,20 +2750,22 @@ void TextFormat::Printer::PrintFieldValue(const Message& message,
5125
? reflection->GetRepeatedStringReference(message, field, index,
5226
&scratch)
5327
: reflection->GetStringReference(message, field, &scratch);
@@ -60,39 +34,39 @@ index 19110499d..0d116ee7e 100644
6034
- "...<truncated>...";
6135
- value_to_print = &truncated_value;
6236
- }
63-
+ StringPiece value_to_print(value);
37+
+ absl::string_view value_to_print(value);
6438
+ bool truncated = TruncateString(truncate_string_field_longer_than_, &value_to_print);
6539
+
6640
if (field->type() == FieldDescriptor::TYPE_STRING) {
6741
- printer->PrintString(*value_to_print, generator);
6842
+ if (truncated) {
69-
+ printer->PrintString(StrCat(value_to_print, "...<truncated>..."), generator);
43+
+ printer->PrintString(absl::StrCat(value_to_print, "...<truncated>..."), generator);
7044
+ } else {
7145
+ printer->PrintString(value, generator);
7246
+ }
7347
} else {
74-
GOOGLE_DCHECK_EQ(field->type(), FieldDescriptor::TYPE_BYTES);
48+
ABSL_DCHECK_EQ(field->type(), FieldDescriptor::TYPE_BYTES);
7549
- printer->PrintBytes(*value_to_print, generator);
7650
+ if (truncated) {
77-
+ printer->PrintBytes(StrCat(value_to_print, "...<truncated>..."), generator);
51+
+ printer->PrintBytes(absl::StrCat(value_to_print, "...<truncated>..."), generator);
7852
+ } else {
7953
+ printer->PrintBytes(value, generator);
8054
+ }
8155
}
8256
break;
8357
}
84-
@@ -2708,7 +2722,14 @@ void TextFormat::Printer::PrintUnknownFields(
85-
// This field is not parseable as a Message (or we ran out of
86-
// recursion budget). So it is probably just a plain string.
87-
generator->PrintMaybeWithMarker(": ", "\"");
88-
- generator->PrintString(CEscape(value));
89-
+ StringPiece value_to_print(value);
58+
@@ -2937,7 +2951,14 @@ void TextFormat::Printer::PrintUnknownFields(
59+
break;
60+
}
61+
generator->PrintMaybeWithMarker(MarkerToken(), ": ", "\"");
62+
- generator->PrintString(absl::CEscape(value));
63+
+ absl::string_view value_to_print(value);
9064
+ bool truncated = TruncateString(truncate_string_field_longer_than_, &value_to_print);
9165
+
9266
+ if (truncated) {
93-
+ generator->PrintString(CEscape(value_to_print) + "...<truncated>...");
67+
+ generator->PrintString(absl::StrCat(absl::CEscape(value_to_print), "...<truncated>..."));
9468
+ } else {
95-
+ generator->PrintString(CEscape(value));
69+
+ generator->PrintString(absl::CEscape(value));
9670
+ }
9771
if (single_line_mode_) {
9872
generator->PrintLiteral("\" ");

bazel/external/protobuf_warning.patch

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ index 5e9a2c418..f95684bd1 100644
1414
virtual_path = "";
1515
disk_path = parts[i];
1616
diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc
17-
index 5f3427dc7..ab049c7c6 100644
17+
index 7456d3c3d..ddcd08c17 100644
1818
--- a/src/google/protobuf/descriptor.cc
1919
+++ b/src/google/protobuf/descriptor.cc
20-
@@ -8161,10 +8161,11 @@ void DescriptorBuilder::LogUnusedDependency(const FileDescriptorProto& proto,
20+
@@ -10410,10 +10410,11 @@ void DescriptorBuilder::LogUnusedDependency(const FileDescriptorProto& proto,
2121
if (is_error) {
22-
AddError((*it)->name(), proto, DescriptorPool::ErrorCollector::IMPORT,
23-
error_message);
22+
AddError(unused->name(), proto, DescriptorPool::ErrorCollector::IMPORT,
23+
make_error);
2424
- } else {
25-
- AddWarning((*it)->name(), proto, DescriptorPool::ErrorCollector::IMPORT,
26-
- error_message);
25+
- AddWarning(unused->name(), proto,
26+
- DescriptorPool::ErrorCollector::IMPORT, make_error);
2727
}
2828
+ // else {
29-
+ // AddWarning((*it)->name(), proto, DescriptorPool::ErrorCollector::IMPORT,
30-
+ // error_message);
29+
+ // AddWarning(unused->name(), proto,
30+
+ // DescriptorPool::ErrorCollector::IMPORT, make_error);
3131
+ // }
3232
}
3333
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
diff --git a/third_party/xla/third_party/gpus/cuda_configure.bzl b/third_party/xla/third_party/gpus/cuda_configure.bzl
2+
index d110fa81460..80fccbfa234 100644
3+
--- a/third_party/xla/third_party/gpus/cuda_configure.bzl
4+
+++ b/third_party/xla/third_party/gpus/cuda_configure.bzl
5+
@@ -278,7 +278,7 @@ def _cuda_include_path(repository_ctx, cuda_config):
6+
7+
def enable_cuda(repository_ctx):
8+
"""Returns whether to build with CUDA support."""
9+
- return int(get_host_environ(repository_ctx, "TF_NEED_CUDA", False))
10+
+ return int(False)
11+
12+
def matches_version(environ_version, detected_version):
13+
"""Checks whether the user-specified version matches the detected version.
14+
diff --git a/third_party/xla/third_party/gpus/rocm_configure.bzl b/third_party/xla/third_party/gpus/rocm_configure.bzl
15+
index 80c151cde4d..b044e061473 100644
16+
--- a/third_party/xla/third_party/gpus/rocm_configure.bzl
17+
+++ b/third_party/xla/third_party/gpus/rocm_configure.bzl
18+
@@ -158,12 +158,6 @@ def _rocm_include_path(repository_ctx, rocm_config, bash_bin):
19+
return inc_dirs
20+
21+
def _enable_rocm(repository_ctx):
22+
- enable_rocm = get_host_environ(repository_ctx, "TF_NEED_ROCM")
23+
- if enable_rocm == "1":
24+
- if get_cpu_value(repository_ctx) != "Linux":
25+
- auto_configure_warning("ROCm configure is only supported on Linux")
26+
- return False
27+
- return True
28+
return False
29+
30+
def _amdgpu_targets(repository_ctx, rocm_toolkit_path, bash_bin):
31+
diff --git a/third_party/xla/third_party/gpus/sycl_configure.bzl b/third_party/xla/third_party/gpus/sycl_configure.bzl
32+
index ee63624f8e4..d60a10b10d6 100644
33+
--- a/third_party/xla/third_party/gpus/sycl_configure.bzl
34+
+++ b/third_party/xla/third_party/gpus/sycl_configure.bzl
35+
@@ -63,7 +63,7 @@ def _sycl_include_path(repository_ctx, sycl_config, bash_bin):
36+
37+
def enable_sycl(repository_ctx):
38+
"""Returns whether to build with SYCL support."""
39+
- return int(get_host_environ(repository_ctx, "TF_NEED_SYCL", False))
40+
+ return int(False)
41+
42+
def auto_configure_fail(msg):
43+
"""Output failure message when auto configuration fails."""
44+
diff --git a/third_party/xla/third_party/tensorrt/tensorrt_configure.bzl b/third_party/xla/third_party/tensorrt/tensorrt_configure.bzl
45+
index 32c6d96f161..169df9b2a8b 100644
46+
--- a/third_party/xla/third_party/tensorrt/tensorrt_configure.bzl
47+
+++ b/third_party/xla/third_party/tensorrt/tensorrt_configure.bzl
48+
@@ -154,7 +154,7 @@ def _create_dummy_repository(repository_ctx):
49+
50+
def enable_tensorrt(repository_ctx):
51+
"""Returns whether to build with TensorRT support."""
52+
- return int(get_host_environ(repository_ctx, _TF_NEED_TENSORRT, False))
53+
+ return int(False)
54+
55+
def _get_tensorrt_static_path(repository_ctx):
56+
"""Returns the path for TensorRT static libraries."""
57+
@@ -284,7 +284,7 @@ def _py_tmpl_dict(d):
58+
def _tensorrt_configure_impl(repository_ctx):
59+
"""Implementation of the tensorrt_configure repository rule."""
60+
61+
- if get_host_environ(repository_ctx, _TF_TENSORRT_CONFIG_REPO) != None:
62+
+ if False:
63+
# Forward to the pre-configured remote repository.
64+
remote_config_repo = repository_ctx.os.environ[_TF_TENSORRT_CONFIG_REPO]
65+
repository_ctx.template("BUILD", config_repo_label(remote_config_repo, ":BUILD"), {})
Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,67 @@
1+
diff --git a/tensorflow/workspace1.bzl b/tensorflow/workspace1.bzl
2+
index b6755a6e68b..9d6562457b5 100644
3+
--- a/tensorflow/workspace1.bzl
4+
+++ b/tensorflow/workspace1.bzl
5+
@@ -4,7 +4,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
6+
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
7+
load("@com_google_benchmark//:bazel/benchmark_deps.bzl", "benchmark_deps")
8+
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
9+
-load("@local_xla//third_party/llvm:setup.bzl", "llvm_setup")
10+
+# load("@local_xla//third_party/llvm:setup.bzl", "llvm_setup")
11+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
12+
load("//third_party/android:android_configure.bzl", "android_configure")
13+
14+
@@ -15,7 +15,7 @@ def workspace(with_rules_cc = True):
15+
Args:
16+
with_rules_cc: Unused, to be removed soon.
17+
"""
18+
- llvm_setup(name = "llvm-project")
19+
+ # llvm_setup(name = "llvm-project")
20+
# native.register_toolchains("@local_config_python//:py_toolchain")
21+
rules_pkg_dependencies()
22+
123
diff --git a/tensorflow/workspace2.bzl b/tensorflow/workspace2.bzl
2-
index 18b63ab47fb..92993d7c341 100644
24+
index e91df06041d..ce281ccf21c 100644
325
--- a/tensorflow/workspace2.bzl
426
+++ b/tensorflow/workspace2.bzl
5-
@@ -14,7 +14,7 @@ load("//tensorflow/tools/toolchains/embedded/arm-linux:arm_linux_toolchain_confi
6-
load("//third_party:repo.bzl", "tf_http_archive", "tf_mirror_urls")
7-
load("//third_party/clang_toolchain:cc_configure_clang.bzl", "cc_download_clang_toolchain")
8-
load("//tensorflow/tools/def_file_filter:def_file_filter_configure.bzl", "def_file_filter_configure")
9-
-load("//third_party/llvm:setup.bzl", "llvm_setup")
10-
+#load("//third_party/llvm:setup.bzl", "llvm_setup")
27+
@@ -475,7 +475,7 @@ def _tf_repositories():
1128

12-
# Import third party repository rules. See go/tfbr-thirdparty.
13-
load("//third_party/FP16:workspace.bzl", FP16 = "repo")
14-
@@ -530,7 +530,7 @@ def _tf_repositories():
15-
urls = tf_mirror_urls("https://github.com/antirez/linenoise/archive/4ce393a66b10903a0ef52edf9775ed526a17395f.tar.gz"),
16-
)
29+
# Load the raw llvm-project. llvm does not have build rules set up by default,
30+
# but provides a script for setting up build rules via overlays.
31+
- llvm("llvm-raw")
32+
+ # llvm("llvm-raw")
1733

34+
# Intel openMP that is part of LLVM sources.
35+
tf_http_archive(
36+
diff --git a/third_party/xla/workspace1.bzl b/third_party/xla/workspace1.bzl
37+
index 05121708fc5..dfc5f2cedf3 100644
38+
--- a/third_party/xla/workspace1.bzl
39+
+++ b/third_party/xla/workspace1.bzl
40+
@@ -4,12 +4,12 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
41+
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
42+
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
43+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
44+
-load("//third_party/llvm:setup.bzl", "llvm_setup")
45+
+# load("//third_party/llvm:setup.bzl", "llvm_setup")
46+
47+
# buildifier: disable=unnamed-macro
48+
def workspace():
49+
"""Loads a set of TensorFlow dependencies in a WORKSPACE file."""
1850
- llvm_setup(name = "llvm-project")
1951
+ # llvm_setup(name = "llvm-project")
52+
native.register_toolchains("@local_config_python//:py_toolchain")
53+
rules_pkg_dependencies()
2054

21-
# Intel openMP that is part of LLVM sources.
22-
tf_http_archive(
23-
diff --git a/tensorflow/workspace3.bzl b/tensorflow/workspace3.bzl
24-
index a6c2c5c5835..3866493fcc9 100644
25-
--- a/tensorflow/workspace3.bzl
26-
+++ b/tensorflow/workspace3.bzl
27-
@@ -38,7 +38,7 @@ def workspace():
55+
diff --git a/third_party/xla/workspace2.bzl b/third_party/xla/workspace2.bzl
56+
index 9e4166034d0..d34f643bd3f 100644
57+
--- a/third_party/xla/workspace2.bzl
58+
+++ b/third_party/xla/workspace2.bzl
59+
@@ -376,7 +376,7 @@ def _tf_repositories():
2860

2961
# Load the raw llvm-project. llvm does not have build rules set up by default,
3062
# but provides a script for setting up build rules via overlays.
3163
- llvm("llvm-raw")
3264
+ # llvm("llvm-raw")
3365

34-
# Alias so it can be loaded without assigning to a different symbol to prevent
35-
# shadowing previous loads and trigger a buildifier warning.
66+
# Intel openMP that is part of LLVM sources.
67+
tf_http_archive(

0 commit comments

Comments
 (0)