BUILD 14 KB

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