BUILD 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # This BUILD file shows how to use protobuf with bazel. Before you can use
  2. # proto_library/<lang>_proto_library rules in a BUILD file, you need to
  3. # include protobuf repo as remote repositories in your WORKSPACE file. See
  4. # the WORKSPACE file in the same directory with this BUILD file for an
  5. # example.
  6. # For each .proto file, a proto_library target should be defined. This target
  7. # is not bound to any particular language. Instead, it defines the dependency
  8. # graph of the .proto files (i.e., proto imports) and serves as the provider
  9. # of .proto source files to the protocol compiler.
  10. #
  11. # Remote repository "com_google_protobuf" must be defined to use this rule.
  12. proto_library(
  13. name = "addressbook_proto",
  14. srcs = ["addressbook.proto"],
  15. deps = ["@com_google_protobuf//:timestamp_proto"],
  16. )
  17. # The cc_proto_library rule generates C++ code for a proto_library rule. It
  18. # must have exactly one proto_library dependency. If you want to use multiple
  19. # proto_library targets, create a separate cc_proto_library target for each
  20. # of them.
  21. #
  22. # Remote repository "com_google_protobuf_cc" must be defined to use this rule.
  23. cc_proto_library(
  24. name = "addressbook_cc_proto",
  25. deps = [":addressbook_proto"],
  26. )
  27. # cc_library/cc_binary targets can depend on cc_proto_library targets.
  28. cc_binary(
  29. name = "add_person_cpp",
  30. srcs = ["add_person.cc"],
  31. deps = [":addressbook_cc_proto"],
  32. )
  33. cc_binary(
  34. name = "list_people_cpp",
  35. srcs = ["list_people.cc"],
  36. deps = [":addressbook_cc_proto"],
  37. )
  38. # Similar to cc_proto_library but for Java.
  39. #
  40. # Remote repository "com_google_protobuf_java" must be defined to use this rule.
  41. java_proto_library(
  42. name = "addressbook_java_proto",
  43. deps = [":addressbook_proto"],
  44. )
  45. java_binary(
  46. name = "add_person_java",
  47. srcs = ["AddPerson.java"],
  48. main_class = "AddPerson",
  49. deps = [":addressbook_java_proto"],
  50. )
  51. java_binary(
  52. name = "list_people_java",
  53. srcs = ["ListPeople.java"],
  54. main_class = "ListPeople",
  55. deps = [":addressbook_java_proto"],
  56. )
  57. # Java lite.
  58. #
  59. # Remote repository "com_google_protobuf_javalite" must be defined to use this
  60. # rule.
  61. java_lite_proto_library(
  62. name = "addressbook_java_lite_proto",
  63. deps = [":addressbook_proto"],
  64. )
  65. # Java lite API is a subset of the regular Java API so if you only uses this
  66. # subset in your code, you can actually compile your code against both (i.e.,
  67. # share code between server build and Android build).
  68. #
  69. # The lite version has a smaller code size, and you can see that by comparing
  70. # the resulted .jar file:
  71. #
  72. # $ bazel build :add_person_java_deploy.jar :add_person_java_lite_deploy.jar
  73. # $ ls -l bazel-bin/*_deploy.jar
  74. # -r-xr-xr-x 1 xiaofeng eng 1230797 Sep 8 12:24 bazel-bin/add_person_java_deploy.jar
  75. # -r-xr-xr-x 1 xiaofeng eng 236166 Sep 8 12:24 bazel-bin/add_person_java_lite_deploy.jar
  76. #
  77. # In the above example, the lite .jar file is 6 times smaller. With proper
  78. # proguard inlining/stripping, the difference can be much more larger than
  79. # that.
  80. java_binary(
  81. name = "add_person_java_lite",
  82. srcs = ["AddPerson.java"],
  83. main_class = "AddPerson",
  84. deps = [":addressbook_java_lite_proto"],
  85. )
  86. java_binary(
  87. name = "list_people_java_lite",
  88. srcs = ["ListPeople.java"],
  89. main_class = "ListPeople",
  90. deps = [":addressbook_java_lite_proto"],
  91. )