BUILD 17 KB

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