2e133263a7cbd6d90810c873aa01235baf367bbd
[platform/upstream/grpc.git] / third_party / upb / BUILD
1 load(
2     "//bazel:build_defs.bzl",
3     "UPB_DEFAULT_COPTS",
4     "upb_amalgamation",  # copybara:strip_for_google3
5 )
6 load(
7     "//bazel:upb_proto_library.bzl",
8     "upb_fasttable_enabled",
9     "upb_proto_library",
10     "upb_proto_library_copts",
11     "upb_proto_reflection_library",
12 )
13
14 # copybara:strip_for_google3_begin
15 load(
16     "@rules_proto//proto:defs.bzl",
17     "proto_library",
18 )
19
20 # copybara:strip_end
21
22 licenses(["notice"])  # BSD (Google-authored w/ possible external contributions)
23
24 exports_files([
25     "LICENSE",
26     "build_defs",
27 ])
28
29 config_setting(
30     name = "windows",
31     constraint_values = ["@bazel_tools//platforms:windows"],
32 )
33
34 upb_fasttable_enabled(
35     name = "fasttable_enabled",
36     build_setting_default = False,
37     visibility = ["//visibility:public"],
38 )
39
40 config_setting(
41     name = "fasttable_enabled_setting",
42     flag_values = {"//:fasttable_enabled": "true"},
43 )
44
45 upb_proto_library_copts(
46     name = "upb_proto_library_copts__for_generated_code_only_do_not_use",
47     copts = UPB_DEFAULT_COPTS,
48     visibility = ["//visibility:public"],
49 )
50
51 # Public C/C++ libraries #######################################################
52
53 cc_library(
54     name = "port",
55     copts = UPB_DEFAULT_COPTS,
56     textual_hdrs = [
57         "upb/port_def.inc",
58         "upb/port_undef.inc",
59     ],
60     visibility = ["//tests:__pkg__"],
61 )
62
63 cc_library(
64     name = "upb",
65     srcs = [
66         "upb/decode.c",
67         "upb/decode.int.h",
68         "upb/encode.c",
69         "upb/msg.c",
70         "upb/msg.h",
71         "upb/table.c",
72         "upb/table.int.h",
73         "upb/upb.c",
74         "upb/upb.int.h",
75     ],
76     hdrs = [
77         "upb/decode.h",
78         "upb/encode.h",
79         "upb/upb.h",
80         "upb/upb.hpp",
81     ],
82     copts = UPB_DEFAULT_COPTS,
83     visibility = ["//visibility:public"],
84     deps = [
85         ":fastdecode",
86         ":port",
87         "//third_party/wyhash",
88     ],
89 )
90
91 cc_library(
92     name = "fastdecode",
93     srcs = [
94         "upb/decode.int.h",
95         "upb/decode_fast.c",
96         "upb/decode_fast.h",
97         "upb/msg.h",
98         "upb/upb.int.h",
99     ],
100     copts = UPB_DEFAULT_COPTS,
101     deps = [
102         ":port",
103         ":table",
104     ],
105 )
106
107 # Common support routines used by generated code.  This library has no
108 # implementation, but depends on :upb and exposes a few more hdrs.
109 #
110 # This is public only because we have no way of visibility-limiting it to
111 # upb_proto_library() only.  This interface is not stable and by using it you
112 # give up any backward compatibility guarantees.
113 cc_library(
114     name = "generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
115     hdrs = [
116         "upb/decode_fast.h",
117         "upb/msg.h",
118         "upb/port_def.inc",
119         "upb/port_undef.inc",
120     ],
121     copts = UPB_DEFAULT_COPTS,
122     visibility = ["//visibility:public"],
123     deps = [
124         ":table",
125         ":upb",
126     ],
127 )
128
129 upb_proto_library(
130     name = "descriptor_upb_proto",
131     visibility = ["//visibility:public"],
132     deps = ["@com_google_protobuf//:descriptor_proto"],
133 )
134
135 upb_proto_reflection_library(
136     name = "descriptor_upb_proto_reflection",
137     visibility = ["//visibility:public"],
138     deps = ["@com_google_protobuf//:descriptor_proto"],
139 )
140
141 cc_library(
142     name = "reflection",
143     srcs = [
144         "upb/def.c",
145         "upb/msg.h",
146         "upb/reflection.c",
147     ],
148     hdrs = [
149         "upb/def.h",
150         "upb/def.hpp",
151         "upb/reflection.h",
152     ],
153     copts = UPB_DEFAULT_COPTS,
154     visibility = ["//visibility:public"],
155     deps = [
156         ":descriptor_upb_proto",
157         ":port",
158         ":table",
159         ":upb",
160     ],
161 )
162
163 cc_library(
164     name = "textformat",
165     srcs = [
166         "upb/text_encode.c",
167     ],
168     hdrs = [
169         "upb/text_encode.h",
170     ],
171     copts = UPB_DEFAULT_COPTS,
172     visibility = ["//visibility:public"],
173     deps = [
174         ":port",
175         ":reflection",
176     ],
177 )
178
179 cc_library(
180     name = "json",
181     srcs = [
182         "upb/json_decode.c",
183         "upb/json_encode.c",
184     ],
185     hdrs = [
186         "upb/json_decode.h",
187         "upb/json_encode.h",
188     ],
189     copts = UPB_DEFAULT_COPTS,
190     visibility = ["//visibility:public"],
191     deps = [
192         ":port",
193         ":reflection",
194         ":upb",
195     ],
196 )
197
198 # Internal C/C++ libraries #####################################################
199
200 cc_library(
201     name = "table",
202     hdrs = [
203         "upb/table.int.h",
204         "upb/upb.h",
205     ],
206     visibility = ["//tests:__pkg__"],
207     deps = [
208         ":port",
209     ],
210 )
211
212 # Legacy C/C++ Libraries (not recommended for new code) ########################
213
214 cc_library(
215     name = "handlers",
216     srcs = [
217         "upb/handlers.c",
218         "upb/handlers-inl.h",
219         "upb/sink.c",
220     ],
221     hdrs = [
222         "upb/handlers.h",
223         "upb/sink.h",
224     ],
225     copts = UPB_DEFAULT_COPTS,
226     visibility = ["//tests:__pkg__"],
227     deps = [
228         ":port",
229         ":reflection",
230         ":table",
231         ":upb",
232     ],
233 )
234
235 cc_library(
236     name = "upb_pb",
237     srcs = [
238         "upb/pb/compile_decoder.c",
239         "upb/pb/decoder.c",
240         "upb/pb/decoder.int.h",
241         "upb/pb/encoder.c",
242         "upb/pb/textprinter.c",
243         "upb/pb/varint.c",
244         "upb/pb/varint.int.h",
245     ],
246     hdrs = [
247         "upb/pb/decoder.h",
248         "upb/pb/encoder.h",
249         "upb/pb/textprinter.h",
250     ],
251     copts = UPB_DEFAULT_COPTS,
252     visibility = ["//tests:__pkg__"],
253     deps = [
254         ":descriptor_upb_proto",
255         ":handlers",
256         ":port",
257         ":reflection",
258         ":table",
259         ":upb",
260     ],
261 )
262
263 # copybara:strip_for_google3_begin
264 cc_library(
265     name = "upb_json",
266     srcs = [
267         "upb/json/parser.c",
268         "upb/json/printer.c",
269     ],
270     hdrs = [
271         "upb/json/parser.h",
272         "upb/json/printer.h",
273     ],
274     copts = UPB_DEFAULT_COPTS,
275     visibility = ["//tests:__pkg__"],
276     deps = [
277         ":upb",
278         ":upb_pb",
279     ],
280 )
281
282 genrule(
283     name = "generate_json_ragel",
284     srcs = ["//:upb/json/parser.rl"],
285     outs = ["upb/json/parser.c"],
286     cmd = "$(location @ragel//:ragelc) -C -o upb/json/parser.c $< && mv upb/json/parser.c $@",
287     tools = ["@ragel//:ragelc"],
288     visibility = ["//cmake:__pkg__"],
289 )
290
291 # Amalgamation #################################################################
292
293 py_binary(
294     name = "amalgamate",
295     srcs = ["tools/amalgamate.py"],
296 )
297
298 upb_amalgamation(
299     name = "gen_amalgamation",
300     outs = [
301         "upb.c",
302         "upb.h",
303     ],
304     amalgamator = ":amalgamate",
305     libs = [
306         ":upb",
307         ":fastdecode",
308         ":descriptor_upb_proto",
309         ":reflection",
310         ":handlers",
311         ":port",
312         ":upb_pb",
313         ":upb_json",
314     ],
315 )
316
317 cc_library(
318     name = "amalgamation",
319     srcs = ["upb.c"],
320     hdrs = ["upb.h"],
321     copts = UPB_DEFAULT_COPTS,
322     deps = ["//third_party/wyhash"],
323 )
324
325 upb_amalgamation(
326     name = "gen_php_amalgamation",
327     outs = [
328         "php-upb.c",
329         "php-upb.h",
330     ],
331     amalgamator = ":amalgamate",
332     libs = [
333         ":upb",
334         ":fastdecode",
335         ":descriptor_upb_proto",
336         ":descriptor_upb_proto_reflection",
337         ":reflection",
338         ":port",
339         ":json",
340     ],
341     prefix = "php-",
342 )
343
344 cc_library(
345     name = "php_amalgamation",
346     srcs = ["php-upb.c"],
347     hdrs = ["php-upb.h"],
348     copts = UPB_DEFAULT_COPTS,
349     deps = ["//third_party/wyhash"],
350 )
351
352 upb_amalgamation(
353     name = "gen_ruby_amalgamation",
354     outs = [
355         "ruby-upb.c",
356         "ruby-upb.h",
357     ],
358     amalgamator = ":amalgamate",
359     libs = [
360         ":upb",
361         ":fastdecode",
362         ":descriptor_upb_proto",
363         ":reflection",
364         ":port",
365         ":json",
366     ],
367     prefix = "ruby-",
368 )
369
370 cc_library(
371     name = "ruby_amalgamation",
372     srcs = ["ruby-upb.c"],
373     hdrs = ["ruby-upb.h"],
374     copts = UPB_DEFAULT_COPTS,
375     deps = ["//third_party/wyhash"],
376 )
377
378 exports_files(
379     [
380         "upb/json/parser.rl",
381         "BUILD",
382         "WORKSPACE",
383     ],
384     visibility = ["//cmake:__pkg__"],
385 )
386
387 exports_files(
388     [
389         "third_party/lunit/console.lua",
390         "third_party/lunit/lunit.lua",
391     ],
392     visibility = ["//tests/bindings/lua:__pkg__"],
393 )
394
395 filegroup(
396     name = "cmake_files",
397     srcs = glob([
398         "upb/json/parser.c",
399         "CMakeLists.txt",
400         "generated_for_cmake/**/*",
401         "google/**/*",
402         "upbc/**/*",
403         "upb/**/*",
404         "tests/**/*",
405         "third_party/**/*",
406     ]),
407     visibility = ["//cmake:__pkg__"],
408 )
409
410 # copybara:strip_end