1# Copyright 2019 gRPC authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15""" 16This is for the gRPC build system. This isn't intended to be used outsite of 17the BUILD file for gRPC. It contains the mapping for the template system we 18use to generate other platform's build system files. 19 20Please consider that there should be a high bar for additions and changes to 21this file. 22Each rule listed must be re-written for Google's internal build system, and 23each change must be ported from one to the other. 24""" 25 26load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test") 27load( 28 "@build_bazel_rules_apple//apple/testing/default_runner:ios_test_runner.bzl", 29 "ios_test_runner", 30) 31load("@rules_proto//proto:defs.bzl", "proto_library") 32load( 33 "//bazel:generate_objc.bzl", 34 "generate_objc", 35 "generate_objc_hdrs", 36 "generate_objc_non_arc_srcs", 37 "generate_objc_srcs", 38) 39load("//bazel:grpc_build_system.bzl", "grpc_objc_library") 40 41# The default device type for ios objc unit tests 42IOS_UNIT_TEST_DEVICE_TYPE = "iPhone 11" 43 44# The default iOS version for ios objc unit tests 45# IOS_UNIT_TEST_OS_VERSION = "13.3" 46 47def grpc_objc_ios_unit_test( 48 name, 49 deps, 50 env = {}): 51 """ios unit test for running objc test suite on iOS simulator runner 52 53 Args: 54 name: The name of the unit test target. 55 deps: The dependencies of the target. 56 env: Optional test environment variables passed to the test 57 """ 58 test_runner = "grpc_ios_sim_runner_" + name 59 ios_test_runner( 60 name = test_runner, 61 device_type = IOS_UNIT_TEST_DEVICE_TYPE, 62 # os_version = IOS_UNIT_TEST_OS_VERSION, 63 test_environment = env, 64 ) 65 66 ios_unit_test( 67 name = name, 68 minimum_os_version = "9.0", 69 runner = test_runner, 70 deps = deps, 71 ) 72 73def proto_library_objc_wrapper( 74 name, 75 srcs, 76 deps = [], 77 use_well_known_protos = False): 78 """proto_library for adding dependencies to google/protobuf protos. 79 80 Args: 81 name: The name of the target. 82 srcs: The sources to include. 83 deps: The dependencies of the target. 84 use_well_known_protos: ignored in open source version. 85 """ 86 proto_library( 87 name = name, 88 srcs = srcs, 89 deps = deps, 90 ) 91 92def grpc_objc_examples_library( 93 name, 94 srcs = [], 95 hdrs = [], 96 textual_hdrs = [], 97 data = [], 98 deps = [], 99 defines = [], 100 sdk_frameworks = [], 101 includes = []): 102 """objc_library for testing, only works in //src/objective-c/exmaples 103 104 Args: 105 name: name of target 106 hdrs: public headers 107 srcs: all source files (.m) 108 textual_hdrs: private headers 109 data: any other bundle resources 110 defines: preprocessors 111 sdk_frameworks: sdks 112 includes: added to search path, always [the path to objc directory] 113 deps: dependencies 114 """ 115 grpc_objc_library( 116 name = name, 117 srcs = srcs, 118 hdrs = hdrs, 119 textual_hdrs = textual_hdrs, 120 data = data, 121 defines = defines, 122 includes = includes, 123 sdk_frameworks = sdk_frameworks, 124 deps = deps + [":RemoteTest"], 125 ) 126 127def grpc_objc_testing_library( 128 name, 129 srcs = [], 130 hdrs = [], 131 textual_hdrs = [], 132 data = [], 133 deps = [], 134 defines = [], 135 includes = []): 136 """objc_library for testing, only works in //src/objective-c/tests 137 138 Args: 139 name: name of target 140 hdrs: public headers 141 srcs: all source files (.m) 142 textual_hdrs: private headers 143 data: any other bundle resources 144 defines: preprocessors 145 includes: added to search path, always [the path to objc directory] 146 deps: dependencies 147 """ 148 149 additional_deps = [ 150 ":RemoteTest", 151 "//src/objective-c:grpc_objc_client_internal_testing", 152 ] 153 154 if not name == "TestConfigs": 155 additional_deps.append(":TestConfigs") 156 157 grpc_objc_library( 158 name = name, 159 hdrs = hdrs, 160 srcs = srcs, 161 textual_hdrs = textual_hdrs, 162 data = data, 163 defines = defines, 164 includes = includes, 165 deps = deps + additional_deps, 166 testonly = 1, 167 ) 168 169def local_objc_grpc_library(name, deps, testing = True, srcs = [], use_well_known_protos = False, **kwargs): 170 """objc_library for use within the repo. 171 172 For local targets within the gRPC repository only. Will not work outside of the repo. 173 174 Args: 175 name: The name of the library. 176 deps: The library dependencies. 177 testing: Whether or not to include testing dependencies. 178 srcs: The source files for the rule. 179 use_well_known_protos: Whether or not to include well known protos. 180 **kwargs: Other arguments to apply to the library. 181 """ 182 objc_grpc_library_name = "_" + name + "_objc_grpc_library" 183 184 generate_objc( 185 name = objc_grpc_library_name, 186 srcs = srcs, 187 deps = deps, 188 use_well_known_protos = use_well_known_protos, 189 **kwargs 190 ) 191 192 generate_objc_hdrs( 193 name = objc_grpc_library_name + "_hdrs", 194 src = ":" + objc_grpc_library_name, 195 ) 196 197 generate_objc_non_arc_srcs( 198 name = objc_grpc_library_name + "_non_arc_srcs", 199 src = ":" + objc_grpc_library_name, 200 ) 201 202 arc_srcs = None 203 if len(srcs) > 0: 204 generate_objc_srcs( 205 name = objc_grpc_library_name + "_srcs", 206 src = ":" + objc_grpc_library_name, 207 ) 208 arc_srcs = [":" + objc_grpc_library_name + "_srcs"] 209 210 library_deps = ["@com_google_protobuf//:protobuf_objc"] 211 if testing: 212 library_deps.append("//src/objective-c:grpc_objc_client_internal_testing") 213 else: 214 library_deps.append("//src/objective-c:proto_objc_rpc") 215 216 grpc_objc_library( 217 name = name, 218 hdrs = [":" + objc_grpc_library_name + "_hdrs"], 219 non_arc_srcs = [":" + objc_grpc_library_name + "_non_arc_srcs"], 220 srcs = arc_srcs, 221 defines = [ 222 "GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0", 223 "GPB_GRPC_FORWARD_DECLARE_MESSAGE_PROTO=0", 224 ], 225 includes = ["_generated_protos"], 226 deps = library_deps, 227 ) 228