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.
233 builder: &Builder<'_>,
235 target: Interned<String>,
237 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
240 /// Cargo's output path for libtest in a given stage, compiled by a particular
241 /// compiler for the specified target.
242 pub fn libtest_stamp(
243 builder: &Builder<'_>,
245 target: Interned<String>,
247 builder.cargo_out(compiler, Mode::Test, target).join(".libtest-check.stamp")
250 /// Cargo's output path for librustc in a given stage, compiled by a particular
251 /// compiler for the specified target.
252 pub fn librustc_stamp(
253 builder: &Builder<'_>,
255 target: Interned<String>,
257 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
260 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
261 /// compiler for the specified target and backend.
262 fn codegen_backend_stamp(builder: &Builder<'_>,
264 target: Interned<String>,
265 backend: Interned<String>) -> PathBuf {
266 builder.cargo_out(compiler, Mode::Codegen, target)
267 .join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
270 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
271 /// compiler for the specified target.
272 pub fn rustdoc_stamp(
273 builder: &Builder<'_>,
275 target: Interned<String>,
277 builder.cargo_out(compiler, Mode::ToolRustc, target)
278 .join(".rustdoc-check.stamp")