BUILD 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
  5. load("@rules_shell//shell:sh_test.bzl", "sh_test")
  6. load("//bazel/cc_rules:defs.bzl", "cc_binary", "cc_library", "cc_test")
  7. load("//bazel/cc_toolchains:defs.bzl", "cc_env")
  8. load("//testing/fuzzing:rules.bzl", "cc_fuzz_test")
  9. load(":prebuilt_runtimes.bzl", "prebuilt_runtimes")
  10. package(default_visibility = ["//visibility:public"])
  11. filegroup(
  12. name = "testdata",
  13. srcs = glob([
  14. "testdata/**/*.carbon",
  15. "testdata/**/*.cpp",
  16. ]),
  17. )
  18. cc_library(
  19. name = "clang_runner",
  20. srcs = [
  21. "clang_runner.cpp",
  22. "clang_runtimes.cpp",
  23. ],
  24. hdrs = [
  25. "clang_runner.h",
  26. "clang_runtimes.h",
  27. ],
  28. deps = [
  29. ":llvm_runner",
  30. ":runtimes_cache",
  31. ":tool_runner_base",
  32. "//common:check",
  33. "//common:error",
  34. "//common:filesystem",
  35. "//common:latch",
  36. "//common:ostream",
  37. "//common:string_helpers",
  38. "//common:vlog",
  39. "//third_party/llvm:clang_cc1",
  40. "//toolchain/base:clang_invocation",
  41. "//toolchain/base:install_paths",
  42. "//toolchain/base:kind_switch",
  43. "//toolchain/base:runtime_sources",
  44. "@llvm-project//clang:basic",
  45. "@llvm-project//clang:clang-driver",
  46. "@llvm-project//clang:codegen",
  47. "@llvm-project//clang:driver",
  48. "@llvm-project//clang:frontend",
  49. "@llvm-project//clang:frontend_tool",
  50. "@llvm-project//clang:serialization",
  51. "@llvm-project//llvm:Core",
  52. "@llvm-project//llvm:Object",
  53. "@llvm-project//llvm:Support",
  54. "@llvm-project//llvm:TargetParser",
  55. ],
  56. )
  57. cc_test(
  58. name = "clang_runner_test",
  59. size = "small",
  60. srcs = ["clang_runner_test.cpp"],
  61. data = ["//toolchain/install:install_data"],
  62. deps = [
  63. ":clang_runner",
  64. ":llvm_runner",
  65. ":runtimes_cache",
  66. "//common:all_llvm_targets",
  67. "//common:check",
  68. "//common:ostream",
  69. "//common:raw_string_ostream",
  70. "//testing/base:capture_std_streams",
  71. "//testing/base:file_helpers",
  72. "//testing/base:global_exe_path",
  73. "//testing/base:gtest_main",
  74. "//toolchain/base:install_paths",
  75. "@googletest//:gtest",
  76. "@llvm-project//llvm:Object",
  77. "@llvm-project//llvm:Support",
  78. "@llvm-project//llvm:TargetParser",
  79. ],
  80. )
  81. cc_test(
  82. name = "clang_runtimes_test",
  83. size = "medium",
  84. srcs = ["clang_runtimes_test.cpp"],
  85. data = [
  86. ":prebuilt_runtimes",
  87. "//toolchain/install:install_data",
  88. ],
  89. deps = [
  90. ":clang_runner",
  91. ":llvm_runner",
  92. ":runtimes_cache",
  93. "//common:all_llvm_targets",
  94. "//common:check",
  95. "//common:ostream",
  96. "//common:raw_string_ostream",
  97. "//testing/base:capture_std_streams",
  98. "//testing/base:file_helpers",
  99. "//testing/base:global_exe_path",
  100. "//testing/base:gtest_main",
  101. "//toolchain/base:install_paths",
  102. "//toolchain/base:llvm_tools",
  103. "@bazel_tools//tools/cpp/runfiles",
  104. "@googletest//:gtest",
  105. "@llvm-project//llvm:Object",
  106. "@llvm-project//llvm:Support",
  107. "@llvm-project//llvm:TargetParser",
  108. ],
  109. )
  110. cc_binary(
  111. name = "compile_benchmark",
  112. testonly = 1,
  113. srcs = ["compile_benchmark.cpp"],
  114. deps = [
  115. ":driver",
  116. "//common:all_llvm_targets",
  117. "//testing/base:benchmark_main",
  118. "//testing/base:global_exe_path",
  119. "//testing/base:source_gen_lib",
  120. "//toolchain/base:install_paths_test_helpers",
  121. "//toolchain/testing:compile_helper",
  122. "@google_benchmark//:benchmark",
  123. "@llvm-project//llvm:Support",
  124. ],
  125. )
  126. sh_test(
  127. name = "compile_benchmark_test",
  128. size = "small",
  129. srcs = [":compile_benchmark"],
  130. args = [
  131. "--benchmark_dry_run",
  132. # The `$$` is repeated for Bazel escaping of `$`.
  133. "--benchmark_filter=/256$$",
  134. ],
  135. env = cc_env(),
  136. )
  137. cc_library(
  138. name = "codegen_options",
  139. srcs = [
  140. "codegen_options.cpp",
  141. ],
  142. hdrs = [
  143. "codegen_options.h",
  144. ],
  145. deps = [
  146. "//common:command_line",
  147. "@llvm-project//llvm:Support",
  148. "@llvm-project//llvm:TargetParser",
  149. ],
  150. )
  151. cc_library(
  152. name = "driver",
  153. srcs = [
  154. "build_runtimes_subcommand.cpp",
  155. "build_runtimes_subcommand.h",
  156. "clang_subcommand.cpp",
  157. "clang_subcommand.h",
  158. "compile_subcommand.cpp",
  159. "compile_subcommand.h",
  160. "driver.cpp",
  161. "driver_env.h",
  162. "driver_subcommand.cpp",
  163. "format_subcommand.cpp",
  164. "format_subcommand.h",
  165. "language_server_subcommand.cpp",
  166. "language_server_subcommand.h",
  167. "link_subcommand.cpp",
  168. "link_subcommand.h",
  169. "lld_subcommand.cpp",
  170. "lld_subcommand.h",
  171. "llvm_subcommand.cpp",
  172. "llvm_subcommand.h",
  173. ],
  174. hdrs = [
  175. "driver.h",
  176. "driver_subcommand.h",
  177. ],
  178. data = [
  179. "//toolchain/install:install_data.no_driver",
  180. ],
  181. textual_hdrs = ["flags.def"],
  182. deps = [
  183. ":clang_runner",
  184. ":codegen_options",
  185. ":lld_runner",
  186. ":llvm_runner",
  187. ":runtimes_cache",
  188. "//common:command_line",
  189. "//common:error",
  190. "//common:ostream",
  191. "//common:pretty_stack_trace_function",
  192. "//common:raw_string_ostream",
  193. "//common:version",
  194. "//common:vlog",
  195. "//toolchain/base:clang_invocation",
  196. "//toolchain/base:install_paths",
  197. "//toolchain/base:llvm_tools",
  198. "//toolchain/base:shared_value_stores",
  199. "//toolchain/base:timings",
  200. "//toolchain/check",
  201. "//toolchain/codegen",
  202. "//toolchain/diagnostics:diagnostic_emitter",
  203. "//toolchain/diagnostics:sorting_diagnostic_consumer",
  204. "//toolchain/format",
  205. "//toolchain/language_server",
  206. "//toolchain/lex",
  207. "//toolchain/lower",
  208. "//toolchain/lower:options",
  209. "//toolchain/parse",
  210. "//toolchain/parse:tree",
  211. "//toolchain/sem_ir:file",
  212. "//toolchain/sem_ir:typed_insts",
  213. "//toolchain/source:source_buffer",
  214. "@llvm-project//llvm:Core",
  215. "@llvm-project//llvm:MC",
  216. "@llvm-project//llvm:Passes",
  217. "@llvm-project//llvm:Support",
  218. "@llvm-project//llvm:TargetParser",
  219. ],
  220. )
  221. cc_test(
  222. name = "driver_test",
  223. size = "small",
  224. srcs = ["driver_test.cpp"],
  225. deps = [
  226. ":driver",
  227. "//common:all_llvm_targets",
  228. "//common:raw_string_ostream",
  229. "//testing/base:file_helpers",
  230. "//testing/base:global_exe_path",
  231. "//testing/base:gtest_main",
  232. "//toolchain/base:install_paths",
  233. "//toolchain/diagnostics:diagnostic_emitter",
  234. "//toolchain/lex:tokenized_buffer_test_helpers",
  235. "//toolchain/testing:yaml_test_helpers",
  236. "@googletest//:gtest",
  237. "@llvm-project//llvm:Object",
  238. "@llvm-project//llvm:Support",
  239. ],
  240. )
  241. cc_fuzz_test(
  242. name = "driver_fuzzer",
  243. size = "small",
  244. srcs = ["driver_fuzzer.cpp"],
  245. corpus = glob(["fuzzer_corpus/*"]),
  246. deps = [
  247. ":driver",
  248. "//common:exe_path",
  249. "//common:raw_string_ostream",
  250. "//testing/fuzzing:libfuzzer_header",
  251. "//toolchain/base:install_paths",
  252. "@llvm-project//llvm:Support",
  253. ],
  254. )
  255. cc_library(
  256. name = "lld_runner",
  257. srcs = ["lld_runner.cpp"],
  258. hdrs = ["lld_runner.h"],
  259. deps = [
  260. ":tool_runner_base",
  261. "//common:ostream",
  262. "//common:string_helpers",
  263. "//common:vlog",
  264. "//toolchain/base:install_paths",
  265. "@llvm-project//lld:Common",
  266. "@llvm-project//lld:ELF",
  267. "@llvm-project//lld:MachO",
  268. "@llvm-project//llvm:Support",
  269. ],
  270. )
  271. cc_test(
  272. name = "lld_runner_test",
  273. size = "small",
  274. srcs = ["lld_runner_test.cpp"],
  275. deps = [
  276. ":clang_runner",
  277. ":lld_runner",
  278. "//common:all_llvm_targets",
  279. "//common:check",
  280. "//common:ostream",
  281. "//common:raw_string_ostream",
  282. "//testing/base:capture_std_streams",
  283. "//testing/base:file_helpers",
  284. "//testing/base:global_exe_path",
  285. "//testing/base:gtest_main",
  286. "@googletest//:gtest",
  287. "@llvm-project//llvm:Object",
  288. "@llvm-project//llvm:Support",
  289. "@llvm-project//llvm:TargetParser",
  290. ],
  291. )
  292. cc_library(
  293. name = "llvm_runner",
  294. srcs = ["llvm_runner.cpp"],
  295. hdrs = ["llvm_runner.h"],
  296. deps = [
  297. ":tool_runner_base",
  298. "//common:ostream",
  299. "//common:string_helpers",
  300. "//common:vlog",
  301. "//toolchain/base:install_paths",
  302. "//toolchain/base:llvm_tools",
  303. "@llvm-project//lld:Common",
  304. "@llvm-project//lld:ELF",
  305. "@llvm-project//lld:MachO",
  306. "@llvm-project//llvm:Support",
  307. ],
  308. )
  309. cc_test(
  310. name = "llvm_runner_test",
  311. size = "small",
  312. srcs = ["llvm_runner_test.cpp"],
  313. deps = [
  314. ":llvm_runner",
  315. "//common:all_llvm_targets",
  316. "//common:ostream",
  317. "//common:raw_string_ostream",
  318. "//testing/base:capture_std_streams",
  319. "//testing/base:global_exe_path",
  320. "//testing/base:gtest_main",
  321. "@googletest//:gtest",
  322. "@llvm-project//llvm:Support",
  323. ],
  324. )
  325. cc_library(
  326. name = "runtimes_cache",
  327. srcs = ["runtimes_cache.cpp"],
  328. hdrs = ["runtimes_cache.h"],
  329. deps = [
  330. "//common:check",
  331. "//common:error",
  332. "//common:filesystem",
  333. "//common:ostream",
  334. "//common:version",
  335. "//common:vlog",
  336. "//toolchain/base:install_paths",
  337. "@llvm-project//llvm:Support",
  338. ],
  339. )
  340. cc_test(
  341. name = "runtimes_cache_test",
  342. size = "small",
  343. srcs = ["runtimes_cache_test.cpp"],
  344. data = ["//toolchain/install:install_data"],
  345. deps = [
  346. ":runtimes_cache",
  347. "//common:check",
  348. "//common:error_test_helpers",
  349. "//common:filesystem",
  350. "//common:ostream",
  351. "//common:raw_string_ostream",
  352. "//common:version",
  353. "//testing/base:capture_std_streams",
  354. "//testing/base:file_helpers",
  355. "//testing/base:global_exe_path",
  356. "//testing/base:gtest_main",
  357. "@googletest//:gtest",
  358. "@llvm-project//llvm:Support",
  359. ],
  360. )
  361. cc_library(
  362. name = "tool_runner_base",
  363. srcs = ["tool_runner_base.cpp"],
  364. hdrs = ["tool_runner_base.h"],
  365. data = [
  366. "//toolchain/install:install_data.no_driver",
  367. ],
  368. deps = [
  369. "//common:ostream",
  370. "//common:vlog",
  371. "//toolchain/base:install_paths",
  372. "@llvm-project//llvm:Support",
  373. ],
  374. )
  375. cc_binary(
  376. name = "bazel_build_clang_runtimes",
  377. srcs = ["bazel_build_clang_runtimes.cpp"],
  378. data = [
  379. "//toolchain/install:install_data.no_driver",
  380. "@llvm-project//clang:clang",
  381. ],
  382. deps = [
  383. ":clang_runner",
  384. ":codegen_options",
  385. ":runtimes_cache",
  386. "//common:all_llvm_targets",
  387. "//common:bazel_working_dir",
  388. "//common:check",
  389. "//common:command_line",
  390. "//common:error",
  391. "//common:exe_path",
  392. "//common:filesystem",
  393. "//common:init_llvm",
  394. "//common:raw_string_ostream",
  395. "//common:version",
  396. "//toolchain/base:install_paths",
  397. "@bazel_tools//tools/cpp/runfiles",
  398. "@llvm-project//llvm:Support",
  399. "@llvm-project//llvm:TargetParser",
  400. ],
  401. )
  402. # Flag controlling whether the target config is used for the
  403. # tools used by the `prebuilt_runtimes` rules.
  404. #
  405. # Using the exec config is more correct and will also optimize the tools used to
  406. # build the runtimes, potentially making them run faster. However, it will
  407. # likely double the number of compiles needed to build everything necessary in
  408. # that configuration. As a consequence, it is useful in development and CI when
  409. # the target config is compatible with the exec config to set this flag.
  410. bool_flag(
  411. name = "use_target_config_runtimes_builder",
  412. build_setting_default = False,
  413. )
  414. config_setting(
  415. name = "use_target_config_runtimes_builder_config",
  416. flag_values = {":use_target_config_runtimes_builder": "True"},
  417. )
  418. # TODO: Correctly set the `target` argument here based on the Bazel target
  419. # platform. Without this, we will generate invalid prebuilt runtimes when cross
  420. # compiling.
  421. prebuilt_runtimes(
  422. name = "prebuilt_runtimes",
  423. )