Imported Upstream version 1.27.0
[platform/upstream/grpc.git] / templates / gRPC-C++.podspec.template
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 list(sorted(set({lib} | set(lib_maps[lib].transitive_deps))))
39
40   def non_abseil_lib_and_transitive_deps(lib):
41     return [l for l in lib_and_transitive_deps(lib) if not is_absl_lib(l)]
42
43   def list_abseil_specs(lib):
44     # This returns a list of abseil specs which the given lib and
45     # its non-abseil transitive dependencies depend on.
46     # As a result, internal abseil libraries are excluded from the result.
47     absl_specs = set()
48     for lib_name in lib_and_transitive_deps(lib):
49       if is_absl_lib(lib_name): continue
50       for dep in lib_maps[lib_name].deps:
51         if is_absl_lib(dep):
52           absl_specs.add(get_absl_spec_name(dep))
53     return list(sorted(absl_specs))
54
55   def list_lib_files(lib, fields):
56     files = set()
57     for lib_name in non_abseil_lib_and_transitive_deps(lib):
58       lib = lib_maps[lib_name]
59       for field in fields:
60         files.update(lib.get(field, []))
61     return list(sorted(files))
62
63   def list_filegroup_files(expect_filegroups, groups):
64     out = []
65     for filegroup_name in expect_filegroups:
66       filegroup = filegroup_maps[filegroup_name]
67       for group in groups:
68         out += filegroup.get(group, [])
69     return list(sorted(set(out)))
70
71   def filter_grpcpp(files):
72     return sorted([file for file in files if not file.startswith("include/grpc++")])
73
74   grpc_private_files = list_lib_files("grpc", ("headers", "src"))
75   grpc_public_headers = list_lib_files("grpc", ("public_headers",))
76   grpc_private_headers = list_lib_files("grpc", ("headers",))
77
78   grpcpp_proto_files = filter_grpcpp(
79     set(list_filegroup_files(("grpc++_codegen_proto", "grpc++_config_proto"), ("headers", "src", "public_headers")))
80     - set(list_filegroup_files(("grpc++_codegen_base",), ("headers", "src", "public_headers")))
81   )
82   grpcpp_private_files = filter_grpcpp(
83     set(list_lib_files("grpc++", ("headers", "src")))
84     - set(grpc_private_files)
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   )
88   grpcpp_private_headers = filter_grpcpp(
89     set(list_lib_files("grpc++", ("headers",)))
90     - set(grpc_private_headers)
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_public_headers = filter_grpcpp(
95     set(list_lib_files("grpc++", ("public_headers",)))
96     - set(grpc_public_headers)
97     # We exclude proto related files in this particular podspec so that we can provide a protobuf-independent lib
98     - set(grpcpp_proto_files)
99   )
100   grpcpp_abseil_specs = list_abseil_specs("grpc++")
101   %>
102   Pod::Spec.new do |s|
103     s.name     = 'gRPC-C++'
104     # TODO (mxyan): use version that match gRPC version when pod is stabilized
105     version = '${settings.version}'
106     s.version  = version
107     s.summary  = 'gRPC C++ library'
108     s.homepage = 'https://grpc.io'
109     s.license  = 'Apache License, Version 2.0'
110     s.authors  = { 'The gRPC contributors' => 'grpc-packages@google.com' }
111
112     s.source = {
113       :git => 'https://github.com/grpc/grpc.git',
114       :tag => "v#{version}",
115     }
116
117     s.ios.deployment_target = '7.0'
118     s.osx.deployment_target = '10.9'
119     s.tvos.deployment_target = '10.0'
120
121     s.requires_arc = false
122
123     name = 'grpcpp'
124     # Use `grpcpp` as framework name so that `#include <grpcpp/xxx.h>` works when built as
125     # framework.
126     s.module_name = name
127
128     # Add include prefix `grpcpp` so that `#include <grpcpp/xxx.h>` works when built as static
129     # library.
130     s.header_dir = name
131
132     s.pod_target_xcconfig = {
133       'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(PODS_TARGET_SRCROOT)/include"',
134       'USER_HEADER_SEARCH_PATHS' => '"$(PODS_TARGET_SRCROOT)"',
135       'GCC_PREPROCESSOR_DEFINITIONS' => '"$(inherited)" "COCOAPODS=1"',
136       'CLANG_WARN_STRICT_PROTOTYPES' => 'NO',
137       'CLANG_WARN_DOCUMENTATION_COMMENTS' => 'NO',
138
139       # If we don't set these two settings, `include/grpc/support/time.h` and
140       # `src/core/lib/support/string.h` shadow the system `<time.h>` and `<string.h>`, breaking the
141       # build.
142       'USE_HEADERMAP' => 'NO',
143       'ALWAYS_SEARCH_USER_PATHS' => 'NO',
144     }
145
146     s.libraries = 'c++'
147     s.compiler_flags = '-Wno-comma'
148
149     s.default_subspecs = 'Interface', 'Implementation'
150
151     # Certificates, to be able to establish TLS connections:
152     s.resource_bundles = { 'gRPCCertificates-Cpp' => ['etc/roots.pem'] }
153
154     s.header_mappings_dir = 'include/grpcpp'
155
156     s.subspec 'Interface' do |ss|
157       ss.header_mappings_dir = 'include/grpcpp'
158
159       ss.source_files = ${ruby_multiline_list(grpcpp_public_headers, 22)}
160     end
161
162     s.subspec 'Implementation' do |ss|
163       ss.header_mappings_dir = '.'
164       ss.dependency "#{s.name}/Interface", version
165       ss.dependency 'gRPC-Core', version
166       abseil_version = '0.20190808.1'
167       % for abseil_spec in grpcpp_abseil_specs:
168       ss.dependency '${abseil_spec}', abseil_version
169       % endfor
170
171       ss.source_files = ${ruby_multiline_list(sorted(grpcpp_private_files + grpc_private_headers), 22)}
172
173       ss.private_header_files = ${ruby_multiline_list(sorted(grpcpp_private_headers + grpc_private_headers), 30)}
174     end
175
176     s.subspec 'Protobuf' do |ss|
177       ss.header_mappings_dir = 'include/grpcpp'
178       ss.dependency "#{s.name}/Interface", version
179
180       ss.source_files = ${ruby_multiline_list(grpcpp_proto_files, 22)}
181     end
182
183     s.subspec 'Cronet-Interface' do |ss|
184       ss.header_mappings_dir = 'include/grpcpp'
185       ss.public_header_files = "include/grpcpp/security/cronet_credentials.h",
186                                "include/grpcpp/security/cronet_credentials_impl.h"
187       ss.source_files = "include/grpcpp/security/cronet_credentials.h",
188                         "include/grpcpp/security/cronet_credentials_impl.h"
189     end
190
191     s.subspec 'Cronet-Implementation' do |ss|
192       ss.header_mappings_dir = '.'
193       ss.dependency "#{s.name}/Cronet-Interface", version
194       ss.dependency "#{s.name}/Implementation", version
195
196       ss.dependency 'gRPC-Core/Cronet-Implementation', version
197
198       ss.source_files = "src/cpp/client/cronet_credentials.cc"
199     end
200
201     s.prepare_command = <<-END_OF_COMMAND
202       find src/core/ third_party/upb/ -type f \\( -name '*.h' -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'
203       find src/core/ third_party/upb/ -type f -name '*.grpc_back' -print0 | xargs -0 rm
204       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'
205       find src/core/ src/cpp/ -type f -name '*.grpc_back' -print0 | xargs -0 rm
206     END_OF_COMMAND
207   end