blob: bff8988274405ef1f5cbe675972118f19141782c [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,
29 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,
Nicolas "Pixel" Noblee8dbd8a2016-10-20 18:54:36 +020036 hdrs = hdrs + public_hdrs,
37 deps = deps + ["//external:" + dep for dep in external_deps],
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020038 copts = copts,
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020039 visibility = visibility,
40 testonly = testonly,
Nicolas "Pixel" Noble60ca22f2016-10-20 10:23:53 +020041 linkopts = ["-pthread"],
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020042 includes = [
43 "include"
Ian Coolidge6b08cf42017-06-16 12:56:23 -070044 ],
45 alwayslink = alwayslink,
Nicolas "Pixel" Noble31d11db2016-10-20 09:29:46 +020046 )
Nicolas "Pixel" Noble4dc64312016-10-20 23:07:37 +020047
48def grpc_proto_plugin(name, srcs = [], deps = []):
49 native.cc_binary(
50 name = name,
51 srcs = srcs,
52 deps = deps,
53 )
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020054
55load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library")
56
Craig Tillera7533712017-05-16 13:09:33 -070057def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = False,
Mahak Mukhi443a75d2017-04-14 15:33:55 -070058 has_services = True, use_external = False, generate_mock = False):
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020059 cc_grpc_library(
60 name = name,
61 srcs = srcs,
62 deps = deps,
Makarand Dharmapurikare3e3b2a2017-03-07 16:12:56 -080063 well_known_protos = well_known_protos,
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020064 proto_only = not has_services,
Makarand Dharmapurikar9098fcc2017-03-02 17:13:10 -080065 use_external = use_external,
Mahak Mukhi443a75d2017-04-14 15:33:55 -070066 generate_mock = generate_mock,
Nicolas "Pixel" Noble799bd5e2016-10-21 01:54:32 +020067 )
68
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020069def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++"):
Craig Tillerf66de6e2017-05-15 08:29:10 -070070 copts = []
71 if language.upper() == "C":
72 copts = ["-std=c99"]
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +020073 native.cc_test(
74 name = name,
75 srcs = srcs,
76 args = args,
77 data = data,
78 deps = deps + ["//external:" + dep for dep in external_deps],
Craig Tillerf66de6e2017-05-15 08:29:10 -070079 copts = copts,
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +020080 linkopts = ["-pthread"],
81 )
82
Vijay Pai42807252017-07-28 15:08:24 -070083def 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 +020084 copts = []
85 if language.upper() == "C":
86 copts = ["-std=c99"]
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +020087 native.cc_binary(
88 name = name,
89 srcs = srcs,
90 args = args,
91 data = data,
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020092 testonly = testonly,
Nicolas "Pixel" Nobled69f7762017-05-12 17:10:13 +020093 linkshared = linkshared,
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +020094 deps = deps + ["//external:" + dep for dep in external_deps],
Nicolas "Pixel" Noble15cd5ce2017-04-18 06:32:11 +020095 copts = copts,
Vijay Pai42807252017-07-28 15:08:24 -070096 linkopts = ["-pthread"] + linkopts,
Nicolas "Pixel" Noble7c26eed2017-04-13 01:40:54 +020097 )
Nicolas "Pixel" Noble2b0f0012017-04-24 19:59:19 +020098
99def grpc_generate_one_off_targets():
Nicolas "Pixel" Noble3dedf652017-05-24 02:29:02 +0200100 pass
Nicolas "Pixel" Noble3bd81772017-04-25 22:23:40 +0200101
102def grpc_sh_test(name, srcs, args = [], data = []):
Nicolas "Pixel" Noble3dedf652017-05-24 02:29:02 +0200103 native.sh_test(
104 name = name,
105 srcs = srcs,
106 args = args,
107 data = data)
Nicolas "Pixel" Noble2bc5e3a2017-08-15 22:32:52 +0200108
109def grpc_package(name, visibility = "private"):
110 if visibility == "tests":
111 visibility = ["//test:__subpackages__"]
112 elif visibility == "public":
113 visibility = ["//visibility:public"]
114 elif visibility == "private":
115 visibility = []
116 else:
117 fail("Unknown visibility " + visibility)
118
119 if len(visibility) != 0:
120 native.package(
121 default_visibility = visibility
122 )