objc_grpc_library.bzl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright 2021 The gRPC Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """
  15. Contains the objc_grpc_library rule.
  16. """
  17. load(
  18. "//bazel:generate_objc.bzl",
  19. "generate_objc",
  20. "generate_objc_hdrs",
  21. "generate_objc_non_arc_srcs",
  22. "generate_objc_srcs",
  23. )
  24. def objc_grpc_library(name, deps, srcs = [], use_well_known_protos = False, **kwargs):
  25. """Generates messages and/or service stubs for given proto_library and all transitively dependent proto files
  26. Args:
  27. name: name of target
  28. deps: a list of proto_library targets that needs to be compiled
  29. srcs: a list of labels to proto files with service stubs to be generated,
  30. labels specified must include service stubs; otherwise Bazel will complain about srcs being empty
  31. use_well_known_protos: whether to use the well known protos defined in
  32. @com_google_protobuf//src/google/protobuf, default to false
  33. **kwargs: other arguments
  34. """
  35. objc_grpc_library_name = "_" + name + "_objc_grpc_library"
  36. generate_objc(
  37. name = objc_grpc_library_name,
  38. srcs = srcs,
  39. deps = deps,
  40. use_well_known_protos = use_well_known_protos,
  41. **kwargs
  42. )
  43. generate_objc_hdrs(
  44. name = objc_grpc_library_name + "_hdrs",
  45. src = ":" + objc_grpc_library_name,
  46. )
  47. generate_objc_non_arc_srcs(
  48. name = objc_grpc_library_name + "_non_arc_srcs",
  49. src = ":" + objc_grpc_library_name,
  50. )
  51. arc_srcs = None
  52. if len(srcs) > 0:
  53. generate_objc_srcs(
  54. name = objc_grpc_library_name + "_srcs",
  55. src = ":" + objc_grpc_library_name,
  56. )
  57. arc_srcs = [":" + objc_grpc_library_name + "_srcs"]
  58. native.objc_library(
  59. name = name,
  60. hdrs = [":" + objc_grpc_library_name + "_hdrs"],
  61. non_arc_srcs = [":" + objc_grpc_library_name + "_non_arc_srcs"],
  62. srcs = arc_srcs,
  63. defines = [
  64. "GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0",
  65. "GPB_GRPC_FORWARD_DECLARE_MESSAGE_PROTO=0",
  66. ],
  67. includes = [
  68. "_generated_protos",
  69. "src/objective-c",
  70. ],
  71. deps = [
  72. "@com_github_grpc_grpc//src/objective-c:proto_objc_rpc",
  73. "@com_google_protobuf//:protobuf_objc",
  74. ],
  75. **kwargs
  76. )