Merge branch 'master' into karthik/cerealrm
diff --git a/WORKSPACE b/WORKSPACE
index 857e3ec..46c7183 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -790,6 +790,12 @@
     strip_prefix = "gflags-2.2.1",
 )
 
+http_archive(
+    name = "com_google_protobuf",
+    urls = ["https://github.com/google/protobuf/archive/v3.4.1.tar.gz"],
+    strip_prefix = "protobuf-3.4.1",
+)
+
 new_http_archive(
     name = "com_github_cereal",
     urls = ["https://github.com/USCiLab/cereal/archive/v1.2.2.tar.gz"],
diff --git a/heron/common/src/cpp/basics/BUILD b/heron/common/src/cpp/basics/BUILD
index dffb8ee..0c3c682 100644
--- a/heron/common/src/cpp/basics/BUILD
+++ b/heron/common/src/cpp/basics/BUILD
@@ -50,7 +50,7 @@
         "@com_github_gflags_gflags//:gflags",
         "//third_party/gperftools:tcmalloc-cxx",
         "//third_party/kashmir:kashmir-cxx",
-        "//third_party/protobuf:protobuf-cxx",
+        "@com_google_protobuf//:protobuf",
     ] + select({
         "//tools/platform:darwin": [], 
         "//conditions:default": ["//third_party/libunwind:libunwind-cxx"],
diff --git a/heron/common/src/cpp/metrics/BUILD b/heron/common/src/cpp/metrics/BUILD
index f3eefeb..e7663a1 100644
--- a/heron/common/src/cpp/metrics/BUILD
+++ b/heron/common/src/cpp/metrics/BUILD
@@ -39,7 +39,7 @@
         "//heron/common/src/cpp/network:network-cxx",
         "//heron/common/src/cpp/config:config-cxx",
         "//third_party/glog:glog-cxx",
-        "//third_party/protobuf:protobuf-cxx",
+        "@com_google_protobuf//:protobuf",
     ],
     linkstatic = 1,
 )
diff --git a/heron/proto/BUILD b/heron/proto/BUILD
index b4ce271..67deeff 100644
--- a/heron/proto/BUILD
+++ b/heron/proto/BUILD
@@ -232,7 +232,7 @@
         ":proto_topology_cc",
         ":proto_stats_cc",
         ":proto_common_cc",
-        "//third_party/protobuf:protobuf-cxx",
+        "@com_google_protobuf//:protobuf",
     ],
     linkstatic = 1,
 )
