blob: a6da377248159868e6f88827a4a7b14154f1b6db [file] [log] [blame]
Jan Tattermusch4d5c3102017-06-07 10:23:56 +02001# Copyright 2016 gRPC authors.
Craig Tiller423ecff2016-10-20 09:45:09 -07002#
Jan Tattermusch4d5c3102017-06-07 10:23:56 +02003# 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
Craig Tiller423ecff2016-10-20 09:45:09 -07006#
Jan Tattermusch4d5c3102017-06-07 10:23:56 +02007# http://www.apache.org/licenses/LICENSE-2.0
Craig Tiller423ecff2016-10-20 09:45:09 -07008#
Jan Tattermusch4d5c3102017-06-07 10:23:56 +02009# 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.
Craig Tiller423ecff2016-10-20 09:45:09 -070014
Nicolas "Pixel" Noblee8dbd8a2016-10-20 18:54:36 +020015#
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#
Craig Tillerf66de6e2017-05-15 08:29:10 -070020# 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#
Nicolas "Pixel" Noblee8dbd8a2016-10-20 18:54:36 +020025
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020026def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [],
27 external_deps = [], deps = [], standalone = False,
Ian Coolidge6b08cf42017-06-16 12:56:23 -070028 language = "C++", testonly = False, visibility = None,
Adele Zhoue5df91f2017-11-29 14:37:18 -080029 alwayslink = 0):
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020030 copts = []
Craig Tiller674c66c2016-10-20 13:08:52 -070031 if language.upper() == "C":
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020032 copts = ["-std=c99"]
33 native.cc_library(
34 name = name,
35 srcs = srcs,
Adele Zhoue5df91f2017-11-29 14:37:18 -080036 defines = select({"//:grpc_no_ares": ["GRPC_ARES=0"],
37 "//conditions:default": [],}) +
38 select({"//:remote_execution": ["GRPC_HERMETIC_TESTS=1"],
39 "//conditions:default": [],}),
Nicolas "Pixel" Noblee8dbd8a2016-10-20 18:54:36 +020040 hdrs = hdrs + public_hdrs,
41 deps = deps + ["//external:" + dep for dep in external_deps],
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020042 copts = copts,
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020043 visibility = visibility,
44 testonly = testonly,
Nicolas "Pixel" Noble60ca22f2016-10-20 10:23:53 +020045 linkopts = ["-pthread"],
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020046 includes = [
47 "include"
Ian Coolidge6b08cf42017-06-16 12:56:23 -070048 ],
49 alwayslink = alwayslink,
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020050 )
Nicolas "Pixel" Noble4dc64312016-10-20 23:07:37 +020051
Vijay Pai4fdb08a2017-11-14 16:48:45 -080052def grpc_proto_plugin(name, srcs = [], deps = []):
Nicolas "Pixel" Noble4dc64312016-10-20 23:07:37 +020053 native.cc_binary(
54 name = name,
Vijay Pai4fdb08a2017-11-14 16:48:45 -080055 srcs = srcs,
Nicolas "Pixel" Noble4dc64312016-10-20 23:07:37 +020056 deps = deps,
57 )
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020058
59load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library")
60
Craig Tillera7533712017-05-16 13:09:33 -070061def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = False,
Mahak Mukhi443a75d2017-04-14 15:33:55 -070062 has_services = True, use_external = False, generate_mock = False):
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020063 cc_grpc_library(
64 name = name,
65 srcs = srcs,
66 deps = deps,
Makarand Dharmapurikare3e3b2a2017-03-07 16:12:56 -080067 well_known_protos = well_known_protos,
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020068 proto_only = not has_services,
Makarand Dharmapurikar9098fcc2017-03-02 17:13:10 -080069 use_external = use_external,
Mahak Mukhi443a75d2017-04-14 15:33:55 -070070 generate_mock = generate_mock,
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020071 )
72
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020073def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++"):
Craig Tillerf66de6e2017-05-15 08:29:10 -070074 copts = []
75 if language.upper() == "C":
76 copts = ["-std=c99"]
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +020077 native.cc_test(
78 name = name,
79 srcs = srcs,
80 args = args,
81 data = data,
82 deps = deps + ["//external:" + dep for dep in external_deps],
Craig Tillerf66de6e2017-05-15 08:29:10 -070083 copts = copts,
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +020084 linkopts = ["-pthread"],
85 )
86
Vijay Pai42807252017-07-28 15:08:24 -070087def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++", testonly = False, linkshared = False, linkopts = []):
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020088 copts = []
89 if language.upper() == "C":
90 copts = ["-std=c99"]
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +020091 native.cc_binary(
92 name = name,
93 srcs = srcs,
94 args = args,
95 data = data,
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020096 testonly = testonly,
Nicolas "Pixel" Nobled69f7762017-05-12 17:10:13 +020097 linkshared = linkshared,
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +020098 deps = deps + ["//external:" + dep for dep in external_deps],
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020099 copts = copts,
Vijay Pai42807252017-07-28 15:08:24 -0700100 linkopts = ["-pthread"] + linkopts,
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +0200101 )
Nicolas "Pixel" Noble2b0f0012017-04-24 19:59:19 +0200102
103def grpc_generate_one_off_targets():
Nicolas "Pixel" Noble3dedf652017-05-24 02:29:02 +0200104 pass
Nicolas "Pixel" Noble3bd81772017-04-25 22:23:40 +0200105
106def grpc_sh_test(name, srcs, args = [], data = []):
Nicolas "Pixel" Noble3dedf652017-05-24 02:29:02 +0200107 native.sh_test(
108 name = name,
109 srcs = srcs,
110 args = args,
111 data = data)
Nicolas "Pixel" Noble2bc5e3a2017-08-15 22:32:52 +0200112
Alexander Polcyn27bf05d2017-08-07 18:09:11 -0700113def grpc_sh_binary(name, srcs, data = []):
114 native.sh_test(
115 name = name,
116 srcs = srcs,
117 data = data)
118
119def grpc_py_binary(name, srcs, data = [], deps = []):
120 if name == "test_dns_server":
121 # TODO: allow running test_dns_server in oss bazel test suite
122 deps = []
123 native.py_binary(
124 name = name,
125 srcs = srcs,
126 data = data,
127 deps = deps)
128
yang-g109040f2017-08-30 21:33:31 -0700129def grpc_package(name, visibility = "private", features = []):
Nicolas "Pixel" Noble2bc5e3a2017-08-15 22:32:52 +0200130 if visibility == "tests":
131 visibility = ["//test:__subpackages__"]
132 elif visibility == "public":
133 visibility = ["//visibility:public"]
134 elif visibility == "private":
135 visibility = []
136 else:
137 fail("Unknown visibility " + visibility)
138
139 if len(visibility) != 0:
140 native.package(
yang-g109040f2017-08-30 21:33:31 -0700141 default_visibility = visibility,
142 features = features
Nicolas "Pixel" Noble2bc5e3a2017-08-15 22:32:52 +0200143 )