BUILD 14 KB

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