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 grpc_tests_abseil_specs = list(sorted(set(list_abseil_specs("end2end_tests")) - set(grpc_abseil_specs))) 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_status.cc', 81 'src/core/ext/transport/cronet/transport/cronet_status.h', 82 'src/core/ext/transport/cronet/transport/cronet_transport.cc', 83 'src/core/ext/transport/cronet/transport/cronet_transport.h', 84 'third_party/objective_c/Cronet/bidirectional_stream_c.h' 85 ] 86 87 grpc_cronet_files = list(sorted(grpc_cronet_extra_impl_files)) 88 grpc_cronet_public_headers = list(sorted(grpc_cronet_extra_public_headers)) 89 90 grpc_test_util_files = list(sorted( 91 set(list_lib_files("end2end_tests", ("src", "headers"))) 92 - set(grpc_private_files) 93 - set(address_sorting_unwanted_files) 94 - set([ 95 # Subprocess is not supported in tvOS and not needed by our tests. 96 "test/core/util/subprocess_posix.cc", 97 ]))) 98 %> 99 Pod::Spec.new do |s| 100 s.name = 'gRPC-Core' 101 version = '${settings.version}' 102 s.version = version 103 s.summary = 'Core cross-platform gRPC library, written in C' 104 s.homepage = 'https://grpc.io' 105 s.license = 'Apache License, Version 2.0' 106 s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' } 107 108 s.source = { 109 :git => 'https://github.com/grpc/grpc.git', 110 :tag => "v#{version}", 111 :submodules => true, 112 } 113 114 # gRPC podspecs depend on fix for https://github.com/CocoaPods/CocoaPods/issues/6024, 115 # which was released in Cocoapods v1.2.0. 116 s.cocoapods_version = '>= 1.2.0' 117 118 s.ios.deployment_target = '9.0' 119 s.osx.deployment_target = '10.10' 120 s.tvos.deployment_target = '10.0' 121 s.watchos.deployment_target = '4.0' 122 123 s.requires_arc = false 124 125 name = 'grpc' 126 abseil_version = '1.20200923.3' 127 128 # When creating a dynamic framework, name it grpc.framework instead of gRPC-Core.framework. 129 # This lets users write their includes like `#include <grpc/grpc.h>` as opposed to `#include 130 # <gRPC-Core/grpc.h>`. 131 s.module_name = name 132 133 # When creating a dynamic framework, copy the headers under `include/grpc/` into the root of 134 # the `Headers/` directory of the framework (i.e., not under `Headers/include/grpc`). 135 # 136 # TODO(jcanizales): Debug why this doesn't work on macOS. 137 s.header_mappings_dir = 'include/grpc' 138 139 # The above has an undesired effect when creating a static library: It forces users to write 140 # includes like `#include <gRPC-Core/grpc.h>`. `s.header_dir` adds a path prefix to that, and 141 # because Cocoapods lets omit the pod name when including headers of static libraries, the 142 # following lets users write `#include <grpc/grpc.h>`. 143 s.header_dir = name 144 145 # The module map created automatically by Cocoapods doesn't work for C libraries like gRPC-Core. 146 s.module_map = 'include/grpc/module.modulemap' 147 148 # To compile the library, we need the user headers search path (quoted includes) to point to the 149 # root of the repo, and the system headers search path (angled includes) to point to `include/`. 150 # Cocoapods effectively clones the repo under `<Podfile dir>/Pods/gRPC-Core/`, and sets a build 151 # variable called `$(PODS_ROOT)` to `<Podfile dir>/Pods/`, so we use that. 152 # 153 # Relying on the file structure under $(PODS_ROOT) isn't officially supported in Cocoapods, as it 154 # is taken as an implementation detail. We've asked for an alternative, and have been told that 155 # what we're doing should keep working: https://github.com/CocoaPods/CocoaPods/issues/4386 156 # 157 # The `src_root` value of `$(PODS_ROOT)/gRPC-Core` assumes Cocoapods is installing this pod from 158 # its remote repo. For local development of this library, enabled by using `:path` in the Podfile, 159 # that assumption is wrong. In such case, the following settings need to be reset with the 160 # appropriate value of `src_root`. This can be accomplished in the `pre_install` hook of the 161 # Podfile; see `src/objective-c/tests/Podfile` for an example. 162 src_root = '$(PODS_ROOT)/gRPC-Core' 163 s.pod_target_xcconfig = { 164 'GRPC_SRC_ROOT' => src_root, 165 'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(GRPC_SRC_ROOT)/include"', 166 'USER_HEADER_SEARCH_PATHS' => '"$(GRPC_SRC_ROOT)"', 167 # If we don't set these two settings, `include/grpc/support/time.h` and 168 # `src/core/lib/gpr/string.h` shadow the system `<time.h>` and `<string.h>`, breaking the 169 # build. 170 'USE_HEADERMAP' => 'NO', 171 'ALWAYS_SEARCH_USER_PATHS' => 'NO', 172 'GCC_PREPROCESSOR_DEFINITIONS' => '"$(inherited)" "COCOAPODS=1"', 173 'CLANG_WARN_STRICT_PROTOTYPES' => 'NO', 174 } 175 176 s.default_subspecs = 'Interface', 'Implementation' 177 s.compiler_flags = '-DGRPC_ARES=0 -Wno-comma' 178 s.libraries = 'c++' 179 180 # Like many other C libraries, gRPC-Core has its public headers under `include/<libname>/` and its 181 # sources and private headers in other directories outside `include/`. Cocoapods' linter doesn't 182 # allow any header to be listed outside the `header_mappings_dir` (even though doing so works in 183 # practice). Because we need our `header_mappings_dir` to be `include/grpc/` for the reason 184 # mentioned above, we work around the linter limitation by dividing the pod into two subspecs, one 185 # for public headers and the other for implementation. Each gets its own `header_mappings_dir`, 186 # making the linter happy. 187 # 188 # The list of source files is generated by a template: `templates/gRPC-Core.podspec.template`. It 189 # can be regenerated from the template by running `tools/buildgen/generate_projects.sh`. 190 s.subspec 'Interface' do |ss| 191 ss.header_mappings_dir = 'include/grpc' 192 193 ss.source_files = ${ruby_multiline_list(grpc_public_headers, 22)} 194 end 195 s.subspec 'Implementation' do |ss| 196 ss.header_mappings_dir = '.' 197 ss.libraries = 'z' 198 ss.dependency "#{s.name}/Interface", version 199 ss.dependency 'BoringSSL-GRPC', '0.0.16' 200 % for abseil_spec in grpc_abseil_specs: 201 ss.dependency '${abseil_spec}', abseil_version 202 % endfor 203 ss.compiler_flags = '-DBORINGSSL_PREFIX=GRPC -Wno-unreachable-code -Wno-shorten-64-to-32' 204 205 ss.source_files = ${ruby_multiline_list(grpc_private_files, 22)} 206 ss.private_header_files = ${ruby_multiline_list(grpc_private_headers, 30)} 207 end 208 209 # CFStream is now default. Leaving this subspec only for compatibility purpose. 210 s.subspec 'CFStream-Implementation' do |ss| 211 ss.dependency "#{s.name}/Implementation", version 212 end 213 214 s.subspec 'Cronet-Interface' do |ss| 215 ss.header_mappings_dir = 'include/grpc' 216 ss.source_files = ${ruby_multiline_list(grpc_cronet_public_headers, 22)} 217 end 218 219 s.subspec 'Cronet-Implementation' do |ss| 220 ss.header_mappings_dir = '.' 221 222 ss.dependency "#{s.name}/Interface", version 223 ss.dependency "#{s.name}/Implementation", version 224 ss.dependency "#{s.name}/Cronet-Interface", version 225 226 ss.source_files = ${ruby_multiline_list(grpc_cronet_files, 22)} 227 end 228 229 s.subspec 'Tests' do |ss| 230 ss.header_mappings_dir = '.' 231 232 ss.dependency "#{s.name}/Interface", version 233 ss.dependency "#{s.name}/Implementation", version 234 % for abseil_spec in grpc_tests_abseil_specs: 235 ss.dependency '${abseil_spec}', abseil_version 236 % endfor 237 238 ss.source_files = ${ruby_multiline_list(grpc_test_util_files, 22)} 239 end 240 241 # TODO (mxyan): Instead of this hack, add include path "third_party" to C core's include path? 242 s.prepare_command = <<-END_OF_COMMAND 243 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' 244 find 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 "third_party/(.*)";#if COCOAPODS==1\\\n #include "third_party/upb/third_party/\\1"\\\n#else\\\n #include "third_party/\\1"\\\n#endif;g' 245 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' 246 find src/core/ src/cpp/ third_party/upb/ -type f -name '*.grpc_back' -print0 | xargs -0 rm 247 find src/core/ src/cpp/ 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.h";#if COCOAPODS==1\\\n #include "src/core/ext/upb-generated/\\1.upb.h"\\\n#else\\\n #include "\\1.upb.h"\\\n#endif;g' 248 find src/core/ src/cpp/ third_party/upb/ -type f \\( -name '*.h' -or -name '*.c' -or -name '*.cc' \\) -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "(.*).upbdefs.h";#if COCOAPODS==1\\\n #include "src/core/ext/upbdefs-generated/\\1.upbdefs.h"\\\n#else\\\n #include "\\1.upbdefs.h"\\\n#endif;g' 249 find src/core/ src/cpp/ third_party/upb/ -type f -name '*.grpc_back' -print0 | xargs -0 rm 250 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' 251 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' 252 find src/core/ third_party/re2/ -type f -name '*.grpc_back' -print0 | xargs -0 rm 253 END_OF_COMMAND 254 end 255