• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#
16# This is for the gRPC build system. This isn't intended to be used outsite of
17# the BUILD file for gRPC. It contains the mapping for the template system we
18# use to generate other platform's build system files.
19#
20# Please consider that there should be a high bar for additions and changes to
21# this file.
22# Each rule listed must be re-written for Google's internal build system, and
23# each change must be ported from one to the other.
24#
25
26load("@rules_proto//proto:defs.bzl", "proto_library")
27load(
28    "//bazel:generate_objc.bzl",
29    "generate_objc",
30    "generate_objc_hdrs",
31    "generate_objc_non_arc_srcs",
32    "generate_objc_srcs",
33)
34
35def proto_library_objc_wrapper(
36        name,
37        srcs,
38        deps = [],
39        use_well_known_protos = False):
40    """proto_library for adding dependencies to google/protobuf protos
41    use_well_known_protos - ignored in open source version
42    """
43    proto_library(
44        name = name,
45        srcs = srcs,
46        deps = deps,
47    )
48
49def grpc_objc_examples_library(
50        name,
51        srcs = [],
52        hdrs = [],
53        textual_hdrs = [],
54        data = [],
55        deps = [],
56        defines = [],
57        sdk_frameworks = [],
58        includes = []):
59    """objc_library for testing, only works in //src/objective-c/exmaples
60
61    Args:
62        name: name of target
63        hdrs: public headers
64        srcs: all source files (.m)
65        textual_hdrs: private headers
66        data: any other bundle resources
67        defines: preprocessors
68        sdk_frameworks: sdks
69        includes: added to search path, always [the path to objc directory]
70        deps: dependencies
71    """
72    native.objc_library(
73        name = name,
74        srcs = srcs,
75        hdrs = hdrs,
76        textual_hdrs = textual_hdrs,
77        data = data,
78        defines = defines,
79        includes = includes,
80        sdk_frameworks = sdk_frameworks,
81        deps = deps + [":RemoteTest"],
82    )
83
84def grpc_objc_testing_library(
85        name,
86        srcs = [],
87        hdrs = [],
88        textual_hdrs = [],
89        data = [],
90        deps = [],
91        defines = [],
92        includes = []):
93    """objc_library for testing, only works in //src/objective-c/tests
94
95    Args:
96        name: name of target
97        hdrs: public headers
98        srcs: all source files (.m)
99        textual_hdrs: private headers
100        data: any other bundle resources
101        defines: preprocessors
102        includes: added to search path, always [the path to objc directory]
103        deps: dependencies
104    """
105
106    additional_deps = [
107        ":RemoteTest",
108        "//src/objective-c:grpc_objc_client_internal_testing",
109    ]
110
111    if not name == "TestConfigs":
112        additional_deps += [":TestConfigs"]
113
114    native.objc_library(
115        name = name,
116        hdrs = hdrs,
117        srcs = srcs,
118        textual_hdrs = textual_hdrs,
119        data = data,
120        defines = defines,
121        includes = includes,
122        deps = deps + additional_deps,
123    )
124
125def local_objc_grpc_library(name, deps, testing = True, srcs = [], use_well_known_protos = False, **kwargs):
126    """!!For local targets within the gRPC repository only!! Will not work outside of the repo
127    """
128    objc_grpc_library_name = "_" + name + "_objc_grpc_library"
129
130    generate_objc(
131        name = objc_grpc_library_name,
132        srcs = srcs,
133        deps = deps,
134        use_well_known_protos = use_well_known_protos,
135        **kwargs
136    )
137
138    generate_objc_hdrs(
139        name = objc_grpc_library_name + "_hdrs",
140        src = ":" + objc_grpc_library_name,
141    )
142
143    generate_objc_non_arc_srcs(
144        name = objc_grpc_library_name + "_non_arc_srcs",
145        src = ":" + objc_grpc_library_name,
146    )
147
148    arc_srcs = None
149    if len(srcs) > 0:
150        generate_objc_srcs(
151            name = objc_grpc_library_name + "_srcs",
152            src = ":" + objc_grpc_library_name,
153        )
154        arc_srcs = [":" + objc_grpc_library_name + "_srcs"]
155
156    library_deps = ["@com_google_protobuf//:protobuf_objc"]
157    if testing:
158        library_deps += ["//src/objective-c:grpc_objc_client_internal_testing"]
159    else:
160        library_deps += ["//src/objective-c:proto_objc_rpc"]
161
162    native.objc_library(
163        name = name,
164        hdrs = [":" + objc_grpc_library_name + "_hdrs"],
165        non_arc_srcs = [":" + objc_grpc_library_name + "_non_arc_srcs"],
166        srcs = arc_srcs,
167        defines = [
168            "GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0",
169            "GPB_GRPC_FORWARD_DECLARE_MESSAGE_PROTO=0",
170        ],
171        includes = ["_generated_protos"],
172        deps = library_deps,
173    )
174