BUILD 13 KB

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