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 names of lib itself and all of its transitive dependencies.""" 38 transitive_deps = [] 39 lib_metadata = lib_maps.get(lib, None) 40 if lib_metadata: 41 transitive_deps = lib_metadata.transitive_deps 42 return list(sorted(set({lib} | set(transitive_deps)))) 43 44 def non_abseil_lib_and_transitive_deps(lib): 45 return [l for l in lib_and_transitive_deps(lib) if not is_absl_lib(l)] 46 47 def list_abseil_specs(lib): 48 # This returns a list of abseil specs which the given lib and 49 # its non-abseil transitive dependencies depend on. 50 # As a result, internal abseil libraries are excluded from the result. 51 absl_specs = set() 52 for lib_name in lib_and_transitive_deps(lib): 53 if is_absl_lib(lib_name): continue 54 lib_metadata = lib_maps.get(lib_name, None) 55 if lib_metadata: 56 for dep in lib_metadata.deps: 57 if is_absl_lib(dep): 58 absl_specs.add(get_absl_spec_name(dep)) 59 return list(sorted(absl_specs)) 60 61 def collect_files_for_libs(libs, fields): 62 files = set() 63 for lib_name in libs: 64 lib = lib_maps.get(lib_name, None) 65 if lib: 66 for field in fields: 67 files.update(lib.get(field, [])) 68 return list(sorted(files)) 69 70 # ObjectiveC doesn't use c-ares so we don't need address_sorting and cares files at all. 71 # absl deps will be declared explicitly so we also don't need to include them. 72 grpc_full_deps = set(non_abseil_lib_and_transitive_deps("grpc")) - set({"address_sorting", "cares"}) 73 74 grpc_private_files = collect_files_for_libs(grpc_full_deps, ("headers", "src")) 75 grpc_public_headers = collect_files_for_libs(grpc_full_deps, ("public_headers", )) 76 grpc_private_headers = collect_files_for_libs(grpc_full_deps, ("headers", )) 77 78 grpc_abseil_specs = list_abseil_specs("grpc") 79 80 # TODO(jtattermusch): build.yaml is now generated from bazel build 81 # which doesn't have an explicit "grpc_cronet" target. Until it exists 82 # we construct the list of files by taking what's in the "grpc" target 83 # and adding a few files on top of that. 84 grpc_cronet_extra_public_headers = ['include/grpc/grpc_cronet.h'] 85 grpc_cronet_extra_impl_files = [ 86 'src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc', 87 'src/core/ext/transport/cronet/client/secure/cronet_channel_create.h', 88 'src/core/ext/transport/cronet/transport/cronet_status.cc', 89 'src/core/ext/transport/cronet/transport/cronet_status.h', 90 'src/core/ext/transport/cronet/transport/cronet_transport.cc', 91 'src/core/ext/transport/cronet/transport/cronet_transport.h', 92 'third_party/objective_c/Cronet/bidirectional_stream_c.h' 93 ] 94 95 grpc_cronet_files = list(sorted(grpc_cronet_extra_impl_files)) 96 grpc_cronet_public_headers = list(sorted(grpc_cronet_extra_public_headers)) 97 %> 98 Pod::Spec.new do |s| 99 s.name = 'gRPC-Core' 100 version = '${settings.version}' 101 s.version = version 102 s.summary = 'Core cross-platform gRPC library, written in C' 103 s.homepage = 'https://grpc.io' 104 s.license = 'Apache License, Version 2.0' 105 s.authors = { 'The gRPC contributors' => '[email protected]' } 106 107 s.source = { 108 :git => 'https://github.com/grpc/grpc.git', 109 :tag => "v#{version}", 110 :submodules => true, 111 } 112 113 # gRPC podspecs depend on fix for https://github.com/CocoaPods/CocoaPods/issues/6024, 114 # which was released in Cocoapods v1.2.0. 115 s.cocoapods_version = '>= 1.2.0' 116 117 s.ios.deployment_target = '10.0' 118 s.osx.deployment_target = '10.12' 119 s.tvos.deployment_target = '12.0' 120 s.watchos.deployment_target = '6.0' 121 122 s.requires_arc = false 123 124 name = 'grpc' 125 abseil_version = '1.20240116.1' 126 127 # When creating a dynamic framework, name it grpc.framework instead of gRPC-Core.framework. 128 # This lets users write their includes like `#include <grpc/grpc.h>` as opposed to `#include 129 # <gRPC-Core/grpc.h>`. 130 s.module_name = name 131 132 # When creating a dynamic framework, copy the headers under `include/grpc/` into the root of 133 # the `Headers/` directory of the framework (i.e., not under `Headers/include/grpc`). 134 # 135 # TODO(jcanizales): Debug why this doesn't work on macOS. 136 s.header_mappings_dir = 'include/grpc' 137 138 # The above has an undesired effect when creating a static library: It forces users to write 139 # includes like `#include <gRPC-Core/grpc.h>`. `s.header_dir` adds a path prefix to that, and 140 # because Cocoapods lets omit the pod name when including headers of static libraries, the 141 # following lets users write `#include <grpc/grpc.h>`. 142 s.header_dir = name 143 144 # The module map created automatically by Cocoapods doesn't work for C libraries like gRPC-Core. 145 s.module_map = 'include/grpc/module.modulemap' 146 147 # To compile the library, we need the user headers search path (quoted includes) to point to the 148 # root of the repo, third_party/** and two upb generated directories, and the system headers 149 # search path (angled includes) to point to `include/`. 150 s.pod_target_xcconfig = { 151 'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(PODS_TARGET_SRCROOT)/include"', 152 'USER_HEADER_SEARCH_PATHS' => '"$(PODS_TARGET_SRCROOT)"'${"\\"} 153 ' "$(PODS_TARGET_SRCROOT)/src/core/ext/upb-gen"'${"\\"} 154 ' "$(PODS_TARGET_SRCROOT)/src/core/ext/upbdefs-gen"'${"\\"} 155 ' "$(PODS_TARGET_SRCROOT)/third_party/re2"'${"\\"} 156 ' "$(PODS_TARGET_SRCROOT)/third_party/upb"'${"\\"} 157 ' "$(PODS_TARGET_SRCROOT)/third_party/utf8_range"'${"\\"} 158 ' "$(PODS_TARGET_SRCROOT)/third_party/xxhash"', 159 # If we don't set these two settings, `include/grpc/support/time.h` and 160 # `src/core/lib/gpr/string.h` shadow the system `<time.h>` and `<string.h>`, breaking the 161 # build. 162 'USE_HEADERMAP' => 'NO', 163 'ALWAYS_SEARCH_USER_PATHS' => 'NO', 164 'GCC_PREPROCESSOR_DEFINITIONS' => '"$(inherited)" "COCOAPODS=1"', 165 'CLANG_WARN_STRICT_PROTOTYPES' => 'NO', 166 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++14', 167 } 168 169 s.default_subspecs = 'Interface', 'Implementation' 170 s.compiler_flags = '-DGRPC_ARES=0 -Wno-comma' 171 s.libraries = 'c++' 172 173 # Exposes the privacy manifest. Depended on by any subspecs containing 174 # non-interface files. 175 s.subspec 'Privacy' do |ss| 176 ss.resource_bundles = { 177 s.module_name => 'src/objective-c/PrivacyInfo.xcprivacy' 178 } 179 end 180 181 # Like many other C libraries, gRPC-Core has its public headers under `include/<libname>/` and its 182 # sources and private headers in other directories outside `include/`. Cocoapods' linter doesn't 183 # allow any header to be listed outside the `header_mappings_dir` (even though doing so works in 184 # practice). Because we need our `header_mappings_dir` to be `include/grpc/` for the reason 185 # mentioned above, we work around the linter limitation by dividing the pod into two subspecs, one 186 # for public headers and the other for implementation. Each gets its own `header_mappings_dir`, 187 # making the linter happy. 188 # 189 # The list of source files is generated by a template: `templates/gRPC-Core.podspec.template`. It 190 # can be regenerated from the template by running `tools/buildgen/generate_projects.sh`. 191 s.subspec 'Interface' do |ss| 192 ss.header_mappings_dir = 'include/grpc' 193 194 ss.source_files = ${ruby_multiline_list(grpc_public_headers, 22)} 195 end 196 s.subspec 'Implementation' do |ss| 197 ss.header_mappings_dir = '.' 198 ss.libraries = 'z' 199 ss.dependency "#{s.name}/Interface", version 200 ss.dependency "#{s.name}/Privacy", version 201 ss.dependency 'BoringSSL-GRPC', '0.0.33' 202 % for abseil_spec in grpc_abseil_specs: 203 ss.dependency '${abseil_spec}', abseil_version 204 % endfor 205 ss.compiler_flags = '-DBORINGSSL_PREFIX=GRPC -Wno-unreachable-code -Wno-shorten-64-to-32' 206 207 ss.source_files = ${ruby_multiline_list(grpc_private_files, 22)} 208 ss.private_header_files = ${ruby_multiline_list(grpc_private_headers, 30)} 209 end 210 211 # CFStream is now default. Leaving this subspec only for compatibility purpose. 212 s.subspec 'CFStream-Implementation' do |ss| 213 ss.dependency "#{s.name}/Implementation", version 214 end 215 216 s.subspec 'Cronet-Interface' do |ss| 217 ss.header_mappings_dir = 'include/grpc' 218 ss.source_files = ${ruby_multiline_list(grpc_cronet_public_headers, 22)} 219 end 220 221 s.subspec 'Cronet-Implementation' do |ss| 222 ss.header_mappings_dir = '.' 223 224 ss.dependency "#{s.name}/Interface", version 225 ss.dependency "#{s.name}/Implementation", version 226 ss.dependency "#{s.name}/Privacy", version 227 ss.dependency "#{s.name}/Cronet-Interface", version 228 229 ss.source_files = ${ruby_multiline_list(grpc_cronet_files, 22)} 230 end 231 232 # patch include of openssl to openssl_grpc 233 s.prepare_command = <<-END_OF_COMMAND 234 set -e 235 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' 236 find src/core/ -type f -name '*.grpc_back' -print0 | xargs -0 rm 237 END_OF_COMMAND 238 end 239