diff --git a/third_party/protobuf/BUILD b/third_party/protobuf/BUILD
deleted file mode 100644
index 788c51c..0000000
--- a/third_party/protobuf/BUILD
+++ /dev/null
@@ -1,209 +0,0 @@
-licenses(["notice"])
-
-package(default_visibility = ["//visibility:public"])
-
-pkg_name = "protobuf"
-pkg_version = "3.4.0"
-
-pkg_file = pkg_name + "-" + pkg_version + ".tar.gz"
-pkg_dir = pkg_name + "-" + pkg_version
-pkg_patch = pkg_name + "-" + pkg_version + ".patch"
-
-gmock_name = "gmock"
-gmock_version = "1.7.0"
-gmock_file = gmock_name + "-" + gmock_version + ".zip"
-gmock_dir = gmock_name + "-" + gmock_version
-
-genrule(
-    name = "protobuf-srcs",
-    srcs = [pkg_file, pkg_patch, gmock_file],
-    outs = [
-        "bin/protoc",
-
-        "include/google/protobuf/arena.h",
-        "include/google/protobuf/arenastring.h",
-        "include/google/protobuf/arena_impl.h",
-        "include/google/protobuf/has_bits.h",
-        "include/google/protobuf/stubs/atomic_sequence_num.h",
-        "include/google/protobuf/stubs/fastmem.h",
-        "include/google/protobuf/stubs/port.h",
-        "include/google/protobuf/stubs/macros.h",
-        "include/google/protobuf/stubs/logging.h",
-        "include/google/protobuf/stubs/scoped_ptr.h",
-        "include/google/protobuf/stubs/mutex.h",
-        "include/google/protobuf/stubs/callback.h",
-        "include/google/protobuf/stubs/shared_ptr.h",
-        "include/google/protobuf/stubs/hash.h",
-        "include/google/protobuf/stubs/casts.h",
-
-        "include/google/protobuf/extension_set.h",
-        "include/google/protobuf/map.h",
-        "include/google/protobuf/map_type_handler.h",
-        "include/google/protobuf/map_entry_lite.h",
-        "include/google/protobuf/metadata_lite.h",
-        "include/google/protobuf/message_lite.h",
-        "include/google/protobuf/unknown_field_set.h",
-        "include/google/protobuf/descriptor.h",
-        "include/google/protobuf/generated_enum_reflection.h",
-        "include/google/protobuf/reflection_ops.h",
-        "include/google/protobuf/wire_format.h",
-        "include/google/protobuf/descriptor.pb.h",
-        "include/google/protobuf/generated_message_reflection.h",
-        "include/google/protobuf/repeated_field.h",
-        "include/google/protobuf/wire_format_lite.h",
-        "include/google/protobuf/descriptor.proto",
-        "include/google/protobuf/generated_message_util.h",
-        "include/google/protobuf/generated_enum_util.h",
-        "include/google/protobuf/service.h",
-        "include/google/protobuf/wire_format_lite_inl.h",
-        "include/google/protobuf/descriptor_database.h",
-        "include/google/protobuf/dynamic_message.h",
-        "include/google/protobuf/message.h",
-        "include/google/protobuf/text_format.h",
-        "include/google/protobuf/metadata.h",
-        "include/google/protobuf/generated_message_table_driven.h",
-
-        "include/google/protobuf/compiler/code_generator.h",
-        "include/google/protobuf/compiler/command_line_interface.h",
-        "include/google/protobuf/compiler/importer.h",
-        "include/google/protobuf/compiler/parser.h",
-        "include/google/protobuf/compiler/plugin.h",
-        "include/google/protobuf/compiler/plugin.pb.h",
-        "include/google/protobuf/compiler/plugin.proto",
-
-        "include/google/protobuf/compiler/cpp/cpp_generator.h",
-        "include/google/protobuf/compiler/java/java_generator.h",
-        "include/google/protobuf/compiler/python/python_generator.h",
-
-        "include/google/protobuf/io/coded_stream.h",
-        "include/google/protobuf/io/printer.h",
-        "include/google/protobuf/io/tokenizer.h",
-        "include/google/protobuf/io/zero_copy_stream.h",
-        "include/google/protobuf/io/zero_copy_stream_impl.h",
-        "include/google/protobuf/io/zero_copy_stream_impl_lite.h",
-
-        "include/google/protobuf/stubs/atomicops.h",
-        "include/google/protobuf/stubs/atomicops_internals_mips_gcc.h",
-        "include/google/protobuf/stubs/once.h",
-        "include/google/protobuf/stubs/atomicops_internals_arm_gcc.h",
-        "include/google/protobuf/stubs/platform_macros.h",
-        "include/google/protobuf/stubs/atomicops_internals_arm_qnx.h",
-        "include/google/protobuf/stubs/atomicops_internals_x86_gcc.h",
-        "include/google/protobuf/stubs/template_util.h",
-        "include/google/protobuf/stubs/atomicops_internals_atomicword_compat.h",
-        "include/google/protobuf/stubs/atomicops_internals_x86_msvc.h",
-        "include/google/protobuf/stubs/type_traits.h",
-        "include/google/protobuf/stubs/common.h",
-
-        "lib/libprotobuf-lite.a",
-        "lib/libprotobuf.a",
-        "lib/libprotoc.a",
-    ],
-    cmd = "\n".join([
-        "export INSTALL_DIR=$$(pwd)/$(@D)",
-        "export TMP_DIR=$$(mktemp -d -t protobuf.XXXXX)",
-        "mkdir -p $$TMP_DIR",
-        "cp -R $(SRCS) $$TMP_DIR",
-        "cd $$TMP_DIR",
-        "tar xfz " + pkg_file,
-        "patch -d " + pkg_dir + " -p1 < " + pkg_patch,
-        "cd " + pkg_dir,
-        "unzip -q -o " + "../" + gmock_file,
-        "mv " + gmock_dir + " gmock",
-        "./autogen.sh",
-        "./configure --prefix=$$INSTALL_DIR --enable-shared=no",
-        "make install",
-        "rm -rf $$TMP_DIR",
-    ]),
-)
-
-cc_library(
-    name = "protobuf-cxx-lite",
-    srcs = [
-        "empty.cc",
-        "lib/libprotobuf-lite.a",
-    ],
-    hdrs = [
-        "include/google/protobuf/message_lite.h",
-    ],
-    includes = ["include"],
-    linkstatic = 1,
-)
-
-cc_library(
-    name = "protobuf-cxx",
-    srcs = [
-        "include/google/protobuf/descriptor.pb.h",
-        "include/google/protobuf/generated_enum_reflection.h",
-
-        "include/google/protobuf/stubs/atomicops.h",
-        "include/google/protobuf/stubs/atomicops_internals_x86_gcc.h",
-        "include/google/protobuf/stubs/atomicops_internals_atomicword_compat.h",
-        "include/google/protobuf/stubs/platform_macros.h",
-        "include/google/protobuf/stubs/type_traits.h",
-        "include/google/protobuf/stubs/template_util.h",
-
-        "empty.cc",
-        "lib/libprotobuf.a",
-    ],
-    hdrs = [
-        "include/google/protobuf/arena.h",
-        "include/google/protobuf/arenastring.h",
-        "include/google/protobuf/arena_impl.h",
-        "include/google/protobuf/has_bits.h",
-        "include/google/protobuf/stubs/atomic_sequence_num.h",
-        "include/google/protobuf/stubs/common.h",
-        "include/google/protobuf/stubs/fastmem.h",
-        "include/google/protobuf/stubs/hash.h",
-        "include/google/protobuf/stubs/once.h",
-        "include/google/protobuf/stubs/port.h",
-        "include/google/protobuf/stubs/macros.h",
-        "include/google/protobuf/stubs/logging.h",
-        "include/google/protobuf/stubs/scoped_ptr.h",
-        "include/google/protobuf/stubs/mutex.h",
-        "include/google/protobuf/stubs/callback.h",
-        "include/google/protobuf/stubs/shared_ptr.h",
-        "include/google/protobuf/stubs/casts.h",
-
-        "include/google/protobuf/descriptor.h",
-        "include/google/protobuf/extension_set.h",
-        "include/google/protobuf/generated_enum_util.h",
-        "include/google/protobuf/generated_message_util.h",
-        "include/google/protobuf/generated_message_reflection.h",
-        "include/google/protobuf/generated_message_table_driven.h",
-        "include/google/protobuf/map.h",
-        "include/google/protobuf/map_entry_lite.h",
-        "include/google/protobuf/map_type_handler.h",
-        "include/google/protobuf/message.h",
-        "include/google/protobuf/message_lite.h",
-        "include/google/protobuf/metadata.h",
-        "include/google/protobuf/metadata_lite.h",
-        "include/google/protobuf/reflection_ops.h",
-        "include/google/protobuf/repeated_field.h",
-        "include/google/protobuf/unknown_field_set.h",
-        "include/google/protobuf/wire_format.h",
-        "include/google/protobuf/wire_format_lite.h",
-        "include/google/protobuf/wire_format_lite_inl.h",
-
-        "include/google/protobuf/io/coded_stream.h",
-    ],
-    includes = [
-        "include",
-    ],
-    linkstatic = 1,
-)
-
-cc_library(
-    name = "protoc-cxx",
-    srcs = [
-        "empty.cc",
-        "lib/libprotoc.a",
-    ],
-    deps = [":protobuf-cxx", ":gtest-cxx"],
-    linkstatic = 1,
-)
-
-filegroup(
-    name = "protoc",
-    srcs = ["bin/protoc"]
-)
diff --git a/third_party/protobuf/empty.cc b/third_party/protobuf/empty.cc
deleted file mode 100644
index e2b1d40..0000000
--- a/third_party/protobuf/empty.cc
+++ /dev/null
@@ -1,2 +0,0 @@
-void _empty_protobuf_xyz() {
-}
diff --git a/third_party/protobuf/gmock-1.7.0.zip b/third_party/protobuf/gmock-1.7.0.zip
deleted file mode 100644
index 2f0edb9..0000000
--- a/third_party/protobuf/gmock-1.7.0.zip
+++ /dev/null
Binary files differ
diff --git a/third_party/protobuf/protobuf-3.4.0.patch b/third_party/protobuf/protobuf-3.4.0.patch
deleted file mode 100644
index 6be277d..0000000
--- a/third_party/protobuf/protobuf-3.4.0.patch
+++ /dev/null
@@ -1,295 +0,0 @@
-diff -rup protobuf-3.4.0.orig/configure.ac protobuf-3.4.0/configure.ac
---- protobuf-3.4.0.orig/configure.ac	2017-09-17 16:34:26.000000000 -0700
-+++ protobuf-3.4.0/configure.ac	2017-09-17 16:46:57.000000000 -0700
-@@ -65,7 +65,6 @@ AC_LANG([C++])
- ACX_USE_SYSTEM_EXTENSIONS
- m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
- AM_CONDITIONAL(GCC, test "$GCC" = yes)   # let the Makefile know if we're gcc
--AC_PROG_OBJC
- 
- # test_util.cc takes forever to compile with GCC and optimization turned on.
- AC_MSG_CHECKING([C++ compiler flags...])
-@@ -189,15 +188,6 @@ case "$target_os" in
-     ;;
- esac
- 
--# Enable ObjC support for conformance directory on OS X.
--OBJC_CONFORMANCE_TEST=0
--case "$target_os" in
--  darwin*)
--    OBJC_CONFORMANCE_TEST=1
--    ;;
--esac
--AM_CONDITIONAL([OBJC_CONFORMANCE_TEST], [test $OBJC_CONFORMANCE_TEST = 1])
--
- AX_CXX_COMPILE_STDCXX([11], [noext], [optional])
- 
- # HACK:  Make gmock's configure script pick up our copy of CFLAGS and CXXFLAGS,
-diff -rup protobuf-3.4.0.orig/conformance/Makefile.am protobuf-3.4.0/conformance/Makefile.am
---- protobuf-3.4.0.orig/conformance/Makefile.am	2017-09-17 16:34:26.000000000 -0700
-+++ protobuf-3.4.0/conformance/Makefile.am	2017-09-17 16:48:31.000000000 -0700
-@@ -24,8 +24,6 @@ protoc_outputs =                        
- 
- other_language_protoc_outputs =                                \
-   conformance_pb2.py                                           \
--  Conformance.pbobjc.h                                         \
--  Conformance.pbobjc.m                                         \
-   conformance_pb.js                                            \
-   conformance_pb.rb                                            \
-   com/google/protobuf/Any.java                                 \
-@@ -225,24 +223,6 @@ conformance_cpp_CPPFLAGS = -I$(top_srcdi
- # so a direct "make test_cpp" could fail if parallel enough.
- conformance_cpp-conformance_cpp.$(OBJEXT): conformance.pb.h
- 
--if OBJC_CONFORMANCE_TEST
--
--bin_PROGRAMS += conformance-objc
--
--conformance_objc_SOURCES = conformance_objc.m ../objectivec/GPBProtocolBuffers.m
--nodist_conformance_objc_SOURCES = Conformance.pbobjc.m google/protobuf/TestMessagesProto2.pbobjc.m google/protobuf/TestMessagesProto3.pbobjc.m
--# On travis, the build fails without the isysroot because whatever system
--# headers are being found don't include generics support for
--# NSArray/NSDictionary, the only guess is their image at one time had an odd
--# setup for Xcode and old frameworks are being found.
--conformance_objc_CPPFLAGS = -I$(top_srcdir)/objectivec -isysroot `xcrun --sdk macosx --show-sdk-path`
--conformance_objc_LDFLAGS = -framework Foundation
--# Explicit dep beacuse BUILT_SOURCES are only done before a "make all/check"
--# so a direct "make test_objc" could fail if parallel enough.
--conformance_objc-conformance_objc.$(OBJEXT): Conformance.pbobjc.h google/protobuf/TestMessagesProto2.pbobjc.h google/protobuf/TestMessagesProto3.pbobjc.h
--
--endif
--
- # JavaScript well-known types are expected to be in a directory called
- # google-protobuf, because they are usually in the google-protobuf npm
- # package.  But we want to use the sources from our tree, so we recreate
-@@ -363,9 +343,3 @@ test_python_cpp: protoc_middleman confor
- test_nodejs: protoc_middleman conformance-test-runner $(other_language_protoc_outputs)
- 	NODE_PATH=../js:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_js.txt ./conformance_nodejs.js
- 
--if OBJC_CONFORMANCE_TEST
--
--test_objc: protoc_middleman conformance-test-runner conformance-objc
--	./conformance-test-runner --enforce_recommended --failure_list failure_list_objc.txt ./conformance-objc
--
--endif
-diff -rup protobuf-3.4.0.orig/conformance/conformance_objc.m protobuf-3.4.0/conformance/conformance_objc.m
---- protobuf-3.4.0.orig/conformance/conformance_objc.m	2017-09-17 16:34:26.000000000 -0700
-+++ protobuf-3.4.0/conformance/conformance_objc.m	2017-09-17 16:49:29.000000000 -0700
-@@ -1,188 +0,0 @@
--// Protocol Buffers - Google's data interchange format
--// Copyright 2015 Google Inc.  All rights reserved.
--// https://developers.google.com/protocol-buffers/
--//
--// Redistribution and use in source and binary forms, with or without
--// modification, are permitted provided that the following conditions are
--// met:
--//
--//     * Redistributions of source code must retain the above copyright
--// notice, this list of conditions and the following disclaimer.
--//     * Redistributions in binary form must reproduce the above
--// copyright notice, this list of conditions and the following disclaimer
--// in the documentation and/or other materials provided with the
--// distribution.
--//     * Neither the name of Google Inc. nor the names of its
--// contributors may be used to endorse or promote products derived from
--// this software without specific prior written permission.
--//
--// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
--// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
--// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
--// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
--// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
--// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
--// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
--// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
--// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
--// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
--// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--
--#import <Foundation/Foundation.h>
--
--#import "Conformance.pbobjc.h"
--#import "google/protobuf/TestMessagesProto2.pbobjc.h"
--#import "google/protobuf/TestMessagesProto3.pbobjc.h"
--
--static void Die(NSString *format, ...) __dead2;
--
--static BOOL verbose = NO;
--static int32_t testCount = 0;
--
--static void Die(NSString *format, ...) {
--  va_list args;
--  va_start(args, format);
--  NSString *msg = [[NSString alloc] initWithFormat:format arguments:args];
--  NSLog(@"%@", msg);
--  va_end(args);
--  [msg release];
--  exit(66);
--}
--
--static NSData *CheckedReadDataOfLength(NSFileHandle *handle, NSUInteger numBytes) {
--  NSData *data = [handle readDataOfLength:numBytes];
--  NSUInteger dataLen = data.length;
--  if (dataLen == 0) {
--    return nil;  // EOF.
--  }
--  if (dataLen != numBytes) {
--    Die(@"Failed to read the request length (%d), only got: %@",
--        numBytes, data);
--  }
--  return data;
--}
--
--static ConformanceResponse *DoTest(ConformanceRequest *request) {
--  ConformanceResponse *response = [ConformanceResponse message];
--  GPBMessage *testMessage = nil;
--
--  switch (request.payloadOneOfCase) {
--    case ConformanceRequest_Payload_OneOfCase_GPBUnsetOneOfCase:
--      Die(@"Request didn't have a payload: %@", request);
--      break;
--
--    case ConformanceRequest_Payload_OneOfCase_ProtobufPayload: {
--      Class msgClass = nil;
--      if ([request.messageType isEqual:@"protobuf_test_messages.proto3.TestAllTypesProto3"]) {
--        msgClass = [Proto3TestAllTypesProto3 class];
--      } else if ([request.messageType isEqual:@"protobuf_test_messages.proto2.TestAllTypesProto2"]) {
--        msgClass = [TestAllTypesProto2 class];
--      } else {
--        Die(@"Protobuf request had an unknown message_type: %@", request.messageType);
--      }
--      NSError *error = nil;
--      testMessage = [msgClass parseFromData:request.protobufPayload error:&error];
--      if (!testMessage) {
--        response.parseError =
--            [NSString stringWithFormat:@"Parse error: %@", error];
--      }
--      break;
--    }
--
--    case ConformanceRequest_Payload_OneOfCase_JsonPayload:
--      response.skipped = @"ObjC doesn't support parsing JSON";
--      break;
--  }
--
--  if (testMessage) {
--    switch (request.requestedOutputFormat) {
--      case WireFormat_GPBUnrecognizedEnumeratorValue:
--      case WireFormat_Unspecified:
--        Die(@"Unrecognized/unspecified output format: %@", request);
--        break;
--
--      case WireFormat_Protobuf:
--        response.protobufPayload = testMessage.data;
--        if (!response.protobufPayload) {
--          response.serializeError =
--            [NSString stringWithFormat:@"Failed to make data from: %@", testMessage];
--        }
--        break;
--
--      case WireFormat_Json:
--        response.skipped = @"ObjC doesn't support generating JSON";
--        break;
--    }
--  }
--
--  return response;
--}
--
--static uint32_t UInt32FromLittleEndianData(NSData *data) {
--  if (data.length != sizeof(uint32_t)) {
--    Die(@"Data not the right size for uint32_t: %@", data);
--  }
--  uint32_t value;
--  memcpy(&value, data.bytes, sizeof(uint32_t));
--  return CFSwapInt32LittleToHost(value);
--}
--
--static NSData *UInt32ToLittleEndianData(uint32_t num) {
--  uint32_t value = CFSwapInt32HostToLittle(num);
--  return [NSData dataWithBytes:&value length:sizeof(uint32_t)];
--}
--
--static BOOL DoTestIo(NSFileHandle *input, NSFileHandle *output) {
--  // See conformance_test_runner.cc for the wire format.
--  NSData *data = CheckedReadDataOfLength(input, sizeof(uint32_t));
--  if (!data) {
--    // EOF.
--    return NO;
--  }
--  uint32_t numBytes = UInt32FromLittleEndianData(data);
--  data = CheckedReadDataOfLength(input, numBytes);
--  if (!data) {
--    Die(@"Failed to read request");
--  }
--
--  NSError *error = nil;
--  ConformanceRequest *request = [ConformanceRequest parseFromData:data
--                                                            error:&error];
--  if (!request) {
--    Die(@"Failed to parse the message data: %@", error);
--  }
--
--  ConformanceResponse *response = DoTest(request);
--  if (!response) {
--    Die(@"Failed to make a reply from %@", request);
--  }
--
--  data = response.data;
--  [output writeData:UInt32ToLittleEndianData((int32_t)data.length)];
--  [output writeData:data];
--
--  if (verbose) {
--    NSLog(@"Request: %@", request);
--    NSLog(@"Response: %@", response);
--  }
--
--  ++testCount;
--  return YES;
--}
--
--int main(int argc, const char *argv[]) {
--  @autoreleasepool {
--    NSFileHandle *input = [[NSFileHandle fileHandleWithStandardInput] retain];
--    NSFileHandle *output = [[NSFileHandle fileHandleWithStandardOutput] retain];
--
--    BOOL notDone = YES;
--    while (notDone) {
--      @autoreleasepool {
--        notDone = DoTestIo(input, output);
--      }
--    }
--
--    NSLog(@"Received EOF from test runner after %d tests, exiting.", testCount);
--  }
--  return 0;
--}
-diff -rup protobuf-3.4.0.orig/src/google/protobuf/io/zero_copy_stream_impl_lite.h protobuf-3.4.0/src/google/protobuf/io/zero_copy_stream_impl_lite.h
---- protobuf-3.4.0.orig/src/google/protobuf/io/zero_copy_stream_impl_lite.h	2017-09-17 16:34:27.000000000 -0700
-+++ protobuf-3.4.0/src/google/protobuf/io/zero_copy_stream_impl_lite.h	2017-09-17 16:45:58.000000000 -0700
-@@ -377,13 +377,9 @@ class LIBPROTOBUF_EXPORT CopyingOutputSt
- // return value is valid until the next time the string is resized.  We
- // trust the caller to treat the return value as an array of length s->size().
- inline char* mutable_string_data(string* s) {
--#ifdef LANG_CXX11
-   // This should be simpler & faster than string_as_array() because the latter
-   // is guaranteed to return NULL when *s is empty, so it has to check for that.
-   return &(*s)[0];
--#else
--  return string_as_array(s);
--#endif
- }
- 
- // as_string_data(s) is equivalent to
-@@ -392,11 +388,7 @@ inline char* mutable_string_data(string*
- // code can avoid that check.
- inline std::pair<char*, bool> as_string_data(string* s) {
-   char *p = mutable_string_data(s);
--#ifdef LANG_CXX11
-   return std::make_pair(p, true);
--#else
--  return std::make_pair(p, p != NULL);
--#endif
- }
- 
- }  // namespace io
diff --git a/third_party/protobuf/protobuf-3.4.0.tar.gz b/third_party/protobuf/protobuf-3.4.0.tar.gz
deleted file mode 100644
index 5431b5b..0000000
--- a/third_party/protobuf/protobuf-3.4.0.tar.gz
+++ /dev/null
Binary files differ
diff --git a/tools/rules/genproto.bzl b/tools/rules/genproto.bzl
index 3b9a9cf..32438f3 100644
--- a/tools/rules/genproto.bzl
+++ b/tools/rules/genproto.bzl
@@ -48,7 +48,7 @@
     genproto_java_impl,
     attrs = genproto_base_attrs + {
         "_protoc": attr.label(
-            default = Label("//third_party/protobuf:protoc"),
+            default = Label("@com_google_protobuf//:protoc"),
             allow_files = True,
             single_file = True,
         ),
@@ -97,13 +97,13 @@
     proto_src = src[:-6] + ".pb.cc"
     proto_srcgen_rule = name + "_cc_src"
     proto_lib = name + "_cc"
-    protoc = "//third_party/protobuf:protoc"
+    protoc = "@com_google_protobuf//:protoc"
     if not includes:
       proto_cmd = "$(location %s) --cpp_out=$(@D) %s" % (protoc, proto_path)
     else:
       proto_cmd = "$(location %s) %s --cpp_out=$(@D) %s" % (protoc, proto_include_paths, proto_path)
 
-    cc_deps = ["//third_party/protobuf:protobuf-cxx"]
+    cc_deps = ["@com_google_protobuf//:protobuf"]
     proto_deps = [src, protoc]
     for dep in deps:
       cc_deps += [dep + "_cc"]
@@ -133,7 +133,7 @@
     proto_src = src[:-6] + "_pb2.py"
     proto_srcgen_rule = name + "_py_src"
     proto_lib = name + "_py"
-    protoc = "//third_party/protobuf:protoc"
+    protoc = "@com_google_protobuf//:protoc"
     if not includes:
       proto_cmd = "$(location %s) --python_out=$(@D) %s" % (protoc, proto_path)
     else: