BUILD 14 KB

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