BUILD 14 KB

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