• 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-Core.podspec.template`
5  # instead. This file can be regenerated from the template by running
6  # `tools/buildgen/generate_projects.sh`.
7
8  # gRPC Core CocoaPods podspec
9  #
10  # Copyright 2015 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
26  def ruby_multiline_list(files, indent):
27    return (',\n' + indent*' ').join('\'%s\'' % f for f in files)
28
29  def is_absl_lib(target_name):
30    return target_name.startswith("absl/")
31
32  def get_absl_spec_name(label):
33    # e.g. absl/apple:banana -> abseil/apple/banana
34    return "abseil/" + label[5:].replace(":", "/")
35
36  def lib_and_transitive_deps(lib):
37    return list(sorted(set({lib} | set(lib_maps[lib].transitive_deps))))
38
39  def non_abseil_lib_and_transitive_deps(lib):
40    return [l for l in lib_and_transitive_deps(lib) if not is_absl_lib(l)]
41
42  def list_abseil_specs(lib):
43    # This returns a list of abseil specs which the given lib and
44    # its non-abseil transitive dependencies depend on.
45    # As a result, internal abseil libraries are excluded from the result.
46    absl_specs = set()
47    for lib_name in lib_and_transitive_deps(lib):
48      if is_absl_lib(lib_name): continue
49      for dep in lib_maps[lib_name].deps:
50        if is_absl_lib(dep):
51          absl_specs.add(get_absl_spec_name(dep))
52    return list(sorted(absl_specs))
53
54  def list_lib_files(lib, fields):
55    files = set()
56    for lib_name in non_abseil_lib_and_transitive_deps(lib):
57      lib = lib_maps[lib_name]
58      for field in fields:
59        files.update(lib.get(field, []))
60    return list(sorted(files))
61
62  # ObjectiveC doesn't use c-ares so we don't need address_sorting files at all
63  address_sorting_unwanted_files = list_lib_files("address_sorting", ("public_headers", "headers", "src"))
64
65  # ObjectiveC needs to obtain re2 explicitly unlike other languages; TODO @donnadionne make ObjC more consistent with others
66  grpc_private_files = list(sorted((set(list_lib_files("grpc", ("headers", "src"))) - set(address_sorting_unwanted_files)) | set(list_lib_files("re2", ("headers", "src")))))
67  grpc_public_headers = list(sorted((set(list_lib_files("grpc", ("public_headers",))) - set(address_sorting_unwanted_files)) | set(list_lib_files("re2", ("public_headers",)))))
68  grpc_private_headers = list(sorted((set(list_lib_files("grpc", ("headers",))) - set(address_sorting_unwanted_files)) | set(list_lib_files("re2", ("headers",)))))
69  grpc_abseil_specs = list_abseil_specs("grpc")
70
71
72  # TODO(jtattermusch): build.yaml is now generated from bazel build
73  # which doesn't have an explicit "grpc_cronet" target. Until it exists
74  # we construct the list of files by taking what's in the "grpc" target
75  # and adding a few files on top of that.
76  grpc_cronet_extra_public_headers = ['include/grpc/grpc_cronet.h']
77  grpc_cronet_extra_impl_files = [
78      'src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc',
79      'src/core/ext/transport/cronet/client/secure/cronet_channel_create.h',
80      'src/core/ext/transport/cronet/transport/cronet_transport.cc',
81      'src/core/ext/transport/cronet/transport/cronet_transport.h',
82      'third_party/objective_c/Cronet/bidirectional_stream_c.h'
83  ]
84
85  grpc_cronet_files = list(sorted(grpc_cronet_extra_impl_files))
86  grpc_cronet_public_headers = list(sorted(grpc_cronet_extra_public_headers))
87
88  grpc_test_util_files = list(sorted(
89    set(list_lib_files("end2end_tests", ("src", "headers")))
90    - set(grpc_private_files)
91    - set(address_sorting_unwanted_files)
92    - set([
93      # Subprocess is not supported in tvOS and not needed by our tests.
94      "test/core/util/subprocess_posix.cc",
95    ])))
96  %>
97  Pod::Spec.new do |s|
98    s.name     = 'gRPC-Core'
99    version = '${settings.version}'
100    s.version  = version
101    s.summary  = 'Core cross-platform gRPC library, written in C'
102    s.homepage = 'https://grpc.io'
103    s.license  = 'Apache License, Version 2.0'
104    s.authors  = { 'The gRPC contributors' => 'grpc-packages@google.com' }
105
106    s.source = {
107      :git => 'https://github.com/grpc/grpc.git',
108      :tag => "v#{version}",
109      :submodules => true,
110    }
111
112    # gRPC podspecs depend on fix for https://github.com/CocoaPods/CocoaPods/issues/6024,
113    # which was released in Cocoapods v1.2.0.
114    s.cocoapods_version = '>= 1.2.0'
115
116    s.ios.deployment_target = '7.0'
117    s.osx.deployment_target = '10.9'
118    s.tvos.deployment_target = '10.0'
119    s.watchos.deployment_target = '4.0'
120
121    s.requires_arc = false
122
123    name = 'grpc'
124
125    # When creating a dynamic framework, name it grpc.framework instead of gRPC-Core.framework.
126    # This lets users write their includes like `#include <grpc/grpc.h>` as opposed to `#include
127    # <gRPC-Core/grpc.h>`.
128    s.module_name = name
129
130    # When creating a dynamic framework, copy the headers under `include/grpc/` into the root of
131    # the `Headers/` directory of the framework (i.e., not under `Headers/include/grpc`).
132    #
133    # TODO(jcanizales): Debug why this doesn't work on macOS.
134    s.header_mappings_dir = 'include/grpc'
135
136    # The above has an undesired effect when creating a static library: It forces users to write
137    # includes like `#include <gRPC-Core/grpc.h>`. `s.header_dir` adds a path prefix to that, and
138    # because Cocoapods lets omit the pod name when including headers of static libraries, the
139    # following lets users write `#include <grpc/grpc.h>`.
140    s.header_dir = name
141
142    # The module map created automatically by Cocoapods doesn't work for C libraries like gRPC-Core.
143    s.module_map = 'include/grpc/module.modulemap'
144
145    # To compile the library, we need the user headers search path (quoted includes) to point to the
146    # root of the repo, and the system headers search path (angled includes) to point to `include/`.
147    # Cocoapods effectively clones the repo under `<Podfile dir>/Pods/gRPC-Core/`, and sets a build
148    # variable called `$(PODS_ROOT)` to `<Podfile dir>/Pods/`, so we use that.
149    #
150    # Relying on the file structure under $(PODS_ROOT) isn't officially supported in Cocoapods, as it
151    # is taken as an implementation detail. We've asked for an alternative, and have been told that
152    # what we're doing should keep working: https://github.com/CocoaPods/CocoaPods/issues/4386
153    #
154    # The `src_root` value of `$(PODS_ROOT)/gRPC-Core` assumes Cocoapods is installing this pod from
155    # its remote repo. For local development of this library, enabled by using `:path` in the Podfile,
156    # that assumption is wrong. In such case, the following settings need to be reset with the
157    # appropriate value of `src_root`. This can be accomplished in the `pre_install` hook of the
158    # Podfile; see `src/objective-c/tests/Podfile` for an example.
159    src_root = '$(PODS_ROOT)/gRPC-Core'
160    s.pod_target_xcconfig = {
161      'GRPC_SRC_ROOT' => src_root,
162      'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(GRPC_SRC_ROOT)/include"',
163      'USER_HEADER_SEARCH_PATHS' => '"$(GRPC_SRC_ROOT)"',
164      # If we don't set these two settings, `include/grpc/support/time.h` and
165      # `src/core/lib/gpr/string.h` shadow the system `<time.h>` and `<string.h>`, breaking the
166      # build.
167      'USE_HEADERMAP' => 'NO',
168      'ALWAYS_SEARCH_USER_PATHS' => 'NO',
169      'GCC_PREPROCESSOR_DEFINITIONS' => '"$(inherited)" "COCOAPODS=1"',
170      'CLANG_WARN_STRICT_PROTOTYPES' => 'NO',
171    }
172
173    s.default_subspecs = 'Interface', 'Implementation'
174    s.compiler_flags = '-DGRPC_ARES=0 -Wno-comma'
175    s.libraries = 'c++'
176
177    # Like many other C libraries, gRPC-Core has its public headers under `include/<libname>/` and its
178    # sources and private headers in other directories outside `include/`. Cocoapods' linter doesn't
179    # allow any header to be listed outside the `header_mappings_dir` (even though doing so works in
180    # practice). Because we need our `header_mappings_dir` to be `include/grpc/` for the reason
181    # mentioned above, we work around the linter limitation by dividing the pod into two subspecs, one
182    # for public headers and the other for implementation. Each gets its own `header_mappings_dir`,
183    # making the linter happy.
184    #
185    # The list of source files is generated by a template: `templates/gRPC-Core.podspec.template`. It
186    # can be regenerated from the template by running `tools/buildgen/generate_projects.sh`.
187    s.subspec 'Interface' do |ss|
188      ss.header_mappings_dir = 'include/grpc'
189
190      ss.source_files = ${ruby_multiline_list(grpc_public_headers, 22)}
191    end
192    s.subspec 'Implementation' do |ss|
193      ss.header_mappings_dir = '.'
194      ss.libraries = 'z'
195      ss.dependency "#{s.name}/Interface", version
196      ss.dependency 'BoringSSL-GRPC', '0.0.11'
197      abseil_version = '1.20200225.0'
198      % for abseil_spec in grpc_abseil_specs:
199      ss.dependency '${abseil_spec}', abseil_version
200      % endfor
201      ss.compiler_flags = '-DBORINGSSL_PREFIX=GRPC -Wno-unreachable-code -Wno-shorten-64-to-32'
202
203      ss.source_files = ${ruby_multiline_list(grpc_private_files, 22)}
204      ss.private_header_files = ${ruby_multiline_list(grpc_private_headers, 30)}
205    end
206
207    # CFStream is now default. Leaving this subspec only for compatibility purpose.
208    s.subspec 'CFStream-Implementation' do |ss|
209      ss.dependency "#{s.name}/Implementation", version
210    end
211
212    s.subspec 'Cronet-Interface' do |ss|
213      ss.header_mappings_dir = 'include/grpc'
214      ss.source_files = ${ruby_multiline_list(grpc_cronet_public_headers, 22)}
215    end
216
217    s.subspec 'Cronet-Implementation' do |ss|
218      ss.header_mappings_dir = '.'
219
220      ss.dependency "#{s.name}/Interface", version
221      ss.dependency "#{s.name}/Implementation", version
222      ss.dependency "#{s.name}/Cronet-Interface", version
223
224      ss.source_files = ${ruby_multiline_list(grpc_cronet_files, 22)}
225    end
226
227    s.subspec 'Tests' do |ss|
228      ss.header_mappings_dir = '.'
229
230      ss.dependency "#{s.name}/Interface", version
231      ss.dependency "#{s.name}/Implementation", version
232
233      ss.source_files = ${ruby_multiline_list(grpc_test_util_files, 22)}
234    end
235
236    # TODO (mxyan): Instead of this hack, add include path "third_party" to C core's include path?
237    s.prepare_command = <<-END_OF_COMMAND
238      sed -E -i '' 's;#include <openssl/(.*)>;#if COCOAPODS==1\\\n  #include <openssl_grpc/\\1>\\\n#else\\\n  #include <openssl/\\1>\\\n#endif;g' $(find src/core -type f \\( -path '*.h' -or -path '*.cc' \\) -print | xargs grep -H -c '#include <openssl_grpc/' | grep 0$ | cut -d':' -f1)
239      find src/core/ src/cpp/ third_party/upb/ -type f \\( -name '*.h' -or -name '*.hpp' -or -name '*.c' -or -name '*.cc' \\) -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "upb/(.*)";#if COCOAPODS==1\\\n  #include  "third_party/upb/upb/\\1"\\\n#else\\\n  #include  "upb/\\1"\\\n#endif;g'
240      find src/core/ src/cpp/ third_party/upb/ -type f -name '*.grpc_back' -print0 | xargs -0 rm
241      find src/core/ src/cpp/ -type f \\( -name '*.h' -or -name '*.c' -or -name '*.cc' \\) -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "(.*).upb.h";#if COCOAPODS==1\\\n  #include  "src/core/ext/upb-generated/\\1.upb.h"\\\n#else\\\n  #include  "\\1.upb.h"\\\n#endif;g'
242      find src/core/ src/cpp/ -type f -name '*.grpc_back' -print0 | xargs -0 rm
243      find third_party/re2/re2/ third_party/re2/util/ -type f \\( -name '*.h' -or -name '*.cc' \\) -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "re2/(.*)";#if COCOAPODS==1\\\n  #include  "third_party/re2/re2/\\1"\\\n#else\\\n  #include  "re2/\\1"\\\n#endif;g;s;#include "util/(.*)";#if COCOAPODS==1\\\n  #include  "third_party/re2/util/\\1"\\\n#else\\\n  #include  "util/\\1"\\\n#endif;g'
244      find src/core/ -type f \\( -name '*.h' -or -name '*.cc' \\) -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "re2/(.*)";#if COCOAPODS==1\\\n  #include  "third_party/re2/re2/\\1"\\\n#else\\\n  #include  "re2/\\1"\\\n#endif;g'
245      find src/core/ third_party/re2/ -type f -name '*.grpc_back' -print0 | xargs -0 rm
246    END_OF_COMMAND
247  end
248