BUILD 13 KB

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