BUILD 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. load("@rules_shell//shell:sh_test.bzl", "sh_test")
  5. load("//bazel/cc_rules:defs.bzl", "cc_binary", "cc_library", "cc_test")
  6. load("//bazel/version:rules.bzl", "expand_version_build_info")
  7. package(default_visibility = ["//visibility:public"])
  8. cc_library(
  9. name = "array_stack",
  10. hdrs = ["array_stack.h"],
  11. deps = [
  12. ":check",
  13. "@llvm-project//llvm:Support",
  14. ],
  15. )
  16. cc_test(
  17. name = "array_stack_test",
  18. size = "small",
  19. srcs = ["array_stack_test.cpp"],
  20. deps = [
  21. ":array_stack",
  22. "//testing/base:gtest_main",
  23. "@googletest//:gtest",
  24. ],
  25. )
  26. cc_library(
  27. name = "bazel_working_dir",
  28. hdrs = ["bazel_working_dir.h"],
  29. deps = [
  30. "@llvm-project//llvm:Support",
  31. ],
  32. )
  33. cc_library(
  34. name = "build_data",
  35. srcs = [
  36. "build_data.cpp",
  37. "build_data_linkstamp.h",
  38. ],
  39. hdrs = ["build_data.h"],
  40. linkstamp = "build_data_linkstamp.cpp",
  41. deps = ["@llvm-project//llvm:Support"],
  42. )
  43. cc_test(
  44. name = "build_data_test",
  45. size = "small",
  46. srcs = ["build_data_test.cpp"],
  47. deps = [
  48. ":build_data",
  49. ":ostream",
  50. "//testing/base:gtest_main",
  51. "@googletest//:gtest",
  52. ],
  53. )
  54. cc_library(
  55. name = "command_line",
  56. srcs = ["command_line.cpp"],
  57. hdrs = ["command_line.h"],
  58. deps = [
  59. ":check",
  60. ":error",
  61. ":ostream",
  62. ":raw_string_ostream",
  63. "@llvm-project//llvm:Support",
  64. ],
  65. )
  66. cc_test(
  67. name = "command_line_test",
  68. size = "small",
  69. srcs = ["command_line_test.cpp"],
  70. deps = [
  71. ":command_line",
  72. ":error_test_helpers",
  73. ":raw_string_ostream",
  74. "//testing/base:gtest_main",
  75. "@googletest//:gtest",
  76. "@llvm-project//llvm:Support",
  77. ],
  78. )
  79. cc_library(
  80. name = "check",
  81. srcs = [
  82. "check_internal.cpp",
  83. "check_internal.h",
  84. ],
  85. hdrs = ["check.h"],
  86. deps = [
  87. ":ostream",
  88. ":template_string",
  89. "@llvm-project//llvm:Support",
  90. ],
  91. )
  92. cc_test(
  93. name = "check_test",
  94. size = "small",
  95. srcs = ["check_test.cpp"],
  96. deps = [
  97. ":check",
  98. "//testing/base:gtest_main",
  99. "@googletest//:gtest",
  100. ],
  101. )
  102. cc_library(
  103. name = "enum_base",
  104. hdrs = ["enum_base.h"],
  105. deps = [
  106. "//common:ostream",
  107. "@llvm-project//llvm:Support",
  108. ],
  109. )
  110. cc_library(
  111. name = "enum_base_test_def",
  112. testonly = 1,
  113. textual_hdrs = ["enum_base_test.def"],
  114. )
  115. cc_test(
  116. name = "enum_base_test",
  117. size = "small",
  118. srcs = ["enum_base_test.cpp"],
  119. deps = [
  120. ":enum_base",
  121. ":enum_base_test_def",
  122. ":raw_string_ostream",
  123. "//testing/base:gtest_main",
  124. "@googletest//:gtest",
  125. ],
  126. )
  127. cc_library(
  128. name = "error",
  129. hdrs = ["error.h"],
  130. deps = [
  131. ":check",
  132. ":ostream",
  133. ":raw_string_ostream",
  134. "@llvm-project//llvm:Support",
  135. ],
  136. )
  137. cc_library(
  138. name = "error_test_helpers",
  139. testonly = 1,
  140. hdrs = ["error_test_helpers.h"],
  141. deps = [
  142. ":error",
  143. "@googletest//:gtest",
  144. ],
  145. )
  146. cc_test(
  147. name = "error_test",
  148. size = "small",
  149. srcs = ["error_test.cpp"],
  150. deps = [
  151. ":error",
  152. ":error_test_helpers",
  153. ":raw_string_ostream",
  154. "//testing/base:gtest_main",
  155. "@googletest//:gtest",
  156. ],
  157. )
  158. cc_library(
  159. name = "exe_path",
  160. srcs = ["exe_path.cpp"],
  161. hdrs = ["exe_path.h"],
  162. deps = [
  163. "@llvm-project//llvm:Support",
  164. ],
  165. )
  166. cc_test(
  167. name = "exe_path_test",
  168. size = "small",
  169. srcs = ["exe_path_test.cpp"],
  170. deps = [
  171. ":exe_path",
  172. "//testing/base:gtest_main",
  173. "@googletest//:gtest",
  174. "@llvm-project//llvm:Support",
  175. ],
  176. )
  177. cc_library(
  178. name = "find",
  179. hdrs = ["find.h"],
  180. deps = [
  181. ":check",
  182. ":ostream",
  183. ":raw_string_ostream",
  184. "@llvm-project//llvm:Support",
  185. ],
  186. )
  187. cc_test(
  188. name = "find_test",
  189. size = "small",
  190. srcs = ["find_test.cpp"],
  191. deps = [
  192. ":find",
  193. "//testing/base:gtest_main",
  194. "@googletest//:gtest",
  195. ],
  196. )
  197. cc_library(
  198. name = "hashing",
  199. srcs = ["hashing.cpp"],
  200. hdrs = ["hashing.h"],
  201. deps = [
  202. ":check",
  203. ":ostream",
  204. "@llvm-project//llvm:Support",
  205. ],
  206. )
  207. cc_test(
  208. name = "hashing_test",
  209. size = "small",
  210. srcs = ["hashing_test.cpp"],
  211. deps = [
  212. ":hashing",
  213. ":raw_string_ostream",
  214. "//testing/base:gtest_main",
  215. "@googletest//:gtest",
  216. "@llvm-project//llvm:Support",
  217. ],
  218. )
  219. cc_binary(
  220. name = "hashing_benchmark",
  221. testonly = 1,
  222. srcs = ["hashing_benchmark.cpp"],
  223. deps = [
  224. ":check",
  225. ":hashing",
  226. "//testing/base:benchmark_main",
  227. "@abseil-cpp//absl/hash",
  228. "@abseil-cpp//absl/random",
  229. "@google_benchmark//:benchmark",
  230. "@llvm-project//llvm:Support",
  231. ],
  232. )
  233. cc_library(
  234. name = "hashtable_key_context",
  235. hdrs = ["hashtable_key_context.h"],
  236. deps = [
  237. ":hashing",
  238. "@llvm-project//llvm:Support",
  239. ],
  240. )
  241. cc_test(
  242. name = "hashtable_key_context_test",
  243. size = "small",
  244. srcs = ["hashtable_key_context_test.cpp"],
  245. deps = [
  246. ":hashtable_key_context",
  247. "//testing/base:gtest_main",
  248. "@googletest//:gtest",
  249. "@llvm-project//llvm:Support",
  250. ],
  251. )
  252. cc_library(
  253. name = "init_llvm",
  254. srcs = ["init_llvm.cpp"],
  255. hdrs = ["init_llvm.h"],
  256. deps = [
  257. "@llvm-project//llvm:Support",
  258. ],
  259. )
  260. # Link against this to cause `:init_llvm` to pull in all LLVM targets.
  261. #
  262. # Be careful when depending on this: it pulls in several hundred megabytes of
  263. # LLVM binary size in -c fastbuild. This should only be depended on by a
  264. # `cc_binary` or `cc_test` target, never a `cc_library`.
  265. cc_library(
  266. name = "all_llvm_targets",
  267. srcs = ["all_llvm_targets.cpp"],
  268. deps = [
  269. ":init_llvm",
  270. "@llvm-project//llvm:AllTargetsAsmParsers",
  271. "@llvm-project//llvm:AllTargetsCodeGens",
  272. "@llvm-project//llvm:Support",
  273. ],
  274. alwayslink = 1,
  275. )
  276. cc_library(
  277. name = "map",
  278. hdrs = ["map.h"],
  279. deps = [
  280. ":check",
  281. ":hashtable_key_context",
  282. ":raw_hashtable",
  283. "@llvm-project//llvm:Support",
  284. ],
  285. )
  286. cc_test(
  287. name = "map_test",
  288. size = "small",
  289. srcs = ["map_test.cpp"],
  290. deps = [
  291. ":map",
  292. ":raw_hashtable_test_helpers",
  293. "//testing/base:gtest_main",
  294. "@googletest//:gtest",
  295. ],
  296. )
  297. cc_binary(
  298. name = "map_benchmark",
  299. testonly = 1,
  300. srcs = ["map_benchmark.cpp"],
  301. deps = [
  302. ":map",
  303. ":raw_hashtable_benchmark_helpers",
  304. "//testing/base:benchmark_main",
  305. "@abseil-cpp//absl/container:flat_hash_map",
  306. "@abseil-cpp//absl/random",
  307. "@boost_unordered",
  308. "@google_benchmark//:benchmark",
  309. "@llvm-project//llvm:Support",
  310. ],
  311. )
  312. sh_test(
  313. name = "map_benchmark_test",
  314. # The benchmark allocates a large amount of memory.
  315. size = "enormous",
  316. # We configure the test to run somewhat quickly.
  317. timeout = "moderate",
  318. srcs = [":map_benchmark"],
  319. args = [
  320. "--benchmark_min_time=1x",
  321. # The `$$` is repeated for Bazel escaping of `$`.
  322. "--benchmark_filter=^[^/]*/[1-9][0-9]{0,3}(/[0-9]+)?$$",
  323. ],
  324. )
  325. cc_library(
  326. name = "move_only",
  327. hdrs = ["move_only.h"],
  328. )
  329. cc_library(
  330. name = "ostream",
  331. hdrs = ["ostream.h"],
  332. deps = [
  333. "@llvm-project//llvm:Support",
  334. ],
  335. )
  336. cc_library(
  337. name = "raw_hashtable",
  338. srcs = ["raw_hashtable.cpp"],
  339. hdrs = ["raw_hashtable.h"],
  340. deps = [
  341. ":check",
  342. ":hashing",
  343. ":hashtable_key_context",
  344. ":raw_hashtable_metadata_group",
  345. "@llvm-project//llvm:Support",
  346. ],
  347. )
  348. cc_library(
  349. name = "raw_hashtable_metadata_group",
  350. srcs = ["raw_hashtable_metadata_group.cpp"],
  351. hdrs = ["raw_hashtable_metadata_group.h"],
  352. deps = [
  353. ":check",
  354. ":ostream",
  355. "@llvm-project//llvm:Support",
  356. ],
  357. )
  358. cc_binary(
  359. name = "raw_hashtable_metadata_group_benchmark",
  360. testonly = 1,
  361. srcs = ["raw_hashtable_metadata_group_benchmark.cpp"],
  362. deps = [
  363. ":raw_hashtable_metadata_group",
  364. "//testing/base:benchmark_main",
  365. "@abseil-cpp//absl/random",
  366. "@google_benchmark//:benchmark",
  367. "@llvm-project//llvm:Support",
  368. ],
  369. )
  370. sh_test(
  371. name = "raw_hashtable_metadata_group_benchmark_test",
  372. size = "small",
  373. srcs = ["raw_hashtable_metadata_group_benchmark"],
  374. args = [
  375. "--benchmark_min_time=1x",
  376. ],
  377. )
  378. cc_library(
  379. name = "raw_hashtable_benchmark_helpers",
  380. testonly = 1,
  381. srcs = ["raw_hashtable_benchmark_helpers.cpp"],
  382. hdrs = ["raw_hashtable_benchmark_helpers.h"],
  383. copts = [
  384. "-O2", # Always optimize to make testing benchmarks faster.
  385. ],
  386. deps = [
  387. ":check",
  388. ":hashing",
  389. ":raw_hashtable",
  390. ":set",
  391. "@abseil-cpp//absl/base:no_destructor",
  392. "@abseil-cpp//absl/hash",
  393. "@abseil-cpp//absl/random",
  394. "@google_benchmark//:benchmark",
  395. "@llvm-project//llvm:Support",
  396. ],
  397. )
  398. cc_library(
  399. name = "raw_hashtable_test_helpers",
  400. testonly = 1,
  401. hdrs = ["raw_hashtable_test_helpers.h"],
  402. deps = [
  403. ":check",
  404. ":hashing",
  405. ":hashtable_key_context",
  406. ":ostream",
  407. ],
  408. )
  409. cc_library(
  410. name = "raw_string_ostream",
  411. hdrs = ["raw_string_ostream.h"],
  412. deps = [
  413. ":check",
  414. ":ostream",
  415. ],
  416. )
  417. cc_test(
  418. name = "raw_string_ostream_test",
  419. size = "small",
  420. srcs = ["raw_string_ostream_test.cpp"],
  421. deps = [
  422. ":raw_string_ostream",
  423. "//testing/base:gtest_main",
  424. "@googletest//:gtest",
  425. ],
  426. )
  427. cc_library(
  428. name = "set",
  429. hdrs = ["set.h"],
  430. deps = [
  431. ":check",
  432. ":hashtable_key_context",
  433. ":raw_hashtable",
  434. "@llvm-project//llvm:Support",
  435. ],
  436. )
  437. cc_test(
  438. name = "set_test",
  439. size = "small",
  440. srcs = ["set_test.cpp"],
  441. deps = [
  442. ":raw_hashtable_test_helpers",
  443. ":set",
  444. "//testing/base:gtest_main",
  445. "@googletest//:gtest",
  446. ],
  447. )
  448. cc_binary(
  449. name = "set_benchmark",
  450. testonly = 1,
  451. srcs = ["set_benchmark.cpp"],
  452. deps = [
  453. ":raw_hashtable_benchmark_helpers",
  454. ":set",
  455. "//testing/base:benchmark_main",
  456. "@abseil-cpp//absl/container:flat_hash_set",
  457. "@google_benchmark//:benchmark",
  458. "@llvm-project//llvm:Support",
  459. ],
  460. )
  461. sh_test(
  462. name = "set_benchmark_test",
  463. # The benchmark allocates a large amount of memory.
  464. size = "enormous",
  465. # We configure the test to run somewhat quickly.
  466. timeout = "moderate",
  467. srcs = [":set_benchmark"],
  468. args = [
  469. "--benchmark_min_time=1x",
  470. # The `$$` is repeated for Bazel escaping of `$`.
  471. "--benchmark_filter=^[^/]*/[1-9][0-9]{0,3}(/[0-9]+)?$$",
  472. ],
  473. )
  474. cc_library(
  475. name = "string_helpers",
  476. srcs = ["string_helpers.cpp"],
  477. hdrs = ["string_helpers.h"],
  478. deps = [
  479. ":check",
  480. ":error",
  481. "@llvm-project//llvm:Support",
  482. ],
  483. )
  484. cc_test(
  485. name = "string_helpers_test",
  486. size = "small",
  487. srcs = ["string_helpers_test.cpp"],
  488. deps = [
  489. ":string_helpers",
  490. "//testing/base:gtest_main",
  491. "@googletest//:gtest",
  492. "@llvm-project//llvm:Support",
  493. ],
  494. )
  495. cc_library(
  496. name = "struct_reflection",
  497. hdrs = ["struct_reflection.h"],
  498. )
  499. cc_test(
  500. name = "struct_reflection_test",
  501. size = "small",
  502. srcs = ["struct_reflection_test.cpp"],
  503. deps = [
  504. ":struct_reflection",
  505. "//testing/base:gtest_main",
  506. "@googletest//:gtest",
  507. ],
  508. )
  509. cc_library(
  510. name = "template_string",
  511. hdrs = ["template_string.h"],
  512. deps = [
  513. "@llvm-project//llvm:Support",
  514. ],
  515. )
  516. cc_test(
  517. name = "template_string_test",
  518. size = "small",
  519. srcs = ["template_string_test.cpp"],
  520. deps = [
  521. ":template_string",
  522. "//testing/base:gtest_main",
  523. "@googletest//:gtest",
  524. ],
  525. )
  526. # The base version source file only uses non-stamped parts of the version
  527. # information so we expand it once here without any stamping.
  528. expand_version_build_info(
  529. name = "version_cpp_gen",
  530. out = "version.cpp",
  531. stamp = 0,
  532. template = "version.tmpl.cpp",
  533. )
  534. # Build a nostamp version of the stamp source, but mark its definitions as weak.
  535. # We'll include this in the library to satisfy definitions of library and test
  536. # users, but still allow binaries that want full build stamping to depend on the
  537. # stamp library below to override with strong, stamped definitions.
  538. expand_version_build_info(
  539. name = "version_nostamp_cpp_gen",
  540. out = "version_nostamp.cpp",
  541. stamp = 0,
  542. substitutions = {"MAKE_WEAK": "1"},
  543. template = "version_stamp.tmpl.cpp",
  544. )
  545. # Provides APIs for accessing Carbon version information.
  546. #
  547. # These provide full access to the major, minor, and patch version. It also
  548. # provides an API for querying version strings that may contain detailed build
  549. # information such as the commit SHA.
  550. #
  551. # By default, this provides the API and an *unstamped* implementations of
  552. # version strings. As a consequence, depending on this library doesn't introduce
  553. # any dependency on the commit SHA or loss of build caching.
  554. #
  555. # Targets that want full build info stamping in the data produced by these APIs
  556. # should additionally depend on `:version_stamp` below -- the data these APIs
  557. # return will be overridden in any binaries depending on that rule with the
  558. # fully stamped details.
  559. cc_library(
  560. name = "version",
  561. srcs = [
  562. "version.cpp",
  563. "version_nostamp.cpp",
  564. ],
  565. hdrs = ["version.h"],
  566. deps = [
  567. "@llvm-project//llvm:Support",
  568. ],
  569. )
  570. # Generate the fully stamped sourcefile if stamping is enabled in the build.
  571. expand_version_build_info(
  572. name = "version_stamp_cpp_gen",
  573. out = "version_stamp.cpp",
  574. template = "version_stamp.tmpl.cpp",
  575. )
  576. # Depend on this library to enable fully-stamped build information in the
  577. # version API provided by `:version`. This doesn't provide the API, it injects
  578. # an override of stamped versions of the data.
  579. #
  580. # Note that depending on this will significantly reduce build caching with
  581. # `--stamp` builds. It should be used sparingly, typically in user-facing
  582. # binaries or systems that need to render a maximally detailed version string
  583. # with build information stamped into it.
  584. cc_library(
  585. name = "version_stamp",
  586. srcs = ["version_stamp.cpp"],
  587. deps = [
  588. ":version",
  589. "@llvm-project//llvm:Support",
  590. ],
  591. )
  592. cc_library(
  593. name = "vlog",
  594. hdrs = ["vlog.h"],
  595. deps = [
  596. ":ostream",
  597. ":template_string",
  598. "@llvm-project//llvm:Support",
  599. ],
  600. )
  601. cc_test(
  602. name = "vlog_test",
  603. size = "small",
  604. srcs = ["vlog_test.cpp"],
  605. deps = [
  606. ":raw_string_ostream",
  607. ":vlog",
  608. "//testing/base:gtest_main",
  609. "@googletest//:gtest",
  610. ],
  611. )