BUILD 14 KB

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