1# Copyright (c) 2009-2021, Google LLC
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are met:
6#     * Redistributions of source code must retain the above copyright
7#       notice, this list of conditions and the following disclaimer.
8#     * Redistributions in binary form must reproduce the above copyright
9#       notice, this list of conditions and the following disclaimer in the
10#       documentation and/or other materials provided with the distribution.
11#     * Neither the name of Google LLC nor the
12#       names of its contributors may be used to endorse or promote products
13#       derived from this software without specific prior written permission.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY
19# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26load(
27    "//bazel:build_defs.bzl",
28    "UPB_DEFAULT_COPTS",
29    "upb_amalgamation",  # copybara:strip_for_google3
30)
31load(
32    "//bazel:upb_proto_library.bzl",
33    "upb_fasttable_enabled",
34    "upb_proto_library",
35    "upb_proto_library_copts",
36    "upb_proto_reflection_library",
37)
38
39licenses(["notice"])
40
41exports_files([
42    "LICENSE",
43    "build_defs",
44])
45
46config_setting(
47    name = "windows",
48    constraint_values = ["@bazel_tools//platforms:windows"],
49)
50
51upb_fasttable_enabled(
52    name = "fasttable_enabled",
53    build_setting_default = False,
54    visibility = ["//visibility:public"],
55)
56
57config_setting(
58    name = "fasttable_enabled_setting",
59    flag_values = {"//:fasttable_enabled": "true"},
60)
61
62upb_proto_library_copts(
63    name = "upb_proto_library_copts__for_generated_code_only_do_not_use",
64    copts = UPB_DEFAULT_COPTS,
65    visibility = ["//visibility:public"],
66)
67
68# Public C/C++ libraries #######################################################
69
70cc_library(
71    name = "port",
72    copts = UPB_DEFAULT_COPTS,
73    textual_hdrs = [
74        "upb/port_def.inc",
75        "upb/port_undef.inc",
76    ],
77    visibility = ["//tests:__pkg__"],
78)
79
80cc_library(
81    name = "upb",
82    srcs = [
83        "upb/decode.c",
84        "upb/decode_internal.h",
85        "upb/encode.c",
86        "upb/msg.c",
87        "upb/msg_internal.h",
88        "upb/table.c",
89        "upb/table_internal.h",
90        "upb/upb.c",
91        "upb/upb_internal.h",
92    ],
93    hdrs = [
94        "upb/decode.h",
95        "upb/encode.h",
96        "upb/msg.h",
97        "upb/upb.h",
98        "upb/upb.hpp",
99    ],
100    copts = UPB_DEFAULT_COPTS,
101    visibility = ["//visibility:public"],
102    deps = [
103        ":fastdecode",
104        ":port",
105    ],
106)
107
108cc_library(
109    name = "fastdecode",
110    srcs = [
111        "upb/decode_internal.h",
112        "upb/decode_fast.c",
113        "upb/decode_fast.h",
114        "upb/msg.h",
115        "upb/msg_internal.h",
116        "upb/upb_internal.h",
117    ],
118    copts = UPB_DEFAULT_COPTS,
119    deps = [
120        ":port",
121        ":table",
122    ],
123)
124
125# Common support routines used by generated code.  This library has no
126# implementation, but depends on :upb and exposes a few more hdrs.
127#
128# This is public only because we have no way of visibility-limiting it to
129# upb_proto_library() only.  This interface is not stable and by using it you
130# give up any backward compatibility guarantees.
131cc_library(
132    name = "generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
133    hdrs = [
134        "upb/decode_fast.h",
135        "upb/msg.h",
136        "upb/msg_internal.h",
137        "upb/port_def.inc",
138        "upb/port_undef.inc",
139    ],
140    copts = UPB_DEFAULT_COPTS,
141    visibility = ["//visibility:public"],
142    deps = [
143        ":table",
144        ":upb",
145    ],
146)
147
148upb_proto_library(
149    name = "descriptor_upb_proto",
150    visibility = ["//visibility:public"],
151    deps = ["@com_google_protobuf//:descriptor_proto"],
152)
153
154upb_proto_reflection_library(
155    name = "descriptor_upb_proto_reflection",
156    visibility = ["//visibility:public"],
157    deps = ["@com_google_protobuf//:descriptor_proto"],
158)
159
160cc_library(
161    name = "reflection",
162    srcs = [
163        "upb/def.c",
164        "upb/msg.h",
165        "upb/reflection.c",
166    ],
167    hdrs = [
168        "upb/def.h",
169        "upb/def.hpp",
170        "upb/reflection.h",
171        "upb/reflection.hpp",
172    ],
173    copts = UPB_DEFAULT_COPTS,
174    visibility = ["//visibility:public"],
175    deps = [
176        ":descriptor_upb_proto",
177        ":port",
178        ":table",
179        ":upb",
180    ],
181)
182
183cc_library(
184    name = "textformat",
185    srcs = [
186        "upb/text_encode.c",
187    ],
188    hdrs = [
189        "upb/text_encode.h",
190    ],
191    copts = UPB_DEFAULT_COPTS,
192    visibility = ["//visibility:public"],
193    deps = [
194        ":port",
195        ":reflection",
196    ],
197)
198
199cc_library(
200    name = "json",
201    srcs = [
202        "upb/json_decode.c",
203        "upb/json_encode.c",
204    ],
205    hdrs = [
206        "upb/json_decode.h",
207        "upb/json_encode.h",
208    ],
209    copts = UPB_DEFAULT_COPTS,
210    visibility = ["//visibility:public"],
211    deps = [
212        ":port",
213        ":reflection",
214        ":upb",
215    ],
216)
217
218# Internal C/C++ libraries #####################################################
219
220cc_library(
221    name = "table",
222    hdrs = [
223        "upb/table_internal.h",
224        "upb/upb.h",
225    ],
226    visibility = ["//tests:__pkg__"],
227    deps = [
228        ":port",
229    ],
230)
231
232# Amalgamation #################################################################
233
234# copybara:strip_for_google3_begin
235
236py_binary(
237    name = "amalgamate",
238    srcs = ["tools/amalgamate.py"],
239)
240
241upb_amalgamation(
242    name = "gen_amalgamation",
243    outs = [
244        "upb.c",
245        "upb.h",
246    ],
247    amalgamator = ":amalgamate",
248    libs = [
249        ":upb",
250        ":fastdecode",
251        ":descriptor_upb_proto",
252        ":reflection",
253        ":port",
254    ],
255)
256
257cc_library(
258    name = "amalgamation",
259    srcs = ["upb.c"],
260    hdrs = ["upb.h"],
261    copts = UPB_DEFAULT_COPTS,
262)
263
264upb_amalgamation(
265    name = "gen_php_amalgamation",
266    outs = [
267        "php-upb.c",
268        "php-upb.h",
269    ],
270    amalgamator = ":amalgamate",
271    libs = [
272        ":upb",
273        ":fastdecode",
274        ":descriptor_upb_proto",
275        ":descriptor_upb_proto_reflection",
276        ":reflection",
277        ":port",
278        ":json",
279    ],
280    prefix = "php-",
281)
282
283cc_library(
284    name = "php_amalgamation",
285    srcs = ["php-upb.c"],
286    hdrs = ["php-upb.h"],
287    copts = UPB_DEFAULT_COPTS,
288)
289
290upb_amalgamation(
291    name = "gen_ruby_amalgamation",
292    outs = [
293        "ruby-upb.c",
294        "ruby-upb.h",
295    ],
296    amalgamator = ":amalgamate",
297    libs = [
298        ":upb",
299        ":fastdecode",
300        ":descriptor_upb_proto",
301        ":reflection",
302        ":port",
303        ":json",
304    ],
305    prefix = "ruby-",
306)
307
308cc_library(
309    name = "ruby_amalgamation",
310    srcs = ["ruby-upb.c"],
311    hdrs = ["ruby-upb.h"],
312    copts = UPB_DEFAULT_COPTS,
313)
314
315exports_files(
316    [
317        "upb/json/parser.rl",
318        "BUILD",
319        "WORKSPACE",
320    ],
321    visibility = ["//cmake:__pkg__"],
322)
323
324exports_files(
325    [
326        "third_party/lunit/console.lua",
327        "third_party/lunit/lunit.lua",
328    ],
329    visibility = ["//tests/bindings/lua:__pkg__"],
330)
331
332filegroup(
333    name = "cmake_files",
334    srcs = glob([
335        "google/**/*",
336        "upbc/**/*",
337        "upb/**/*",
338        "tests/**/*",
339        "third_party/**/*",
340    ]),
341    visibility = ["//cmake:__pkg__"],
342)
343
344# copybara:strip_end
345