Repository: bazelbuild/bazel
Issue: Update Protobuf to 3.6.1
Labels: P1
type: process

### Description of the problem / feature request:

Please update Bazel's Protocol Buffer version to 3.6.1

### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

This is breaking Bazel at HEAD when built with Visual C++ 2017 on Windows.

See https://github.com/bazelbuild/bazel/issues/6053#issuecomment-418031872.

### What operating system are you running Bazel on?

Windows 10

/cc @meteorcloudy @jin 

Issue comments:
Why am I assigned to this @laszlocsomor?
IIRC you updated Protobuf in the past. If so, you have domain expertise. Am I confusing it with gRPC though?
I have, so have other people. I currently have multiple P1s I am working on and don't have time to update protobuf anytime soon. There's a detailed description on how to update protobuf here: https://github.com/bazelbuild/bazel/tree/master/third_party/protobuf
Thanks for the info. Let me take a look.
If there's a cherrypick request, please add it to the release thread (https://github.com/bazelbuild/bazel/issues/5059).

Pull request review comments:
please put `load()` statements at the top of the file

Patch that resolved the issue:
diff --git a/WORKSPACE b/WORKSPACE
index 634894979f5bd7..cf6dd6c1a2bccb 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -69,20 +69,20 @@ bind(
 
 new_local_repository(
     name = "com_google_protobuf",
-    build_file = "./third_party/protobuf/3.6.0/BUILD",
-    path = "./third_party/protobuf/3.6.0/",
+    build_file = "./third_party/protobuf/3.6.1/BUILD",
+    path = "./third_party/protobuf/3.6.1/",
 )
 
 new_local_repository(
     name = "com_google_protobuf_cc",
-    build_file = "./third_party/protobuf/3.6.0/BUILD",
-    path = "./third_party/protobuf/3.6.0/",
+    build_file = "./third_party/protobuf/3.6.1/BUILD",
+    path = "./third_party/protobuf/3.6.1/",
 )
 
 new_local_repository(
     name = "com_google_protobuf_java",
-    build_file = "./third_party/protobuf/3.6.0/com_google_protobuf_java.BUILD",
-    path = "./third_party/protobuf/3.6.0/",
+    build_file = "./third_party/protobuf/3.6.1/com_google_protobuf_java.BUILD",
+    path = "./third_party/protobuf/3.6.1/",
 )
 
 new_local_repository(
diff --git a/src/main/protobuf/BUILD b/src/main/protobuf/BUILD
index f7037cea540034..e95881a31bd59e 100644
--- a/src/main/protobuf/BUILD
+++ b/src/main/protobuf/BUILD
@@ -2,7 +2,7 @@ package(default_visibility = ["//visibility:public"])
 
 load("//tools/build_rules:genproto.bzl", "cc_grpc_library")
 load("//tools/build_rules:utilities.bzl", "java_library_srcs")
-load("//third_party/protobuf/3.6.0:protobuf.bzl", "py_proto_library")
+load("//third_party/protobuf/3.6.1:protobuf.bzl", "py_proto_library")
 load("//third_party/grpc:build_defs.bzl", "java_grpc_library")
 
 exports_files(
diff --git a/third_party/protobuf/3.6.1/BUILD b/third_party/protobuf/3.6.1/BUILD
index f489d25bb18efb..740eead5e47a69 100644
--- a/third_party/protobuf/3.6.1/BUILD
+++ b/third_party/protobuf/3.6.1/BUILD
@@ -20,6 +20,7 @@ config_setting(
 ################################################################################
 
 load(":protobuf.bzl", "py_proto_library")
+load(":compiler_config_setting.bzl", "create_compiler_config_setting")
 
 filegroup(
     name = "srcs",
@@ -60,6 +61,11 @@ filegroup(
     visibility = ["//visibility:public"],
 )
 
+create_compiler_config_setting(
+    name = "msvc",
+    value = "msvc-cl",
+)
+
 ################################################################################
 # The below build rules are a copy of the upstream protobuf BUILD file without
 # the "Java support" section, as advised by Step 3 in the "Updating protobuf"
@@ -91,11 +97,6 @@ COPTS = select({
     ],
 })
 
-config_setting(
-    name = "msvc",
-    values = { "compiler": "msvc-cl" },
-)
-
 config_setting(
     name = "android",
     values = {
diff --git a/third_party/protobuf/3.6.1/compiler_config_setting.bzl b/third_party/protobuf/3.6.1/compiler_config_setting.bzl
new file mode 100644
index 00000000000000..5e52a6524ffe5f
--- /dev/null
+++ b/third_party/protobuf/3.6.1/compiler_config_setting.bzl
@@ -0,0 +1,21 @@
+"""Creates config_setting that allows selecting based on 'compiler' value."""
+
+def create_compiler_config_setting(name, value):
+    # The "do_not_use_tools_cpp_compiler_present" attribute exists to
+    # distinguish between older versions of Bazel that do not support
+    # "@bazel_tools//tools/cpp:compiler" flag_value, and newer ones that do.
+    # In the future, the only way to select on the compiler will be through
+    # flag_values{"@bazel_tools//tools/cpp:compiler"} and the else branch can
+    # be removed.
+    if hasattr(cc_common, "do_not_use_tools_cpp_compiler_present"):
+        native.config_setting(
+            name = name,
+            flag_values = {
+                "@bazel_tools//tools/cpp:compiler": value,
+            },
+        )
+    else:
+        native.config_setting(
+            name = name,
+            values = {"compiler": value},
+        )
diff --git a/third_party/protobuf/BUILD b/third_party/protobuf/BUILD
index 0e90544f85b0c0..9a67e87ffdacff 100644
--- a/third_party/protobuf/BUILD
+++ b/third_party/protobuf/BUILD
@@ -4,14 +4,14 @@ licenses(["notice"])
 
 load(":proto_alias.bzl", "proto_alias")
 
-PROTOBUF_VERSION = "3.6.0"
-_PROTOBUF_NEW_VERSION = "3.6.1"
+_OLD_PROTOBUF_VERSION = "3.6.0"
+PROTOBUF_VERSION = "3.6.1"
 
 filegroup(
     name = "srcs",
     srcs = [
+        "//third_party/protobuf/" + _OLD_PROTOBUF_VERSION + ":srcs",
         "//third_party/protobuf/" + PROTOBUF_VERSION + ":srcs",
-        "//third_party/protobuf/" + _PROTOBUF_NEW_VERSION + ":srcs",
     ] + glob(["**"]),  # glob everything to satisfy the compile.sh srcs test
     visibility = ["//third_party:__pkg__"],
 )
diff --git a/third_party/protobuf/README.md b/third_party/protobuf/README.md
index 10837db9db2cc7..e2a428a2afa9dd 100644
--- a/third_party/protobuf/README.md
+++ b/third_party/protobuf/README.md
@@ -38,4 +38,4 @@ the new version.
 
 # Current protobuf version
 
-The current version of protobuf is [3.6.0](https://github.com/google/protobuf/releases/tag/v3.6.0).
+The current version of protobuf is [3.6.1](https://github.com/google/protobuf/releases/tag/v3.6.1).


Test patch:
diff --git a/src/test/shell/bazel/testdata/embedded_tools_srcs_deps b/src/test/shell/bazel/testdata/embedded_tools_srcs_deps
index 5f373788af0ba7..07704af47d52ed 100644
--- a/src/test/shell/bazel/testdata/embedded_tools_srcs_deps
+++ b/src/test/shell/bazel/testdata/embedded_tools_srcs_deps
@@ -2,7 +2,6 @@
 @com_google_protobuf//:protoc_lib
 @com_google_protobuf//:protobuf
 @com_google_protobuf//:protobuf_lite
-@com_google_protobuf//:js_embed
 //tools/test:test_wrapper_bin
 //third_party/ijar:zipper
 //third_party/ijar:ijar
diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh
index d5b7afc82d8c0e..b9f1b9dcbb65f0 100755
--- a/src/test/shell/testenv.sh
+++ b/src/test/shell/testenv.sh
@@ -115,7 +115,7 @@ if [ "${MACHINE_TYPE}" = 's390x' ]; then
 fi
 
 # Requires //third_party/protobuf:protoc
-protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/3.6.0/protoc"
+protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/3.6.1/protoc"
 
 if [ -z ${RUNFILES_MANIFEST_ONLY+x} ]; then
   junit_jar="${BAZEL_RUNFILES}/third_party/junit/junit-*.jar"