BUILD 17 KB

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