BUILD 13 KB

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