BUILD 16 KB

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