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 <%! 25 def grpc_lib_files(libs, expect_libs, groups): 26 out = [] 27 for lib in libs: 28 if lib.name in expect_libs: 29 for group in groups: 30 out += lib.get(group, []) 31 return out 32 33 def grpc_private_files(libs): 34 out = grpc_lib_files(libs, ("grpc", "gpr"), ("headers", "src")) 35 return [file for file in out if not file.startswith("third_party/nanopb/")] 36 37 def grpc_public_headers(libs): 38 out = grpc_lib_files(libs, ("grpc", "gpr"), ("public_headers",)) 39 return out 40 41 def grpc_private_headers(libs): 42 out = grpc_lib_files(libs, ("grpc", "gpr"), ("headers",)) 43 return [file for file in out if not file.startswith("third_party/nanopb/")] 44 45 def grpc_cronet_files(libs): 46 out = grpc_lib_files(libs, ("grpc_cronet",), ("src", "headers")) 47 excl = grpc_private_files(libs) 48 excl += [ 49 # We do not need cronet dedicated plugin registry 50 "src/core/plugin_registry/grpc_cronet_plugin_registry.cc", 51 # We do not need dummy cronet API for ObjC 52 "src/core/ext/transport/cronet/transport/cronet_api_dummy.cc", 53 ] 54 return [file for file in out if not file in excl] 55 56 def grpc_cronet_public_headers(libs): 57 out = grpc_lib_files(libs, ("grpc_cronet",), ("public_headers",)) 58 excl = grpc_public_headers(libs) 59 return [file for file in out if not file in excl] 60 61 def grpc_test_util_files(libs): 62 out = grpc_lib_files(libs, ("grpc_test_util", "gpr_test_util"), ("src", "headers")) 63 excl = grpc_private_files(libs) 64 return [file for file in out if not file in excl] 65 66 def end2end_tests_files(libs): 67 out = grpc_lib_files(libs, ("end2end_tests",), ("src", "headers")) 68 excl = grpc_private_files(libs) 69 return [file for file in out if not file in excl] 70 71 def cfstream_private_headers(libs): 72 out = grpc_lib_files(libs, ("grpc_cfstream",), ("own_headers",)) 73 return out 74 75 def cfstream_private_files(libs): 76 out = grpc_lib_files(libs, ("grpc_cfstream",), ("own_src", "own_headers")) 77 return out 78 79 def ruby_multiline_list(files, indent): 80 return (',\n' + indent*' ').join('\'%s\'' % f for f in files) 81 %> 82 Pod::Spec.new do |s| 83 s.name = 'gRPC-Core' 84 version = '${settings.version}' 85 s.version = version 86 s.summary = 'Core cross-platform gRPC library, written in C' 87 s.homepage = 'https://grpc.io' 88 s.license = 'Apache License, Version 2.0' 89 s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' } 90 91 s.source = { 92 :git => 'https://github.com/grpc/grpc.git', 93 :tag => "v#{version}", 94 } 95 96 # gRPC podspecs depend on fix for https://github.com/CocoaPods/CocoaPods/issues/6024, 97 # which was released in Cocoapods v1.2.0. 98 s.cocoapods_version = '>= 1.2.0' 99 100 s.ios.deployment_target = '7.0' 101 s.osx.deployment_target = '10.9' 102 s.requires_arc = false 103 104 name = 'grpc' 105 106 # When creating a dynamic framework, name it grpc.framework instead of gRPC-Core.framework. 107 # This lets users write their includes like `#include <grpc/grpc.h>` as opposed to `#include 108 # <gRPC-Core/grpc.h>`. 109 s.module_name = name 110 111 # When creating a dynamic framework, copy the headers under `include/grpc/` into the root of 112 # the `Headers/` directory of the framework (i.e., not under `Headers/include/grpc`). 113 # 114 # TODO(jcanizales): Debug why this doesn't work on macOS. 115 s.header_mappings_dir = 'include/grpc' 116 117 # The above has an undesired effect when creating a static library: It forces users to write 118 # includes like `#include <gRPC-Core/grpc.h>`. `s.header_dir` adds a path prefix to that, and 119 # because Cocoapods lets omit the pod name when including headers of static libraries, the 120 # following lets users write `#include <grpc/grpc.h>`. 121 s.header_dir = name 122 123 # The module map created automatically by Cocoapods doesn't work for C libraries like gRPC-Core. 124 s.module_map = 'include/grpc/module.modulemap' 125 126 # To compile the library, we need the user headers search path (quoted includes) to point to the 127 # root of the repo, and the system headers search path (angled includes) to point to `include/`. 128 # Cocoapods effectively clones the repo under `<Podfile dir>/Pods/gRPC-Core/`, and sets a build 129 # variable called `$(PODS_ROOT)` to `<Podfile dir>/Pods/`, so we use that. 130 # 131 # Relying on the file structure under $(PODS_ROOT) isn't officially supported in Cocoapods, as it 132 # is taken as an implementation detail. We've asked for an alternative, and have been told that 133 # what we're doing should keep working: https://github.com/CocoaPods/CocoaPods/issues/4386 134 # 135 # The `src_root` value of `$(PODS_ROOT)/gRPC-Core` assumes Cocoapods is installing this pod from 136 # its remote repo. For local development of this library, enabled by using `:path` in the Podfile, 137 # that assumption is wrong. In such case, the following settings need to be reset with the 138 # appropriate value of `src_root`. This can be accomplished in the `pre_install` hook of the 139 # Podfile; see `src/objective-c/tests/Podfile` for an example. 140 src_root = '$(PODS_ROOT)/gRPC-Core' 141 s.pod_target_xcconfig = { 142 'GRPC_SRC_ROOT' => src_root, 143 'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(GRPC_SRC_ROOT)/include"', 144 'USER_HEADER_SEARCH_PATHS' => '"$(GRPC_SRC_ROOT)"', 145 # If we don't set these two settings, `include/grpc/support/time.h` and 146 # `src/core/lib/gpr/string.h` shadow the system `<time.h>` and `<string.h>`, breaking the 147 # build. 148 'USE_HEADERMAP' => 'NO', 149 'ALWAYS_SEARCH_USER_PATHS' => 'NO', 150 'GCC_PREPROCESSOR_DEFINITIONS' => '"$(inherited)" "COCOAPODS=1" "PB_NO_PACKED_STRUCTS=1"', 151 'CLANG_WARN_STRICT_PROTOTYPES' => 'NO', 152 } 153 154 s.default_subspecs = 'Interface', 'Implementation' 155 s.compiler_flags = '-DGRPC_ARES=0', '-DPB_FIELD_16BIT' 156 s.libraries = 'c++' 157 158 # Like many other C libraries, gRPC-Core has its public headers under `include/<libname>/` and its 159 # sources and private headers in other directories outside `include/`. Cocoapods' linter doesn't 160 # allow any header to be listed outside the `header_mappings_dir` (even though doing so works in 161 # practice). Because we need our `header_mappings_dir` to be `include/grpc/` for the reason 162 # mentioned above, we work around the linter limitation by dividing the pod into two subspecs, one 163 # for public headers and the other for implementation. Each gets its own `header_mappings_dir`, 164 # making the linter happy. 165 # 166 # The list of source files is generated by a template: `templates/gRPC-Core.podspec.template`. It 167 # can be regenerated from the template by running `tools/buildgen/generate_projects.sh`. 168 s.subspec 'Interface' do |ss| 169 ss.header_mappings_dir = 'include/grpc' 170 171 ss.source_files = ${ruby_multiline_list(grpc_public_headers(libs), 22)} 172 end 173 s.subspec 'Implementation' do |ss| 174 ss.header_mappings_dir = '.' 175 ss.libraries = 'z' 176 ss.dependency "#{s.name}/Interface", version 177 ss.dependency 'BoringSSL-GRPC', '0.0.1' 178 ss.dependency 'nanopb', '~> 0.3' 179 ss.compiler_flags = '-DGRPC_SHADOW_BORINGSSL_SYMBOLS' 180 181 # To save you from scrolling, this is the last part of the podspec. 182 ss.source_files = ${ruby_multiline_list(grpc_private_files(libs), 22)} 183 184 ss.private_header_files = ${ruby_multiline_list(grpc_private_headers(libs), 30)} 185 end 186 187 s.subspec 'CFStream-Implementation' do |ss| 188 ss.header_mappings_dir = '.' 189 ss.dependency "#{s.name}/Implementation", version 190 ss.pod_target_xcconfig = { 191 'GCC_PREPROCESSOR_DEFINITIONS' => 'GRPC_CFSTREAM=1' 192 } 193 ss.source_files = ${ruby_multiline_list(cfstream_private_files(filegroups), 22)} 194 ss.private_header_files = ${ruby_multiline_list(cfstream_private_headers(filegroups), 30)} 195 end 196 197 s.subspec 'Cronet-Interface' do |ss| 198 ss.header_mappings_dir = 'include/grpc' 199 ss.source_files = ${ruby_multiline_list(grpc_cronet_public_headers(libs), 22)} 200 end 201 202 s.subspec 'Cronet-Implementation' do |ss| 203 ss.header_mappings_dir = '.' 204 205 ss.dependency "#{s.name}/Interface", version 206 ss.dependency "#{s.name}/Implementation", version 207 ss.dependency "#{s.name}/Cronet-Interface", version 208 209 ss.source_files = ${ruby_multiline_list(grpc_cronet_files(libs), 22)} 210 end 211 212 s.subspec 'Tests' do |ss| 213 ss.header_mappings_dir = '.' 214 215 ss.dependency "#{s.name}/Interface", version 216 ss.dependency "#{s.name}/Implementation", version 217 218 ss.source_files = ${ruby_multiline_list(grpc_test_util_files(libs), 22)}, 219 ${ruby_multiline_list(end2end_tests_files(libs), 22)} 220 end 221 222 # TODO (mxyan): Instead of this hack, add include path "third_party" to C core's include path? 223 s.prepare_command = <<-END_OF_COMMAND 224 find src/core/ -type f ! -path '*.grpc_back' -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include "(pb(_.*)?\\.h)";#include <nanopb/\\1>;g' 225 find src/core/ -type f -path '*.grpc_back' -print0 | xargs -0 rm 226 END_OF_COMMAND 227 end 228