Adding deps to protobuf rules.

Change-Id: Ib1f4f1e061a55885389a7b51c98317ee241a1bba
diff --git a/build_tests/BUILD b/build_tests/BUILD
index be6a201..72dc6da 100644
--- a/build_tests/BUILD
+++ b/build_tests/BUILD
@@ -74,6 +74,14 @@
 proto_cc_library(
   name = 'proto_build_test_library',
   src = 'proto.proto',
+  deps = [
+    ':proto_build_test_library_base',
+  ],
+)
+
+proto_cc_library(
+  name = 'proto_build_test_library_base',
+  src = 'proto_base.proto',
 )
 
 cc_test(
diff --git a/build_tests/proto.cc b/build_tests/proto.cc
index 23ff879..bb09003 100644
--- a/build_tests/proto.cc
+++ b/build_tests/proto.cc
@@ -6,6 +6,7 @@
   ::frc971::TestProto test_proto1, test_proto2;
   test_proto1.set_s("Hi!");
   test_proto1.set_i(971);
+  test_proto1.mutable_base_proto()->set_a("silly");
 
   ::std::string serialized;
   ASSERT_TRUE(test_proto1.SerializeToString(&serialized));
diff --git a/build_tests/proto.proto b/build_tests/proto.proto
index 367a650..d0e6fe2 100644
--- a/build_tests/proto.proto
+++ b/build_tests/proto.proto
@@ -4,9 +4,13 @@
 
 import "google/protobuf/empty.proto";
 
+import "build_tests/proto_base.proto";
+
 message TestProto {
   string s = 1;
   int32 i = 2;
   // Making sure that well-known protos work.
   .google.protobuf.Empty empty = 3;
+  // Making sure we can depend on other protos.
+  BaseProto base_proto = 4;
 }
diff --git a/build_tests/proto_base.proto b/build_tests/proto_base.proto
new file mode 100644
index 0000000..8fc2143
--- /dev/null
+++ b/build_tests/proto_base.proto
@@ -0,0 +1,8 @@
+syntax = "proto2";
+
+package frc971;
+
+message BaseProto {
+  optional string a = 1;
+  optional string b = 2;
+}
diff --git a/tools/build_rules/protobuf.bzl b/tools/build_rules/protobuf.bzl
index d5f4284..c9bb9ef 100644
--- a/tools/build_rules/protobuf.bzl
+++ b/tools/build_rules/protobuf.bzl
@@ -1,16 +1,22 @@
 def _do_proto_cc_library_impl(ctx):
+  srcs = ctx.files.srcs
+  deps = []
+  deps += ctx.files.srcs
+
+  for dep in ctx.attr.deps:
+    deps += dep.proto.deps
+
   message = 'Building %s and %s from %s' % (ctx.outputs.pb_h.short_path,
                                             ctx.outputs.pb_cc.short_path,
-                                            ctx.file.src.short_path)
+                                            ctx.files.srcs[0].short_path)
   ctx.action(
-    inputs = ctx.files.src + ctx.files._well_known_protos,
+    inputs = deps + ctx.files._well_known_protos,
     executable = ctx.executable._protoc,
     arguments = [
       '--cpp_out=%s' % ctx.configuration.genfiles_dir.path,
       '-I.',
       '-Ithird_party/protobuf/src',
-      ctx.file.src.path,
-    ],
+    ] + [s.path for s in srcs],
     mnemonic = 'ProtocCc',
     progress_message = message,
     outputs = [
@@ -19,8 +25,15 @@
     ],
   )
 
-def _do_proto_cc_library_outputs(src):
-  basename = src.name[:-len('.proto')]
+  return struct(
+    proto = struct(
+      srcs = srcs,
+      deps = deps,
+    )
+  )
+
+def _do_proto_cc_library_outputs(srcs):
+  basename = srcs[0].name[:-len('.proto')]
   return {
     'pb_h': '%s.pb.h' % basename,
     'pb_cc': '%s.pb.cc' % basename,
@@ -29,11 +42,10 @@
 _do_proto_cc_library = rule(
   implementation = _do_proto_cc_library_impl,
   attrs = {
-    'src': attr.label(
+    'srcs': attr.label_list(
       allow_files = FileType(['.proto']),
-      mandatory = True,
-      single_file = True,
     ),
+    'deps': attr.label_list(providers = ["proto"]),
     '_protoc': attr.label(
       default = Label('//third_party/protobuf:protoc'),
       executable = True,
@@ -47,7 +59,7 @@
   output_to_genfiles = True,
 )
 
-def proto_cc_library(name, src, visibility = None):
+def proto_cc_library(name, src, deps = [], visibility = None):
   '''Generates a cc_library from a single .proto file. Does not support
   dependencies on any .proto files except the well-known ones protobuf comes
   with (which are unconditionally depended on).
@@ -58,7 +70,8 @@
 
   _do_proto_cc_library(
     name = '%s__proto_srcs' % name,
-    src = src,
+    srcs = [src],
+    deps = [('%s__proto_srcs' % o_name) for o_name in deps],
     visibility = ['//visibility:private'],
   )
   basename = src[:-len('.proto')]
@@ -66,6 +79,6 @@
     name = name,
     srcs = [ '%s.pb.cc' % basename ],
     hdrs = [ '%s.pb.h' % basename ],
-    deps = [ '//third_party/protobuf' ],
+    deps = [ '//third_party/protobuf' ] + deps,
     visibility = visibility,
   )