BUILD 13 KB

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