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. 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({"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' => 'grpc-packages@google.com' } 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 = '11.0' 118 s.osx.deployment_target = '10.14' 119 s.tvos.deployment_target = '13.0' 120 s.watchos.deployment_target = '6.0' 121 s.visionos.deployment_target = '1.0' 122 123 s.requires_arc = false 124 125 name = 'grpc' 126 abseil_version = '~> 1.20240722.0' 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, third_party/** and two upb generated directories, and the system headers 150 # search path (angled includes) to point to `include/`. 151 s.pod_target_xcconfig = { 152 'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(PODS_TARGET_SRCROOT)/include"'${"\\"} 153 ' "$(PODS_TARGET_SRCROOT)/third_party/address_sorting/include"', 154 'USER_HEADER_SEARCH_PATHS' => '"$(PODS_TARGET_SRCROOT)"'${"\\"} 155 ' "$(PODS_TARGET_SRCROOT)/src/core/ext/upb-gen"'${"\\"} 156 ' "$(PODS_TARGET_SRCROOT)/src/core/ext/upbdefs-gen"'${"\\"} 157 ' "$(PODS_TARGET_SRCROOT)/third_party/re2"'${"\\"} 158 ' "$(PODS_TARGET_SRCROOT)/third_party/upb"'${"\\"} 159 ' "$(PODS_TARGET_SRCROOT)/third_party/utf8_range"'${"\\"} 160 ' "$(PODS_TARGET_SRCROOT)/third_party/xxhash"', 161 # If we don't set these two settings, `include/grpc/support/time.h` and 162 # `src/core/util/string.h` shadow the system `<time.h>` and `<string.h>`, breaking the 163 # build. 164 'USE_HEADERMAP' => 'NO', 165 'ALWAYS_SEARCH_USER_PATHS' => 'NO', 166 'GCC_PREPROCESSOR_DEFINITIONS' => '"$(inherited)" "COCOAPODS=1"', 167 'CLANG_WARN_STRICT_PROTOTYPES' => 'NO', 168 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17', 169 } 170 171 s.default_subspecs = 'Interface', 'Implementation' 172 s.compiler_flags = '-DGRPC_ARES=0 -Wno-comma' 173 s.libraries = 'c++' 174 175 # Exposes the privacy manifest. Depended on by any subspecs containing 176 # non-interface files. 177 s.subspec 'Privacy' do |ss| 178 ss.resource_bundles = { 179 s.module_name => 'src/objective-c/PrivacyInfo.xcprivacy' 180 } 181 end 182 183 # Like many other C libraries, gRPC-Core has its public headers under `include/<libname>/` and its 184 # sources and private headers in other directories outside `include/`. Cocoapods' linter doesn't 185 # allow any header to be listed outside the `header_mappings_dir` (even though doing so works in 186 # practice). Because we need our `header_mappings_dir` to be `include/grpc/` for the reason 187 # mentioned above, we work around the linter limitation by dividing the pod into two subspecs, one 188 # for public headers and the other for implementation. Each gets its own `header_mappings_dir`, 189 # making the linter happy. 190 # 191 # The list of source files is generated by a template: `templates/gRPC-Core.podspec.template`. It 192 # can be regenerated from the template by running `tools/buildgen/generate_projects.sh`. 193 s.subspec 'Interface' do |ss| 194 ss.header_mappings_dir = 'include/grpc' 195 196 ss.source_files = ${ruby_multiline_list(grpc_public_headers, 22)} 197 end 198 s.subspec 'Implementation' do |ss| 199 ss.header_mappings_dir = '.' 200 ss.libraries = 'z' 201 ss.dependency "#{s.name}/Interface", version 202 ss.dependency "#{s.name}/Privacy", version 203 ss.dependency 'BoringSSL-GRPC', '0.0.38' 204 % for abseil_spec in grpc_abseil_specs: 205 ss.dependency '${abseil_spec}', abseil_version 206 % endfor 207 ss.compiler_flags = '-DBORINGSSL_PREFIX=GRPC -Wno-unreachable-code -Wno-shorten-64-to-32' 208 209 ss.source_files = ${ruby_multiline_list(grpc_private_files, 22)} 210 ss.private_header_files = ${ruby_multiline_list(grpc_private_headers, 30)} 211 end 212 213 # CFStream is now default. Leaving this subspec only for compatibility purpose. 214 s.subspec 'CFStream-Implementation' do |ss| 215 ss.dependency "#{s.name}/Implementation", version 216 end 217 218 s.subspec 'Cronet-Interface' do |ss| 219 ss.header_mappings_dir = 'include/grpc' 220 ss.source_files = ${ruby_multiline_list(grpc_cronet_public_headers, 22)} 221 end 222 223 s.subspec 'Cronet-Implementation' do |ss| 224 ss.header_mappings_dir = '.' 225 226 ss.dependency "#{s.name}/Interface", version 227 ss.dependency "#{s.name}/Implementation", version 228 ss.dependency "#{s.name}/Privacy", version 229 ss.dependency "#{s.name}/Cronet-Interface", version 230 231 ss.source_files = ${ruby_multiline_list(grpc_cronet_files, 22)} 232 end 233 234 # patch include of openssl to openssl_grpc 235 s.prepare_command = <<-END_OF_COMMAND 236 set -e 237 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' 238 find src/core/ -type f -name '*.grpc_back' -print0 | xargs -0 rm 239 END_OF_COMMAND 240 end 241