BUILD 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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. load(
  26. "//bazel:build_defs.bzl",
  27. "UPB_DEFAULT_COPTS",
  28. "UPB_DEFAULT_CPPOPTS",
  29. "make_shell_script",
  30. "upb_amalgamation", # copybara:strip_for_google3
  31. )
  32. load(
  33. "//bazel:upb_proto_library.bzl",
  34. "upb_fasttable_enabled",
  35. "upb_proto_library",
  36. "upb_proto_library_copts",
  37. "upb_proto_reflection_library",
  38. )
  39. licenses(["notice"])
  40. exports_files([
  41. "LICENSE",
  42. "build_defs",
  43. ])
  44. config_setting(
  45. name = "windows",
  46. constraint_values = ["@bazel_tools//platforms:windows"],
  47. visibility = ["//visibility:public"],
  48. )
  49. upb_fasttable_enabled(
  50. name = "fasttable_enabled",
  51. build_setting_default = False,
  52. visibility = ["//visibility:public"],
  53. )
  54. config_setting(
  55. name = "fasttable_enabled_setting",
  56. flag_values = {"//:fasttable_enabled": "true"},
  57. )
  58. upb_proto_library_copts(
  59. name = "upb_proto_library_copts__for_generated_code_only_do_not_use",
  60. copts = UPB_DEFAULT_COPTS,
  61. visibility = ["//visibility:public"],
  62. )
  63. # Public C/C++ libraries #######################################################
  64. cc_library(
  65. name = "port",
  66. copts = UPB_DEFAULT_COPTS,
  67. textual_hdrs = [
  68. "upb/port_def.inc",
  69. "upb/port_undef.inc",
  70. ],
  71. visibility = ["//tests:__pkg__"],
  72. )
  73. cc_library(
  74. name = "upb",
  75. srcs = [
  76. "upb/decode.c",
  77. "upb/decode_internal.h",
  78. "upb/encode.c",
  79. "upb/msg.c",
  80. "upb/msg_internal.h",
  81. "upb/table.c",
  82. "upb/table_internal.h",
  83. "upb/upb.c",
  84. "upb/upb_internal.h",
  85. ],
  86. hdrs = [
  87. "upb/decode.h",
  88. "upb/encode.h",
  89. "upb/msg.h",
  90. "upb/upb.h",
  91. "upb/upb.hpp",
  92. ],
  93. copts = UPB_DEFAULT_COPTS,
  94. visibility = ["//visibility:public"],
  95. deps = [
  96. ":fastdecode",
  97. ":port",
  98. "//third_party/utf8_range",
  99. ],
  100. )
  101. cc_library(
  102. name = "fastdecode",
  103. srcs = [
  104. "upb/decode.h",
  105. "upb/decode_internal.h",
  106. "upb/decode_fast.c",
  107. "upb/decode_fast.h",
  108. "upb/msg.h",
  109. "upb/msg_internal.h",
  110. "upb/upb_internal.h",
  111. ],
  112. copts = UPB_DEFAULT_COPTS,
  113. deps = [
  114. ":port",
  115. ":table",
  116. "//third_party/utf8_range",
  117. ],
  118. )
  119. # Common support routines used by generated code. This library has no
  120. # implementation, but depends on :upb and exposes a few more hdrs.
  121. #
  122. # This is public only because we have no way of visibility-limiting it to
  123. # upb_proto_library() only. This interface is not stable and by using it you
  124. # give up any backward compatibility guarantees.
  125. cc_library(
  126. name = "generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
  127. hdrs = [
  128. "upb/decode_fast.h",
  129. "upb/msg.h",
  130. "upb/msg_internal.h",
  131. "upb/port_def.inc",
  132. "upb/port_undef.inc",
  133. ],
  134. copts = UPB_DEFAULT_COPTS,
  135. visibility = ["//visibility:public"],
  136. deps = [
  137. ":table",
  138. ":upb",
  139. ],
  140. )
  141. upb_proto_library(
  142. name = "descriptor_upb_proto",
  143. visibility = ["//visibility:public"],
  144. deps = ["@com_google_protobuf//:descriptor_proto"],
  145. )
  146. upb_proto_reflection_library(
  147. name = "descriptor_upb_proto_reflection",
  148. visibility = ["//visibility:public"],
  149. deps = ["@com_google_protobuf//:descriptor_proto"],
  150. )
  151. cc_library(
  152. name = "reflection",
  153. srcs = [
  154. "upb/def.c",
  155. "upb/msg.h",
  156. "upb/reflection.c",
  157. ],
  158. hdrs = [
  159. "upb/def.h",
  160. "upb/def.hpp",
  161. "upb/reflection.h",
  162. "upb/reflection.hpp",
  163. ],
  164. copts = UPB_DEFAULT_COPTS,
  165. visibility = ["//visibility:public"],
  166. deps = [
  167. ":descriptor_upb_proto",
  168. ":port",
  169. ":table",
  170. ":upb",
  171. ],
  172. )
  173. cc_library(
  174. name = "textformat",
  175. srcs = [
  176. "upb/text_encode.c",
  177. ],
  178. hdrs = [
  179. "upb/text_encode.h",
  180. ],
  181. copts = UPB_DEFAULT_COPTS,
  182. visibility = ["//visibility:public"],
  183. deps = [
  184. ":port",
  185. ":reflection",
  186. ],
  187. )
  188. cc_library(
  189. name = "json",
  190. srcs = [
  191. "upb/json_decode.c",
  192. "upb/json_encode.c",
  193. ],
  194. hdrs = [
  195. "upb/json_decode.h",
  196. "upb/json_encode.h",
  197. ],
  198. copts = UPB_DEFAULT_COPTS,
  199. visibility = ["//visibility:public"],
  200. deps = [
  201. ":port",
  202. ":reflection",
  203. ":upb",
  204. ],
  205. )
  206. # Tests ########################################################################
  207. cc_test(
  208. name = "test_generated_code",
  209. srcs = ["upb/test_generated_code.cc"],
  210. deps = [
  211. ":empty_upbdefs_proto",
  212. ":test_messages_proto3_proto_upb",
  213. ":test_upb_proto",
  214. "@com_google_googletest//:gtest_main",
  215. ],
  216. )
  217. proto_library(
  218. name = "test_proto",
  219. testonly = 1,
  220. srcs = ["upb/test.proto"],
  221. )
  222. upb_proto_library(
  223. name = "test_upb_proto",
  224. testonly = 1,
  225. deps = [":test_proto"],
  226. )
  227. proto_library(
  228. name = "empty_proto",
  229. srcs = ["upb/empty.proto"],
  230. )
  231. upb_proto_reflection_library(
  232. name = "empty_upbdefs_proto",
  233. testonly = 1,
  234. deps = [":empty_proto"],
  235. )
  236. upb_proto_library(
  237. name = "test_messages_proto3_proto_upb",
  238. testonly = 1,
  239. deps = ["@com_google_protobuf//:test_messages_proto3_proto"],
  240. )
  241. cc_test(
  242. name = "msg_test",
  243. srcs = ["upb/msg_test.cc"],
  244. deps = [
  245. "@com_google_googletest//:gtest_main",
  246. ":msg_test_upb_proto_reflection",
  247. ":json",
  248. ],
  249. )
  250. proto_library(
  251. name = "msg_test_proto",
  252. srcs = ["upb/msg_test.proto"],
  253. deps = ["@com_google_protobuf//:test_messages_proto3_proto"],
  254. )
  255. upb_proto_reflection_library(
  256. name = "msg_test_upb_proto_reflection",
  257. deps = [":msg_test_proto"],
  258. )
  259. proto_library(
  260. name = "test_cpp_proto",
  261. srcs = ["upb/test_cpp.proto"],
  262. deps = ["@com_google_protobuf//:timestamp_proto"]
  263. )
  264. upb_proto_library(
  265. name = "test_cpp_upb_proto",
  266. deps = ["test_cpp_proto"],
  267. )
  268. upb_proto_reflection_library(
  269. name = "test_cpp_upb_proto_reflection",
  270. deps = ["test_cpp_proto"],
  271. )
  272. cc_test(
  273. name = "test_cpp",
  274. srcs = ["upb/test_cpp.cc"],
  275. copts = UPB_DEFAULT_CPPOPTS,
  276. deps = [
  277. ":test_cpp_upb_proto",
  278. ":test_cpp_upb_proto_reflection",
  279. "//:json",
  280. "//:port",
  281. "//:reflection",
  282. "//:upb",
  283. "@com_google_googletest//:gtest_main",
  284. ],
  285. )
  286. cc_test(
  287. name = "test_table",
  288. srcs = ["upb/test_table.cc"],
  289. copts = UPB_DEFAULT_CPPOPTS,
  290. deps = [
  291. "//:port",
  292. "//:table",
  293. "//:upb",
  294. "@com_google_googletest//:gtest_main",
  295. ],
  296. )
  297. upb_proto_library(
  298. name = "conformance_proto_upb",
  299. testonly = 1,
  300. deps = ["@com_google_protobuf//:conformance_proto"],
  301. )
  302. upb_proto_reflection_library(
  303. name = "conformance_proto_upbdefs",
  304. testonly = 1,
  305. deps = ["@com_google_protobuf//:conformance_proto"],
  306. )
  307. upb_proto_reflection_library(
  308. name = "test_messages_proto2_upbdefs",
  309. testonly = 1,
  310. deps = ["@com_google_protobuf//:test_messages_proto2_proto"],
  311. )
  312. upb_proto_reflection_library(
  313. name = "test_messages_proto3_upbdefs",
  314. testonly = 1,
  315. deps = ["@com_google_protobuf//:test_messages_proto3_proto"],
  316. )
  317. cc_binary(
  318. name = "conformance_upb",
  319. testonly = 1,
  320. srcs = ["upb/conformance_upb.c"],
  321. copts = UPB_DEFAULT_COPTS,
  322. data = ["upb/conformance_upb_failures.txt"],
  323. deps = [
  324. ":conformance_proto_upb",
  325. ":conformance_proto_upbdefs",
  326. ":test_messages_proto2_upbdefs",
  327. ":test_messages_proto3_upbdefs",
  328. "//:json",
  329. "//:port",
  330. "//:reflection",
  331. "//:textformat",
  332. "//:upb",
  333. ],
  334. )
  335. make_shell_script(
  336. name = "gen_test_conformance_upb",
  337. out = "test_conformance_upb.sh",
  338. contents = "external/com_google_protobuf/conformance_test_runner " +
  339. " --enforce_recommended " +
  340. " --failure_list ./upb/conformance_upb_failures.txt" +
  341. " ./conformance_upb",
  342. )
  343. sh_test(
  344. name = "test_conformance_upb",
  345. srcs = ["test_conformance_upb.sh"],
  346. data = [
  347. "upb/conformance_upb_failures.txt",
  348. ":conformance_upb",
  349. "@com_google_protobuf//:conformance_test_runner",
  350. ],
  351. deps = ["@bazel_tools//tools/bash/runfiles"],
  352. )
  353. # Internal C/C++ libraries #####################################################
  354. cc_library(
  355. name = "table",
  356. hdrs = [
  357. "upb/table_internal.h",
  358. "upb/upb.h",
  359. ],
  360. visibility = ["//tests:__pkg__"],
  361. deps = [
  362. ":port",
  363. ],
  364. )
  365. # Amalgamation #################################################################
  366. # copybara:strip_for_google3_begin
  367. upb_amalgamation(
  368. name = "gen_amalgamation",
  369. outs = [
  370. "upb.c",
  371. "upb.h",
  372. ],
  373. libs = [
  374. ":upb",
  375. ":fastdecode",
  376. ":descriptor_upb_proto",
  377. ":reflection",
  378. ":port",
  379. ],
  380. )
  381. cc_library(
  382. name = "amalgamation",
  383. srcs = ["upb.c"],
  384. hdrs = ["upb.h"],
  385. copts = UPB_DEFAULT_COPTS,
  386. deps = ["//third_party/utf8_range"],
  387. )
  388. upb_amalgamation(
  389. name = "gen_php_amalgamation",
  390. outs = [
  391. "php-upb.c",
  392. "php-upb.h",
  393. ],
  394. libs = [
  395. ":upb",
  396. ":fastdecode",
  397. ":descriptor_upb_proto",
  398. ":descriptor_upb_proto_reflection",
  399. ":reflection",
  400. ":port",
  401. ":json",
  402. ],
  403. prefix = "php-",
  404. )
  405. cc_library(
  406. name = "php_amalgamation",
  407. srcs = ["php-upb.c"],
  408. hdrs = ["php-upb.h"],
  409. copts = UPB_DEFAULT_COPTS,
  410. deps = ["//third_party/utf8_range"],
  411. )
  412. upb_amalgamation(
  413. name = "gen_ruby_amalgamation",
  414. outs = [
  415. "ruby-upb.c",
  416. "ruby-upb.h",
  417. ],
  418. libs = [
  419. ":upb",
  420. ":fastdecode",
  421. ":descriptor_upb_proto",
  422. ":reflection",
  423. ":port",
  424. ":json",
  425. ],
  426. prefix = "ruby-",
  427. )
  428. cc_library(
  429. name = "ruby_amalgamation",
  430. srcs = ["ruby-upb.c"],
  431. hdrs = ["ruby-upb.h"],
  432. copts = UPB_DEFAULT_COPTS,
  433. deps = ["//third_party/utf8_range"],
  434. )
  435. exports_files(
  436. [
  437. "upb/json/parser.rl",
  438. "BUILD",
  439. "WORKSPACE",
  440. ],
  441. visibility = ["//cmake:__pkg__"],
  442. )
  443. exports_files(
  444. [
  445. "third_party/lunit/console.lua",
  446. "third_party/lunit/lunit.lua",
  447. ],
  448. visibility = ["//upb/bindings/lua:__pkg__"],
  449. )
  450. filegroup(
  451. name = "cmake_files",
  452. srcs = glob([
  453. "google/**/*",
  454. "upbc/**/*",
  455. "upb/**/*",
  456. "tests/**/*",
  457. "third_party/**/*",
  458. ]),
  459. visibility = ["//cmake:__pkg__"],
  460. )
  461. # copybara:strip_end