• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8  # gRPC C++ CocoaPods podspec
9  #
10  # Copyright 2017 gRPC authors.
11  #
12  # Licensed under the Apache License, Version 2.0 (the "License");
13  # you may not use this file except in compliance with the License.
14  # You may obtain a copy of the License at
15  #
16  #     http://www.apache.org/licenses/LICENSE-2.0
17  #
18  # Unless required by applicable law or agreed to in writing, software
19  # distributed under the License is distributed on an "AS IS" BASIS,
20  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  # See the License for the specific language governing permissions and
22  # limitations under the License.
23  <%
24  lib_maps = {lib.name: lib for lib in libs}
25  filegroup_maps = {filegroup.name: filegroup for filegroup in filegroups}
26
27  def ruby_multiline_list(files, indent):
28    return (',\n' + indent*' ').join('\'%s\'' % f for f in files)
29
30  def is_absl_lib(target_name):
31    return target_name.startswith("absl/")
32
33  def get_absl_spec_name(label):
34    # e.g. absl/apple:banana -> abseil/apple/banana
35    return "abseil/" + label[5:].replace(":", "/")
36
37  def lib_and_transitive_deps(lib):
38    """Return names of lib itself and all of its transitive dependencies."""
39    transitive_deps = []
40    lib_metadata = lib_maps.get(lib, None)
41    if lib_metadata:
42      transitive_deps = lib_metadata.transitive_deps
43    return list(sorted(set({lib} | set(transitive_deps))))
44
45  def non_abseil_lib_and_transitive_deps(lib):
46    return [l for l in lib_and_transitive_deps(lib) if not is_absl_lib(l)]
47
48  def list_abseil_specs(lib):
49    # This returns a list of abseil specs which the given lib and
50    # its non-abseil transitive dependencies depend on.
51    # As a result, internal abseil libraries are excluded from the result.
52    absl_specs = set()
53    for lib_name in lib_and_transitive_deps(lib):
54      if is_absl_lib(lib_name): continue
55      lib_metadata = lib_maps.get(lib_name, None)
56      if lib_metadata:
57        for dep in lib_metadata.deps:
58          if is_absl_lib(dep):
59            absl_specs.add(get_absl_spec_name(dep))
60    return list(sorted(absl_specs))
61
62  def collect_files_for_libs(libs, fields):
63    files = set()
64    for lib_name in libs:
65      lib = lib_maps.get(lib_name, None)
66      if lib:
67        for field in fields:
68          files.update(lib.get(field, []))
69    return list(sorted(files))
70
71  def filter_grpcpp(files):
72    return sorted([file for file in files if not file.startswith("include/grpc++")])
73
74  # ObjectiveC doesn't use c-ares.
75  # absl deps will be declared explicitly so we also don't need to include them.
76  grpc_full_deps = set(non_abseil_lib_and_transitive_deps("grpc")) - set({"cares"})
77  grpc_private_headers = collect_files_for_libs(grpc_full_deps, ("headers", ))
78
79  # grpc++ dependencies minus grpc and the libraries grpc itself depends on.
80  grpcpp_full_deps = set(non_abseil_lib_and_transitive_deps("grpc++")) - set(lib_and_transitive_deps("grpc"))
81
82  # TODO(jtattermusch): build.yaml no longer has filegroups, so the files here are just hand-listed
83  # This template shouldn't be touching the filegroups anyway, so this is only a bit more fragile.
84  grpcpp_proto_files = ['include/grpcpp/impl/codegen/config_protobuf.h',
85                        'include/grpcpp/impl/codegen/proto_buffer_reader.h',
86                        'include/grpcpp/impl/codegen/proto_buffer_writer.h',
87                        'include/grpcpp/impl/codegen/proto_utils.h']
88
89  grpcpp_private_files = filter_grpcpp(
90    set(collect_files_for_libs(grpcpp_full_deps, ("headers", "src")))
91    # We exclude proto related files in this particular podspec so that we can provide a protobuf-independent lib
92    - set(grpcpp_proto_files)
93  )
94  grpcpp_private_headers = filter_grpcpp(
95    set(collect_files_for_libs(grpcpp_full_deps, ("headers", )))
96    # We exclude proto related files in this particular podspec so that we can provide a protobuf-independent lib
97    - set(grpcpp_proto_files)
98  )
99  grpcpp_public_headers = filter_grpcpp(
100    set(collect_files_for_libs(grpcpp_full_deps, ("public_headers", )))
101    # We exclude proto related files in this particular podspec so that we can provide a protobuf-independent lib
102    - set(grpcpp_proto_files)
103  )
104  grpcpp_abseil_specs = list_abseil_specs("grpc++")
105  %>
106  Pod::Spec.new do |s|
107    s.name     = 'gRPC-C++'
108    # TODO (mxyan): use version that match gRPC version when pod is stabilized
109    version = '${settings.version}'
110    s.version  = version
111    s.summary  = 'gRPC C++ library'
112    s.homepage = 'https://grpc.io'
113    s.license  = 'Apache License, Version 2.0'
114    s.authors  = { 'The gRPC contributors' => 'grpc-packages@google.com' }
115
116    s.source = {
117      :git => 'https://github.com/grpc/grpc.git',
118      :tag => "v#{version}",
119    }
120
121    s.ios.deployment_target = '11.0'
122    s.osx.deployment_target = '10.14'
123    s.tvos.deployment_target = '13.0'
124    s.watchos.deployment_target = '6.0'
125    s.visionos.deployment_target = '1.0'
126
127    s.requires_arc = false
128
129    name = 'grpcpp'
130    # Use `grpcpp` as framework name so that `#include <grpcpp/xxx.h>` works when built as
131    # framework.
132    s.module_name = name
133
134    # Add include prefix `grpcpp` so that `#include <grpcpp/xxx.h>` works when built as static
135    # library.
136    s.header_dir = name
137
138    s.pod_target_xcconfig = {
139      'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(PODS_TARGET_SRCROOT)/include"'${"\\"}
140          ' "$(PODS_TARGET_SRCROOT)/third_party/address_sorting/include"',
141      'USER_HEADER_SEARCH_PATHS' => '"$(PODS_TARGET_SRCROOT)"'${"\\"}
142          ' "$(PODS_TARGET_SRCROOT)/src/core/ext/upb-gen"'${"\\"}
143          ' "$(PODS_TARGET_SRCROOT)/src/core/ext/upbdefs-gen"'${"\\"}
144          ' "$(PODS_TARGET_SRCROOT)/third_party/re2"'${"\\"}
145          ' "$(PODS_TARGET_SRCROOT)/third_party/upb"'${"\\"}
146          ' "$(PODS_TARGET_SRCROOT)/third_party/xxhash"',
147      'GCC_PREPROCESSOR_DEFINITIONS' => '"$(inherited)" "COCOAPODS=1"',
148      'CLANG_WARN_STRICT_PROTOTYPES' => 'NO',
149      'CLANG_WARN_DOCUMENTATION_COMMENTS' => 'NO',
150
151      # If we don't set these two settings, `include/grpc/support/time.h` and
152      # `src/core/lib/support/string.h` shadow the system `<time.h>` and `<string.h>`, breaking the
153      # build.
154      'USE_HEADERMAP' => 'NO',
155      'ALWAYS_SEARCH_USER_PATHS' => 'NO',
156      'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
157    }
158
159    s.libraries = 'c++'
160    s.compiler_flags = '-Wno-comma -Wno-unreachable-code -Wno-shorten-64-to-32'
161
162    s.default_subspecs = 'Interface', 'Implementation'
163
164    # Certificates, to be able to establish TLS connections:
165    s.resource_bundles = { 'gRPCCertificates-Cpp' => ['etc/roots.pem'] }
166
167    s.header_mappings_dir = 'include/grpcpp'
168
169    # Exposes the privacy manifest. Depended on by any subspecs containing
170    # non-interface files.
171    s.subspec 'Privacy' do |ss|
172      ss.resource_bundles = {
173        s.module_name => 'src/objective-c/PrivacyInfo.xcprivacy'
174      }
175    end
176
177    s.subspec 'Interface' do |ss|
178      ss.header_mappings_dir = 'include/grpcpp'
179
180      ss.source_files = ${ruby_multiline_list(grpcpp_public_headers, 22)}
181    end
182
183    s.subspec 'Implementation' do |ss|
184      ss.header_mappings_dir = '.'
185      ss.dependency "#{s.name}/Privacy", version
186      ss.dependency "#{s.name}/Interface", version
187      ss.dependency 'gRPC-Core', version
188      abseil_version = '~> 1.20240722.0'
189      % for abseil_spec in grpcpp_abseil_specs:
190      ss.dependency '${abseil_spec}', abseil_version
191      % endfor
192
193      ss.source_files = ${ruby_multiline_list(sorted(grpcpp_private_files + grpc_private_headers), 22)}
194
195      ss.private_header_files = ${ruby_multiline_list(sorted(grpcpp_private_headers + grpc_private_headers), 30)}
196    end
197
198    s.subspec 'Protobuf' do |ss|
199      ss.header_mappings_dir = 'include/grpcpp'
200      ss.dependency "#{s.name}/Interface", version
201
202      ss.source_files = ${ruby_multiline_list(grpcpp_proto_files, 22)}
203    end
204
205    s.subspec 'Cronet-Interface' do |ss|
206      ss.header_mappings_dir = 'include/grpcpp'
207      ss.public_header_files = "include/grpcpp/security/cronet_credentials.h",
208                               "include/grpcpp/security/cronet_credentials_impl.h"
209      ss.source_files = "include/grpcpp/security/cronet_credentials.h",
210                        "include/grpcpp/security/cronet_credentials_impl.h"
211    end
212
213    s.subspec 'Cronet-Implementation' do |ss|
214      ss.header_mappings_dir = '.'
215      ss.dependency "#{s.name}/Cronet-Interface", version
216      ss.dependency "#{s.name}/Implementation", version
217      ss.dependency "#{s.name}/Privacy", version
218
219      ss.dependency 'gRPC-Core/Cronet-Implementation', version
220
221      ss.source_files = "src/cpp/client/cronet_credentials.cc"
222    end
223
224    # patch include of openssl to openssl_grpc
225    s.prepare_command = <<-END_OF_COMMAND
226      set -e
227      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'
228      find src/core/ -type f -name '*.grpc_back' -print0 | xargs -0 rm
229    END_OF_COMMAND
230  end
231