Make protobuf build

This includes the following:
  - Setting up dependencies protobuf needs
  - A few hacks to make protobuf work with our version of Bazel (going
    to upgrade soon...)
  - A few tweaks to make protobuf be happy in third_party
  - Commenting out a few things we don't care about that didn't want to
    work

Tested with -c fastbuild for all 3 toolchains.

Change-Id: I02c50cd7e82e509bd7973f2e7cecf9b7d183783e
diff --git a/third_party/protobuf/BUILD b/third_party/protobuf/BUILD
index 3cac4a8..bb5d889 100644
--- a/third_party/protobuf/BUILD
+++ b/third_party/protobuf/BUILD
@@ -2,18 +2,34 @@
 
 licenses(["notice"])
 
+load("/tools/build_rules/select", "compiler_select")
+
 ################################################################################
 # Protobuf Runtime Library
 ################################################################################
 
 COPTS = [
     "-DHAVE_PTHREAD",
+    "-DGOOGLE_THIRD_PARTY_PROTOBUF",
     "-Wall",
     "-Wwrite-strings",
     "-Woverloaded-virtual",
     "-Wno-sign-compare",
-    "-Wno-error=unused-function",
-]
+    "-Wno-unused-function",
+    "-Wno-unused-parameter",
+    "-Wno-format-nonliteral",
+    "-Wno-switch-enum",
+    "-Wno-missing-field-initializers",
+    "-Wno-ignored-qualifiers",
+] + compiler_select({
+    "gcc": [
+        "-Wno-error=cast-align",
+    ],
+    "clang": [
+        "-Wno-unused-const-variable",
+        "-Wno-unused-private-field",
+    ],
+})
 
 # Bazel should provide portable link_opts for pthread.
 LINK_OPTS = ["-lpthread"]
@@ -127,6 +143,7 @@
     deps = [":protobuf_lite"],
 )
 
+'''
 objc_library(
     name = "protobuf_objc",
     hdrs = ["objectivec/GPBProtocolBuffers.h"],
@@ -134,6 +151,7 @@
     non_arc_srcs = ["objectivec/GPBProtocolBuffers.m"],
     visibility = ["//visibility:public"],
 )
+'''
 
 RELATIVE_WELL_KNOWN_PROTOS = [
     # AUTOGEN(well_known_protos)
@@ -342,6 +360,7 @@
     default_runtime = ":protobuf",
     protoc = ":protoc",
     deps = [":cc_wkt_protos"],
+    copts = COPTS,
 )
 
 COMMON_TEST_SRCS = [
@@ -366,6 +385,7 @@
         ":protoc_lib",
         "//external:gtest",
     ],
+    copts = COPTS,
 )
 
 cc_test(
@@ -465,7 +485,7 @@
         "wellknown.srcjar"
     ],
     cmd = "$(location :protoc) --java_out=$(@D)/wellknown.jar" +
-        " -Isrc $(SRCS) " +
+        " -Ithird_party/protobuf/src $(SRCS) " +
         " && mv $(@D)/wellknown.jar $(@D)/wellknown.srcjar",
     tools = [":protoc"],
 )
@@ -517,6 +537,7 @@
     include = "python",
 )
 
+'''
 cc_binary(
     name = "internal/_api_implementation.so",
     srcs = ["python/google/protobuf/internal/api_implementation.cc"],
@@ -527,7 +548,7 @@
     linkstatic = 1,
     deps = select({
         "//conditions:default": [],
-        ":use_fast_cpp_protos": ["//util/python:python_headers"],
+        ":use_fast_cpp_protos": ["//third_party/protobuf/util/python:python_headers"],
     }),
 )
 
@@ -550,9 +571,10 @@
         ":protobuf",
     ] + select({
         "//conditions:default": [],
-        ":use_fast_cpp_protos": ["//util/python:python_headers"],
+        ":use_fast_cpp_protos": ["//third_party/protobuf/util/python:python_headers"],
     }),
 )
+'''
 
 config_setting(
     name = "use_fast_cpp_protos",