BUILD 15 KB

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