BUILD 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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. #
  5. # Build rules supporting the install data tree for the Carbon toolchain.
  6. #
  7. # This populates a synthetic Carbon toolchain installation rooted at this
  8. # package in the output tree.
  9. #
  10. # We use a `toolchain_files` rule organize the files in in the installation and
  11. # handle cases where we need to symlink existing files or build outputs
  12. # into the correct location.
  13. #
  14. # This package also includes the logic for building Carbon's runtimes, and Bazel
  15. # `cc_toolchain`s for using the installation as a C++ toolchain in Bazel. This
  16. # allows multi-stage bootstrapping to occur entirely within Bazel. Note that the
  17. # specific stage will be in a _configuration specific_ output tree, but always
  18. # rooted under the install package.
  19. #
  20. # Last but ont least, we provide rules to build packages of the installation in
  21. # conventional layouts for directly extracting and using a binary build. The
  22. # packaged installation includes custom Bazel files to handle a pre-built and
  23. # installed toolchain in the same way as these handle the just-built toolchain.
  24. load(
  25. "@llvm-project//:vars.bzl",
  26. "LLVM_VERSION_MAJOR",
  27. )
  28. load(
  29. "@llvm-project//compiler-rt:compiler-rt.bzl",
  30. "builtins_copts",
  31. "crt_copts",
  32. )
  33. load("@llvm-project//libcxx:libcxx_library.bzl", "libcxx_and_abi_copts")
  34. load("@llvm-project//libunwind:libunwind_library.bzl", "libunwind_copts")
  35. load("@rules_python//python:defs.bzl", "py_test")
  36. load("//bazel/cc_rules:defs.bzl", "cc_binary", "cc_library", "cc_test")
  37. load(
  38. "//bazel/cc_toolchains:carbon_bootstrapping.bzl",
  39. "carbon_bootstrapped_cc_toolchain",
  40. "filegroup_with_stage",
  41. "gen_cc_toolchain_paths_with_stage",
  42. )
  43. load("//bazel/manifest:defs.bzl", "manifest")
  44. load(
  45. "//toolchain/base:runtimes_build_info.bzl",
  46. "generate_runtimes_build_vars",
  47. )
  48. load("//toolchain/runtimes:carbon_runtimes.bzl", "carbon_runtimes_config")
  49. load("bazel/make_include_copts.bzl", "make_include_copts")
  50. load(
  51. "install_filegroups.bzl",
  52. "filtered_toolchain_files",
  53. "toolchain_files",
  54. "toolchain_llvm_binaries",
  55. "toolchain_pkg_filegroup",
  56. )
  57. load("pkg_helpers.bzl", "pkg_naming_variables", "pkg_tar_and_test")
  58. package(default_visibility = ["//visibility:public"])
  59. config_setting(
  60. name = "is_runtimes_build",
  61. flag_values = {"//:runtimes_build": "True"},
  62. )
  63. config_setting(
  64. name = "not_runtimes_build",
  65. flag_values = {"//:runtimes_build": "False"},
  66. )
  67. config_setting(
  68. name = "is_bootstrap_stage_0",
  69. flag_values = {"//:bootstrap_stage": "0"},
  70. )
  71. config_setting(
  72. name = "is_bootstrap_stage_1",
  73. flag_values = {"//:bootstrap_stage": "1"},
  74. )
  75. config_setting(
  76. name = "is_bootstrap_stage_2",
  77. flag_values = {"//:bootstrap_stage": "2"},
  78. )
  79. cc_library(
  80. name = "busybox_info",
  81. srcs = ["busybox_info.cpp"],
  82. hdrs = ["busybox_info.h"],
  83. deps = [
  84. "//common:error",
  85. "//common:exe_path",
  86. "//common:filesystem",
  87. "@llvm-project//llvm:Support",
  88. ],
  89. )
  90. cc_test(
  91. name = "busybox_info_test",
  92. size = "small",
  93. srcs = ["busybox_info_test.cpp"],
  94. deps = [
  95. ":busybox_info",
  96. "//common:check",
  97. "//common:filesystem",
  98. "//testing/base:gtest_main",
  99. "@googletest//:gtest",
  100. "@llvm-project//llvm:Support",
  101. ],
  102. )
  103. # This target doesn't include prelude libraries. To get a target that has the
  104. # prelude available, use //toolchain.
  105. cc_binary(
  106. name = "carbon-busybox",
  107. srcs = ["busybox_main.cpp"],
  108. deps = [
  109. ":busybox_info",
  110. "//common:all_llvm_targets",
  111. "//common:bazel_working_dir",
  112. "//common:error",
  113. "//common:exe_path",
  114. "//common:init_llvm",
  115. "//common:version_stamp",
  116. "//toolchain/base:install_paths",
  117. "//toolchain/base:llvm_tools_def",
  118. "//toolchain/driver",
  119. "@llvm-project//clang:driver",
  120. "@llvm-project//llvm:Support",
  121. ],
  122. )
  123. toolchain_files(
  124. name = "install_marker",
  125. srcs = ["carbon_install.txt"],
  126. )
  127. toolchain_llvm_binaries(
  128. name = "llvm_bins",
  129. carbon_binary = ":carbon-busybox",
  130. )
  131. toolchain_files(
  132. name = "core",
  133. srcs = ["//core:prelude"],
  134. prefix = "core/",
  135. )
  136. toolchain_files(
  137. name = "clang_builtin_hdrs",
  138. srcs = ["@llvm-project//clang:builtin_headers_gen"],
  139. prefix = "llvm/lib/clang/{0}/include/".format(LLVM_VERSION_MAJOR),
  140. remove_prefix = "staging/include/",
  141. )
  142. toolchain_files(
  143. name = "fuzzer_runtime_hdrs",
  144. srcs = ["@llvm-project//compiler-rt:fuzzer_installed_hdrs"],
  145. prefix = "llvm/lib/clang/{0}/include/".format(LLVM_VERSION_MAJOR),
  146. remove_prefix = "include/",
  147. )
  148. toolchain_files(
  149. name = "profile_runtime_hdrs",
  150. srcs = ["@llvm-project//compiler-rt:profile_installed_hdrs"],
  151. prefix = "llvm/lib/clang/{0}/include/".format(LLVM_VERSION_MAJOR),
  152. remove_prefix = "include/",
  153. )
  154. toolchain_files(
  155. name = "sanitizer_runtime_hdrs",
  156. srcs = ["@llvm-project//compiler-rt:sanitizer_installed_hdrs"],
  157. prefix = "llvm/lib/clang/{0}/include/".format(LLVM_VERSION_MAJOR),
  158. remove_prefix = "include/",
  159. )
  160. filegroup(
  161. name = "clang_hdrs",
  162. srcs = [
  163. ":clang_builtin_hdrs",
  164. ":fuzzer_runtime_hdrs",
  165. ":profile_runtime_hdrs",
  166. ":sanitizer_runtime_hdrs",
  167. ],
  168. )
  169. filtered_toolchain_files(
  170. name = "builtins_srcs",
  171. prefix = "runtimes/builtins/",
  172. remove_prefix = "lib/builtins/",
  173. srcs_groups = [
  174. "@llvm-project//compiler-rt:builtins_aarch64_srcs",
  175. "@llvm-project//compiler-rt:builtins_aarch64_textual_srcs",
  176. "@llvm-project//compiler-rt:builtins_crtbegin_src",
  177. "@llvm-project//compiler-rt:builtins_crtend_src",
  178. "@llvm-project//compiler-rt:builtins_i386_srcs",
  179. "@llvm-project//compiler-rt:builtins_i386_textual_srcs",
  180. "@llvm-project//compiler-rt:builtins_x86_64_srcs",
  181. "@llvm-project//compiler-rt:builtins_x86_64_textual_srcs",
  182. ],
  183. )
  184. toolchain_files(
  185. name = "libcxx_basic_hdrs",
  186. srcs = ["@llvm-project//libcxx:libcxx_hdrs"],
  187. prefix = "runtimes/libcxx/include/",
  188. remove_prefix = "include/",
  189. )
  190. toolchain_files(
  191. name = "libcxx_gen_hdrs",
  192. srcs = ["//toolchain/runtimes:libcxx_gen_files"],
  193. prefix = "runtimes/libcxx/include/",
  194. remove_prefix = "staging_libcxx/include/",
  195. )
  196. filegroup(
  197. name = "libcxx_hdrs",
  198. srcs = [
  199. ":libcxx_basic_hdrs",
  200. ":libcxx_gen_hdrs",
  201. ],
  202. )
  203. filtered_toolchain_files(
  204. name = "libcxx_srcs",
  205. prefix = "runtimes/libcxx/src/",
  206. remove_prefix = "src/",
  207. srcs_groups = [
  208. "@llvm-project//libcxx:libcxx_linux_srcs",
  209. "@llvm-project//libcxx:libcxx_macos_srcs",
  210. "@llvm-project//libcxx:libcxx_win32_srcs",
  211. ],
  212. )
  213. toolchain_files(
  214. name = "libcxxabi_hdrs",
  215. srcs = ["@llvm-project//libcxxabi:libcxxabi_hdrs"],
  216. prefix = "runtimes/libcxxabi/include/",
  217. remove_prefix = "include/",
  218. )
  219. toolchain_files(
  220. name = "libcxxabi_srcs",
  221. srcs = ["@llvm-project//libcxxabi:libcxxabi_srcs"],
  222. prefix = "runtimes/libcxxabi/src/",
  223. remove_prefix = "src/",
  224. )
  225. toolchain_files(
  226. name = "libcxxabi_textual_srcs",
  227. srcs = ["@llvm-project//libcxxabi:libcxxabi_textual_srcs"],
  228. prefix = "runtimes/libcxxabi/src/",
  229. remove_prefix = "src/",
  230. )
  231. toolchain_files(
  232. name = "libc_internal_libcxx_hdrs",
  233. srcs = ["@llvm-project//libc:libcxx_shared_headers_hdrs"],
  234. prefix = "runtimes/libc/internal/",
  235. )
  236. toolchain_files(
  237. name = "libunwind_hdrs",
  238. srcs = ["@llvm-project//libunwind:libunwind_hdrs"],
  239. prefix = "runtimes/libunwind/include/",
  240. remove_prefix = "include/",
  241. )
  242. toolchain_files(
  243. name = "libunwind_srcs",
  244. srcs = ["@llvm-project//libunwind:libunwind_srcs"],
  245. prefix = "runtimes/libunwind/src/",
  246. remove_prefix = "src/",
  247. )
  248. filegroup(
  249. name = "cc_toolchain_all_files",
  250. srcs = [
  251. ":carbon-busybox",
  252. ":clang_hdrs",
  253. ":core",
  254. ":install_marker",
  255. ":libcxx_hdrs",
  256. ":libcxxabi_hdrs",
  257. ":libunwind_hdrs",
  258. ":llvm_bins",
  259. ],
  260. )
  261. # The toolchain configuration starlark needs to switch from referencing the
  262. # `carbon_runtimes.bzl` starlark in the toolchain layout to the `bazel` tree
  263. # within the installation.
  264. #
  265. # TODO: Maybe we should move the `carbon_runtimes.bzl` to the same directory as
  266. # the other starlark so we can use relative load lines and avoid this?
  267. genrule(
  268. name = "carbon_cc_toolchain_config_for_install",
  269. srcs = ["//bazel/cc_toolchains:carbon_cc_toolchain_config.bzl"],
  270. outs = ["carbon_cc_toolchain_config.bzl"],
  271. cmd = "sed 's|//toolchain/runtimes:carbon_runtimes.bzl|//bazel:carbon_runtimes.bzl|' $< > $@",
  272. )
  273. toolchain_files(
  274. name = "bazel_common_srcs",
  275. srcs = [
  276. ":carbon_cc_toolchain_config_for_install",
  277. "//bazel/cc_toolchains:installed_cc_toolchain_starlark",
  278. ],
  279. prefix = "bazel/",
  280. )
  281. toolchain_files(
  282. name = "bazel_install_srcs",
  283. srcs = [
  284. "bazel/carbon_clang_variables.bzl",
  285. "bazel/carbon_detected_variables.tpl.bzl",
  286. "bazel/carbon_toolchain.bzl",
  287. "bazel/make_include_copts.bzl",
  288. ],
  289. )
  290. toolchain_files(
  291. name = "carbon_runtimes_bzl_installed",
  292. srcs = ["//toolchain/runtimes:carbon_runtimes.bzl"],
  293. prefix = "bazel/",
  294. )
  295. toolchain_files(
  296. name = "bazel_build_and_module",
  297. srcs = [
  298. "bazel/empty.BUILD",
  299. "bazel/install.BUILD",
  300. "bazel/install.MODULE.bazel",
  301. ],
  302. remove_prefix = "bazel/",
  303. renames = {
  304. "empty.BUILD": "bazel/BUILD.bazel",
  305. "install.BUILD": "BUILD.bazel",
  306. "install.MODULE.bazel": "MODULE.bazel",
  307. },
  308. )
  309. # Generate a Starlark file with all the build variables needed for our runtimes.
  310. generate_runtimes_build_vars(
  311. name = "bazel/runtimes_build_vars.bzl",
  312. )
  313. filegroup(
  314. name = "installed_bazel_files",
  315. srcs = [
  316. ":bazel_build_and_module",
  317. ":bazel_common_srcs",
  318. ":bazel_install_srcs",
  319. ":carbon_runtimes_bzl_installed",
  320. # Note that we have to put this here and not in one of the
  321. # `toolchain_files` because it is a generated file.
  322. "bazel/runtimes_build_vars.bzl",
  323. ],
  324. )
  325. filegroup(
  326. name = "all_data_files",
  327. srcs = [
  328. ":builtins_all_srcs",
  329. ":clang_hdrs",
  330. ":core",
  331. ":install_marker",
  332. ":installed_bazel_files",
  333. ":libc_internal_libcxx_hdrs",
  334. ":libcxx_all_srcs",
  335. ":libcxx_hdrs",
  336. ":libcxxabi_hdrs",
  337. ":libcxxabi_srcs",
  338. ":libcxxabi_textual_srcs",
  339. ":libunwind_hdrs",
  340. ":libunwind_srcs",
  341. ],
  342. )
  343. # A list of clang's installed builtin header files.
  344. # This is consumed by //toolchain/testing:file_test.
  345. manifest(
  346. name = "clang_headers_manifest.txt",
  347. srcs = [":clang_hdrs"],
  348. strip_package_dir = True,
  349. )
  350. filegroup(
  351. name = "all_digest_files",
  352. srcs = [
  353. ":all_data_files",
  354. ":carbon-busybox",
  355. ],
  356. )
  357. manifest(
  358. name = "install_digest_manifest.txt",
  359. srcs = [":all_digest_files"],
  360. )
  361. cc_binary(
  362. name = "make-installation-digest",
  363. srcs = ["make_installation_digest.cpp"],
  364. deps = [
  365. "//common:bazel_working_dir",
  366. "//common:error",
  367. "//common:exe_path",
  368. "//common:filesystem",
  369. "//common:init_llvm",
  370. "//common:map",
  371. "//common:vlog",
  372. "@llvm-project//llvm:Support",
  373. ],
  374. )
  375. genrule(
  376. name = "gen_digest",
  377. srcs = [
  378. ":all_digest_files",
  379. "install_digest_manifest.txt",
  380. ],
  381. outs = ["install_digest.txt"],
  382. cmd = "{0} {1} $@".format(
  383. "$(location :make-installation-digest)",
  384. "$(location install_digest_manifest.txt)",
  385. ),
  386. tools = [":make-installation-digest"],
  387. )
  388. filegroup(
  389. name = "install_data",
  390. srcs = [
  391. "install_digest.txt",
  392. ":all_digest_files",
  393. ":llvm_bins",
  394. ],
  395. )
  396. manifest(
  397. name = "install_data_manifest.txt",
  398. srcs = [":install_data"],
  399. )
  400. cc_library(
  401. name = "builtins_internal",
  402. hdrs_check = "strict",
  403. textual_hdrs = select({
  404. "@platforms//cpu:aarch64": [":builtins_aarch64_textual_srcs"],
  405. "@platforms//cpu:i386": [":builtins_i386_textual_srcs"],
  406. "@platforms//cpu:x86_64": [":builtins_x86_64_textual_srcs"],
  407. "//conditions:default": [],
  408. }),
  409. )
  410. cc_library(
  411. name = "builtins",
  412. srcs = select({
  413. "@platforms//cpu:aarch64": [":builtins_aarch64_srcs"],
  414. "@platforms//cpu:i386": [":builtins_i386_srcs"],
  415. "@platforms//cpu:x86_64": [":builtins_x86_64_srcs"],
  416. "//conditions:default": [],
  417. }),
  418. copts = builtins_copts + make_include_copts([
  419. "runtimes/builtins",
  420. ]) + [
  421. # TODO: Remove this once we are building sanitizer runtime libraries.
  422. "-fno-sanitize=all",
  423. ],
  424. hdrs_check = "strict",
  425. target_compatible_with = select({
  426. ":is_runtimes_build": [],
  427. "//conditions:default": ["@platforms//:incompatible"],
  428. }),
  429. deps = [":builtins_internal"],
  430. )
  431. filegroup(
  432. name = "builtins_archive",
  433. srcs = [":builtins"],
  434. output_group = "archive",
  435. )
  436. cc_library(
  437. name = "libunwind",
  438. srcs = [":libunwind_srcs"],
  439. hdrs = [":libunwind_hdrs"],
  440. copts = libunwind_copts + [
  441. # We disable all warnings as upstream isn't clean with the common
  442. # warning flags Carbon uses by default.
  443. "-w",
  444. # TODO: Remove this once we are building sanitizer runtime libraries.
  445. "-fno-sanitize=all",
  446. ],
  447. hdrs_check = "strict",
  448. includes = ["runtimes/libunwind/include"],
  449. linkstatic = 1,
  450. target_compatible_with = select({
  451. ":is_runtimes_build": [],
  452. "//conditions:default": ["@platforms//:incompatible"],
  453. }),
  454. )
  455. filegroup(
  456. name = "libunwind_archive",
  457. srcs = [":libunwind"],
  458. output_group = "archive",
  459. )
  460. cc_library(
  461. name = "libcxxabi_internal",
  462. hdrs_check = "strict",
  463. target_compatible_with = select({
  464. ":is_runtimes_build": [],
  465. "//conditions:default": ["@platforms//:incompatible"],
  466. }),
  467. textual_hdrs = [":libcxxabi_textual_srcs"],
  468. )
  469. cc_library(
  470. name = "libc_internal_libcxx",
  471. hdrs = [":libc_internal_libcxx_hdrs"],
  472. hdrs_check = "strict",
  473. target_compatible_with = select({
  474. ":is_runtimes_build": [],
  475. "//conditions:default": ["@platforms//:incompatible"],
  476. }),
  477. )
  478. cc_library(
  479. name = "libcxx",
  480. srcs = select({
  481. "@platforms//os:macos": [":libcxx_macos_srcs"],
  482. "@platforms//os:windows": [":libcxx_win32_srcs"],
  483. "//conditions:default": [":libcxx_linux_srcs"],
  484. }) + [":libcxxabi_srcs"],
  485. hdrs = [
  486. ":libcxx_hdrs",
  487. ":libcxxabi_hdrs",
  488. ],
  489. copts = libcxx_and_abi_copts + make_include_copts([
  490. "runtimes/libcxx/src",
  491. "runtimes/libc/internal",
  492. ]) + [
  493. # We disable all warnings as upstream isn't clean with the common
  494. # warning flags Carbon uses by default.
  495. "-w",
  496. # TODO: Remove this once we are building sanitizer runtime libraries.
  497. "-fno-sanitize=all",
  498. ],
  499. hdrs_check = "strict",
  500. includes = [
  501. "runtimes/libcxx/include",
  502. "runtimes/libcxxabi/include",
  503. ],
  504. target_compatible_with = select({
  505. ":is_runtimes_build": [],
  506. "//conditions:default": ["@platforms//:incompatible"],
  507. }),
  508. deps = [
  509. ":libc_internal_libcxx",
  510. ":libcxxabi_internal",
  511. ],
  512. )
  513. filegroup(
  514. name = "libcxx_archive",
  515. srcs = [":libcxx"],
  516. output_group = "archive",
  517. )
  518. carbon_runtimes_config(
  519. name = "runtimes_cfg",
  520. builtins_archive = ":builtins_archive",
  521. clang_hdrs_prefix = "llvm/lib/clang/{0}/include/".format(LLVM_VERSION_MAJOR),
  522. crt_copts = crt_copts + [
  523. # Disable all sanitizers for CRT objects.
  524. "-fno-sanitize=all",
  525. ],
  526. crtbegin_src = select({
  527. "@platforms//os:linux": ":builtins_crtbegin_src",
  528. "//conditions:default": None,
  529. }),
  530. crtend_src = select({
  531. "@platforms//os:linux": ":builtins_crtend_src",
  532. "//conditions:default": None,
  533. }),
  534. darwin_os_suffix = select({
  535. # TODO: Add support for tvOS, watchOS, and iOS variants with the
  536. # relevant Bazel constraints.
  537. ":is_macos_arm64": "osx",
  538. ":is_macos_x86_64": "osx",
  539. "//conditions:default": None,
  540. }),
  541. libcxx_archive = ":libcxx_archive",
  542. libunwind_archive = ":libunwind_archive",
  543. target_triple = select({
  544. # TODO: Add other triples (and if needed, constraints) so that we can
  545. # build the correct Clang resource-dir structure for each.
  546. ":is_freebsd_x86_64": "x86_64-unknown-freebsd",
  547. ":is_linux_aarch64": "aarch64-unknown-linux-gnu",
  548. ":is_linux_x86_64": "x86_64-unknown-linux-gnu",
  549. # Note that Darwin OSes are handled by the `darwin_os_suffix` attribute.
  550. "//conditions:default": None,
  551. }),
  552. )
  553. platforms = {
  554. "freebsd": ["x86_64"],
  555. "linux": [
  556. "aarch64",
  557. "x86_64",
  558. ],
  559. "macos": [
  560. "arm64",
  561. "x86_64",
  562. ],
  563. }
  564. [
  565. config_setting(
  566. name = "is_{0}_{1}".format(os, cpu),
  567. constraint_values = [
  568. "@platforms//os:{}".format(os),
  569. "@platforms//cpu:{}".format(cpu),
  570. ],
  571. )
  572. for os, cpus in platforms.items()
  573. for cpu in cpus
  574. ]
  575. carbon_bootstrapped_cc_toolchain(
  576. name = "carbon_stage1",
  577. all_hdrs = [
  578. ":clang_hdrs",
  579. ":libunwind_hdrs",
  580. ":libcxx_hdrs",
  581. ":libcxxabi_hdrs",
  582. ],
  583. base_files = [
  584. ":install_marker",
  585. ":carbon-busybox",
  586. ":llvm_bins",
  587. ],
  588. build_stage = 1,
  589. clang_hdrs = [":clang_hdrs"],
  590. platforms = platforms,
  591. runtimes_cfg = ":runtimes_cfg",
  592. )
  593. carbon_bootstrapped_cc_toolchain(
  594. name = "carbon_stage2",
  595. all_hdrs = [
  596. ":clang_hdrs",
  597. ":libunwind_hdrs",
  598. ":libcxx_hdrs",
  599. ":libcxxabi_hdrs",
  600. ],
  601. base_files = [
  602. ":install_marker",
  603. ":carbon-busybox",
  604. ":llvm_bins",
  605. ],
  606. base_stage = 1,
  607. build_stage = 2,
  608. clang_hdrs = [":clang_hdrs"],
  609. platforms = platforms,
  610. runtimes_cfg = ":runtimes_cfg",
  611. tags = ["manual"],
  612. )
  613. pkg_naming_variables(
  614. name = "packaging_variables",
  615. )
  616. toolchain_pkg_filegroup(
  617. name = "stage1_pkg_data",
  618. srcs = [
  619. "install_digest.txt",
  620. ":all_data_files",
  621. ],
  622. carbon_busybox = ":carbon-busybox",
  623. )
  624. # We build both a compressed and uncompressed tar file with the same code here.
  625. # This lets us use the tar file in testing as it is fast to create, but ship the
  626. # compressed version as a release.
  627. #
  628. # For manual tests, the tar rules are `carbon_toolchain_tar` and
  629. # `carbon_toolchain_tar_gz`.
  630. pkg_tar_and_test(
  631. name = "carbon_toolchain",
  632. srcs = [":stage1_pkg_data"],
  633. install_data_manifest = ":install_data_manifest.txt",
  634. package_dir = "carbon_toolchain-$(version)",
  635. package_file_name_base = "carbon_toolchain-$(version)",
  636. package_variables = ":packaging_variables",
  637. stamp = -1, # Allow `--stamp` builds to produce file timestamps.
  638. )
  639. filegroup_with_stage(
  640. name = "stage2_pkg_files",
  641. srcs = [
  642. ":all_data_files",
  643. ":gen_digest",
  644. ],
  645. stage = 1,
  646. tags = ["manual"],
  647. )
  648. filegroup_with_stage(
  649. name = "stage2_busybox",
  650. srcs = [":carbon-busybox"],
  651. stage = 1,
  652. tags = ["manual"],
  653. )
  654. toolchain_pkg_filegroup(
  655. name = "stage2_pkg_data",
  656. srcs = [":stage2_pkg_files"],
  657. carbon_busybox = ":stage2_busybox",
  658. tags = ["manual"],
  659. )
  660. pkg_tar_and_test(
  661. name = "carbon_bootstrapped_toolchain",
  662. srcs = [":stage2_pkg_data"],
  663. install_data_manifest = ":install_data_manifest.txt",
  664. package_dir = "carbon_toolchain-$(version)",
  665. package_file_name_base = "carbon_bootstrapped_toolchain-$(version)",
  666. package_variables = ":packaging_variables",
  667. stamp = -1, # Allow `--stamp` builds to produce file timestamps.
  668. tags = ["manual"],
  669. )
  670. filegroup(
  671. name = "built_runtimes",
  672. srcs = [":carbon_stage1_runtimes"],
  673. )
  674. py_test(
  675. name = "install_test",
  676. size = "large",
  677. srcs = ["install_test.py"],
  678. data = [
  679. ":built_runtimes",
  680. ":carbon-busybox",
  681. ":install_data",
  682. ],
  683. deps = ["@bazel_tools//tools/python/runfiles"],
  684. )
  685. # Generate paths file for stage 1 toolchain.
  686. gen_cc_toolchain_paths_with_stage(
  687. name = "gen_cc_tools_paths_stage1",
  688. stage = 1,
  689. )
  690. # Test that stage 1 toolchain's Make variables expand correctly.
  691. py_test(
  692. name = "cc_tools_stage1_test",
  693. srcs = ["cc_tools_wrapper_test.py"],
  694. args = ["$(location :gen_cc_tools_paths_stage1)"],
  695. data = [":gen_cc_tools_paths_stage1"],
  696. main = "cc_tools_wrapper_test.py",
  697. deps = ["//bazel/cc_toolchains:cc_tools_test_lib"],
  698. )
  699. # Generate paths file for stage 2 toolchain.
  700. gen_cc_toolchain_paths_with_stage(
  701. name = "gen_cc_tools_paths_stage2",
  702. stage = 2,
  703. tags = ["manual"],
  704. )
  705. # Test that stage 2 toolchain's Make variables expand correctly.
  706. py_test(
  707. name = "cc_tools_stage2_test",
  708. srcs = ["cc_tools_wrapper_test.py"],
  709. args = ["$(location :gen_cc_tools_paths_stage2)"],
  710. data = [":gen_cc_tools_paths_stage2"],
  711. main = "cc_tools_wrapper_test.py",
  712. tags = ["manual"],
  713. deps = ["//bazel/cc_toolchains:cc_tools_test_lib"],
  714. )