gRPC-C++.podspec.template 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. %YAML 1.2
  2. --- |
  3. # This file has been automatically generated from a template file.
  4. # Please make modifications to `templates/gRPC-C++.podspec.template`
  5. # instead. This file can be regenerated from the template by running
  6. # `tools/buildgen/generate_projects.sh`.
  7. # gRPC C++ CocoaPods podspec
  8. #
  9. # Copyright 2017 gRPC authors.
  10. #
  11. # Licensed under the Apache License, Version 2.0 (the "License");
  12. # you may not use this file except in compliance with the License.
  13. # You may obtain a copy of the License at
  14. #
  15. # http://www.apache.org/licenses/LICENSE-2.0
  16. #
  17. # Unless required by applicable law or agreed to in writing, software
  18. # distributed under the License is distributed on an "AS IS" BASIS,
  19. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. # See the License for the specific language governing permissions and
  21. # limitations under the License.
  22. <%
  23. lib_maps = {lib.name: lib for lib in libs}
  24. filegroup_maps = {filegroup.name: filegroup for filegroup in filegroups}
  25. def ruby_multiline_list(files, indent):
  26. return (',\n' + indent*' ').join('\'%s\'' % f for f in files)
  27. def is_absl_lib(target_name):
  28. return target_name.startswith("absl/")
  29. def get_absl_spec_name(label):
  30. # e.g. absl/apple:banana -> abseil/apple/banana
  31. return "abseil/" + label[5:].replace(":", "/")
  32. def lib_and_transitive_deps(lib):
  33. return list(sorted(set({lib} | set(lib_maps[lib].transitive_deps))))
  34. def non_abseil_lib_and_transitive_deps(lib):
  35. return [l for l in lib_and_transitive_deps(lib) if not is_absl_lib(l)]
  36. def list_abseil_specs(lib):
  37. # This returns a list of abseil specs which the given lib and
  38. # its non-abseil transitive dependencies depend on.
  39. # As a result, internal abseil libraries are excluded from the result.
  40. absl_specs = set()
  41. for lib_name in lib_and_transitive_deps(lib):
  42. if is_absl_lib(lib_name): continue
  43. for dep in lib_maps[lib_name].deps:
  44. if is_absl_lib(dep):
  45. absl_specs.add(get_absl_spec_name(dep))
  46. return list(sorted(absl_specs))
  47. def list_lib_files(lib, fields):
  48. files = set()
  49. for lib_name in non_abseil_lib_and_transitive_deps(lib):
  50. lib = lib_maps[lib_name]
  51. for field in fields:
  52. files.update(lib.get(field, []))
  53. return list(sorted(files))
  54. def filter_grpcpp(files):
  55. return sorted([file for file in files if not file.startswith("include/grpc++")])
  56. # ObjectiveC doesn't use c-ares so we don't need address_sorting files at all
  57. address_sorting_unwanted_files = list_lib_files("address_sorting", ("public_headers", "headers", "src"))
  58. # ObjectiveC needs to obtain re2 explicitly unlike other languages; TODO @donnadionne make ObjC more consistent with others
  59. grpc_private_files = list(sorted((set(list_lib_files("grpc", ("headers", "src"))) - set(address_sorting_unwanted_files)) | set(list_lib_files("re2", ("headers", "src")))))
  60. grpc_public_headers = list(sorted((set(list_lib_files("grpc", ("public_headers",))) - set(address_sorting_unwanted_files)) | set(list_lib_files("re2", ("public_headers",)))))
  61. grpc_private_headers = list(sorted((set(list_lib_files("grpc", ("headers",))) - set(address_sorting_unwanted_files)) | set(list_lib_files("re2", ("headers",)))))
  62. # TODO(jtattermusch): build.yaml no longer has filegroups, so the files here are just hand-listed
  63. # This template shouldn't be touching the filegroups anyway, so this is only a bit more fragile.
  64. grpcpp_proto_files = ['include/grpcpp/impl/codegen/config_protobuf.h',
  65. 'include/grpcpp/impl/codegen/proto_buffer_reader.h',
  66. 'include/grpcpp/impl/codegen/proto_buffer_writer.h',
  67. 'include/grpcpp/impl/codegen/proto_utils.h']
  68. grpcpp_private_files = filter_grpcpp(
  69. set(list_lib_files("grpc++", ("headers", "src")))
  70. - set(grpc_private_files)
  71. # We exclude proto related files in this particular podspec so that we can provide a protobuf-independent lib
  72. - set(grpcpp_proto_files)
  73. - set(address_sorting_unwanted_files)
  74. )
  75. grpcpp_private_headers = filter_grpcpp(
  76. set(list_lib_files("grpc++", ("headers",)))
  77. - set(grpc_private_headers)
  78. # We exclude proto related files in this particular podspec so that we can provide a protobuf-independent lib
  79. - set(grpcpp_proto_files)
  80. - set(address_sorting_unwanted_files)
  81. )
  82. grpcpp_public_headers = filter_grpcpp(
  83. set(list_lib_files("grpc++", ("public_headers",)))
  84. - set(grpc_public_headers)
  85. # We exclude proto related files in this particular podspec so that we can provide a protobuf-independent lib
  86. - set(grpcpp_proto_files)
  87. - set(address_sorting_unwanted_files)
  88. )
  89. grpcpp_abseil_specs = list_abseil_specs("grpc++")
  90. %>
  91. Pod::Spec.new do |s|
  92. s.name = 'gRPC-C++'
  93. # TODO (mxyan): use version that match gRPC version when pod is stabilized
  94. version = '${settings.version}'
  95. s.version = version
  96. s.summary = 'gRPC C++ library'
  97. s.homepage = 'https://grpc.io'
  98. s.license = 'Apache License, Version 2.0'
  99. s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' }
  100. s.source = {
  101. :git => 'https://github.com/grpc/grpc.git',
  102. :tag => "v#{version}",
  103. }
  104. s.ios.deployment_target = '9.0'
  105. s.osx.deployment_target = '10.10'
  106. s.tvos.deployment_target = '10.0'
  107. s.requires_arc = false
  108. name = 'grpcpp'
  109. # Use `grpcpp` as framework name so that `#include <grpcpp/xxx.h>` works when built as
  110. # framework.
  111. s.module_name = name
  112. # Add include prefix `grpcpp` so that `#include <grpcpp/xxx.h>` works when built as static
  113. # library.
  114. s.header_dir = name
  115. s.pod_target_xcconfig = {
  116. 'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(PODS_TARGET_SRCROOT)/include"',
  117. 'USER_HEADER_SEARCH_PATHS' => '"$(PODS_TARGET_SRCROOT)"'${"\\"}
  118. ' "$(PODS_TARGET_SRCROOT)/src/core/ext/upb-generated"'${"\\"}
  119. ' "$(PODS_TARGET_SRCROOT)/src/core/ext/upbdefs-generated"'${"\\"}
  120. ' "$(PODS_TARGET_SRCROOT)/third_party/**"',
  121. 'GCC_PREPROCESSOR_DEFINITIONS' => '"$(inherited)" "COCOAPODS=1"',
  122. 'CLANG_WARN_STRICT_PROTOTYPES' => 'NO',
  123. 'CLANG_WARN_DOCUMENTATION_COMMENTS' => 'NO',
  124. # If we don't set these two settings, `include/grpc/support/time.h` and
  125. # `src/core/lib/support/string.h` shadow the system `<time.h>` and `<string.h>`, breaking the
  126. # build.
  127. 'USE_HEADERMAP' => 'NO',
  128. 'ALWAYS_SEARCH_USER_PATHS' => 'NO',
  129. }
  130. s.libraries = 'c++'
  131. s.compiler_flags = '-Wno-comma -Wno-unreachable-code -Wno-shorten-64-to-32'
  132. s.default_subspecs = 'Interface', 'Implementation'
  133. # Certificates, to be able to establish TLS connections:
  134. s.resource_bundles = { 'gRPCCertificates-Cpp' => ['etc/roots.pem'] }
  135. s.header_mappings_dir = 'include/grpcpp'
  136. s.subspec 'Interface' do |ss|
  137. ss.header_mappings_dir = 'include/grpcpp'
  138. ss.source_files = ${ruby_multiline_list(grpcpp_public_headers, 22)}
  139. end
  140. s.subspec 'Implementation' do |ss|
  141. ss.header_mappings_dir = '.'
  142. ss.dependency "#{s.name}/Interface", version
  143. ss.dependency 'gRPC-Core', version
  144. abseil_version = '1.20211102.0'
  145. % for abseil_spec in grpcpp_abseil_specs:
  146. ss.dependency '${abseil_spec}', abseil_version
  147. % endfor
  148. ss.source_files = ${ruby_multiline_list(sorted(grpcpp_private_files + grpc_private_headers), 22)}
  149. ss.private_header_files = ${ruby_multiline_list(sorted(grpcpp_private_headers + grpc_private_headers), 30)}
  150. end
  151. s.subspec 'Protobuf' do |ss|
  152. ss.header_mappings_dir = 'include/grpcpp'
  153. ss.dependency "#{s.name}/Interface", version
  154. ss.source_files = ${ruby_multiline_list(grpcpp_proto_files, 22)}
  155. end
  156. s.subspec 'Cronet-Interface' do |ss|
  157. ss.header_mappings_dir = 'include/grpcpp'
  158. ss.public_header_files = "include/grpcpp/security/cronet_credentials.h",
  159. "include/grpcpp/security/cronet_credentials_impl.h"
  160. ss.source_files = "include/grpcpp/security/cronet_credentials.h",
  161. "include/grpcpp/security/cronet_credentials_impl.h"
  162. end
  163. s.subspec 'Cronet-Implementation' do |ss|
  164. ss.header_mappings_dir = '.'
  165. ss.dependency "#{s.name}/Cronet-Interface", version
  166. ss.dependency "#{s.name}/Implementation", version
  167. ss.dependency 'gRPC-Core/Cronet-Implementation', version
  168. ss.source_files = "src/cpp/client/cronet_credentials.cc"
  169. end
  170. # patch include of openssl to openssl_grpc
  171. # patch xxhash.h to silent the -Wdocumentation error
  172. s.prepare_command = <<-END_OF_COMMAND
  173. set -e
  174. find src/core -type f \\( -path '*.h' -or -path '*.cc' \\) -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include <openssl/(.*)>;#if COCOAPODS==1\\\n #include <openssl_grpc/\\1>\\\n#else\\\n #include <openssl/\\1>\\\n#endif;g'
  175. find third_party/xxhash -type f -name xxhash.h -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;@param([^,]*),;@param\\1 ,;g'
  176. find src/core/ third_party/xxhash/ -type f -name '*.grpc_back' -print0 | xargs -0 rm
  177. END_OF_COMMAND
  178. end