BUILD 13 KB

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