1 //! Implementation of compiling the compiler and standard library, in "check" mode.
3 use crate::compile::{run_cargo, std_cargo, test_cargo, rustc_cargo, rustc_cargo_env,
5 use crate::builder::{RunConfig, Builder, ShouldRun, Step};
6 use crate::tool::{prepare_tool_cargo, SourceType};
7 use crate::{Compiler, Mode};
8 use crate::cache::{INTERNER, Interned};
9 use std::path::PathBuf;
11 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
13 pub target: Interned<String>,
18 const DEFAULT: bool = true;
20 fn should_run(run: ShouldRun) -> ShouldRun {
24 fn make_run(run: RunConfig) {
25 run.builder.ensure(Std {
30 fn run(self, builder: &Builder) {
31 let target = self.target;
32 let compiler = builder.compiler(0, builder.config.build);
34 let mut cargo = builder.cargo(compiler, Mode::Std, target, "check");
35 std_cargo(builder, &compiler, target, &mut cargo);
37 let _folder = builder.fold_output(|| format!("stage{}-std", compiler.stage));
38 builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
41 &libstd_stamp(builder, compiler, target),
44 let libdir = builder.sysroot_libdir(compiler, target);
45 add_to_sysroot(&builder, &libdir, &libstd_stamp(builder, compiler, target));
49 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
51 pub target: Interned<String>,
56 const ONLY_HOSTS: bool = true;
57 const DEFAULT: bool = true;
59 fn should_run(run: ShouldRun) -> ShouldRun {
60 run.all_krates("rustc-main")
63 fn make_run(run: RunConfig) {
64 run.builder.ensure(Rustc {
69 /// Builds the compiler.
71 /// This will build the compiler for a particular stage of the build using
72 /// the `compiler` targeting the `target` architecture. The artifacts
73 /// created will also be linked into the sysroot directory.
74 fn run(self, builder: &Builder) {
75 let compiler = builder.compiler(0, builder.config.build);
76 let target = self.target;
78 builder.ensure(Test { target });
80 let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "check");
81 rustc_cargo(builder, &mut cargo);
83 let _folder = builder.fold_output(|| format!("stage{}-rustc", compiler.stage));
84 builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
87 &librustc_stamp(builder, compiler, target),
90 let libdir = builder.sysroot_libdir(compiler, target);
91 add_to_sysroot(&builder, &libdir, &librustc_stamp(builder, compiler, target));
95 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
96 pub struct CodegenBackend {
97 pub target: Interned<String>,
98 pub backend: Interned<String>,
101 impl Step for CodegenBackend {
103 const ONLY_HOSTS: bool = true;
104 const DEFAULT: bool = true;
106 fn should_run(run: ShouldRun) -> ShouldRun {
107 run.all_krates("rustc_codegen_llvm")
110 fn make_run(run: RunConfig) {
111 let backend = run.builder.config.rust_codegen_backends.get(0);
112 let backend = backend.cloned().unwrap_or_else(|| {
113 INTERNER.intern_str("llvm")
115 run.builder.ensure(CodegenBackend {
121 fn run(self, builder: &Builder) {
122 let compiler = builder.compiler(0, builder.config.build);
123 let target = self.target;
124 let backend = self.backend;
126 builder.ensure(Rustc { target });
128 let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "check");
129 cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
130 rustc_cargo_env(builder, &mut cargo);
132 // We won't build LLVM if it's not available, as it shouldn't affect `check`.
134 let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
137 &codegen_backend_stamp(builder, compiler, target, backend),
142 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
144 pub target: Interned<String>,
149 const DEFAULT: bool = true;
151 fn should_run(run: ShouldRun) -> ShouldRun {
152 run.all_krates("test")
155 fn make_run(run: RunConfig) {
156 run.builder.ensure(Test {
161 fn run(self, builder: &Builder) {
162 let compiler = builder.compiler(0, builder.config.build);
163 let target = self.target;
165 builder.ensure(Std { target });
167 let mut cargo = builder.cargo(compiler, Mode::Test, target, "check");
168 test_cargo(builder, &compiler, target, &mut cargo);
170 let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
171 builder.info(&format!("Checking test artifacts ({} -> {})", &compiler.host, target));
174 &libtest_stamp(builder, compiler, target),
177 let libdir = builder.sysroot_libdir(compiler, target);
178 add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target));
182 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
184 pub target: Interned<String>,
187 impl Step for Rustdoc {
189 const ONLY_HOSTS: bool = true;
190 const DEFAULT: bool = true;
192 fn should_run(run: ShouldRun) -> ShouldRun {
193 run.path("src/tools/rustdoc")
196 fn make_run(run: RunConfig) {
197 run.builder.ensure(Rustdoc {
202 fn run(self, builder: &Builder) {
203 let compiler = builder.compiler(0, builder.config.build);
204 let target = self.target;
206 builder.ensure(Rustc { target });
208 let mut cargo = prepare_tool_cargo(builder,
217 let _folder = builder.fold_output(|| format!("stage{}-rustdoc", compiler.stage));
218 println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
221 &rustdoc_stamp(builder, compiler, target),
224 let libdir = builder.sysroot_libdir(compiler, target);
225 add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target));
226 builder.cargo(compiler, Mode::ToolRustc, target, "clean");
230 /// Cargo's output path for the standard library in a given stage, compiled
231 /// by a particular compiler for the specified target.
232 pub fn libstd_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
233 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
236 /// Cargo's output path for libtest in a given stage, compiled by a particular
237 /// compiler for the specified target.
238 pub fn libtest_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
239 builder.cargo_out(compiler, Mode::Test, target).join(".libtest-check.stamp")
242 /// Cargo's output path for librustc in a given stage, compiled by a particular
243 /// compiler for the specified target.
244 pub fn librustc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
245 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
248 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
249 /// compiler for the specified target and backend.
250 fn codegen_backend_stamp(builder: &Builder,
252 target: Interned<String>,
253 backend: Interned<String>) -> PathBuf {
254 builder.cargo_out(compiler, Mode::Codegen, target)
255 .join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
258 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
259 /// compiler for the specified target.
260 pub fn rustdoc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
261 builder.cargo_out(compiler, Mode::ToolRustc, target)
262 .join(".rustdoc-check.stamp")