BUILD 15 KB

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