BUILD 15 KB

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