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 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
46 add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
50 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
52 pub target: Interned<String>,
57 const ONLY_HOSTS: bool = true;
58 const DEFAULT: bool = true;
60 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
61 run.all_krates("rustc-main")
64 fn make_run(run: RunConfig<'_>) {
65 run.builder.ensure(Rustc {
70 /// Builds the compiler.
72 /// This will build the compiler for a particular stage of the build using
73 /// the `compiler` targeting the `target` architecture. The artifacts
74 /// created will also be linked into the sysroot directory.
75 fn run(self, builder: &Builder<'_>) {
76 let compiler = builder.compiler(0, builder.config.build);
77 let target = self.target;
79 builder.ensure(Test { target });
81 let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "check");
82 rustc_cargo(builder, &mut cargo);
84 let _folder = builder.fold_output(|| format!("stage{}-rustc", compiler.stage));
85 builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
88 &librustc_stamp(builder, compiler, target),
91 let libdir = builder.sysroot_libdir(compiler, target);
92 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
93 add_to_sysroot(&builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
97 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
98 pub struct CodegenBackend {
99 pub target: Interned<String>,
100 pub backend: Interned<String>,
103 impl Step for CodegenBackend {
105 const ONLY_HOSTS: bool = true;
106 const DEFAULT: bool = true;
108 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
109 run.all_krates("rustc_codegen_llvm")
112 fn make_run(run: RunConfig<'_>) {
113 let backend = run.builder.config.rust_codegen_backends.get(0);
114 let backend = backend.cloned().unwrap_or_else(|| {
115 INTERNER.intern_str("llvm")
117 run.builder.ensure(CodegenBackend {
123 fn run(self, builder: &Builder<'_>) {
124 let compiler = builder.compiler(0, builder.config.build);
125 let target = self.target;
126 let backend = self.backend;
128 builder.ensure(Rustc { target });
130 let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "check");
131 cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
132 rustc_cargo_env(builder, &mut cargo);
134 // We won't build LLVM if it's not available, as it shouldn't affect `check`.
136 let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
139 &codegen_backend_stamp(builder, compiler, target, backend),
144 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
146 pub target: Interned<String>,
151 const DEFAULT: bool = true;
153 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
154 run.all_krates("test")
157 fn make_run(run: RunConfig<'_>) {
158 run.builder.ensure(Test {
163 fn run(self, builder: &Builder<'_>) {
164 let compiler = builder.compiler(0, builder.config.build);
165 let target = self.target;
167 builder.ensure(Std { target });
169 let mut cargo = builder.cargo(compiler, Mode::Test, target, "check");
170 test_cargo(builder, &compiler, target, &mut cargo);
172 let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
173 builder.info(&format!("Checking test artifacts ({} -> {})", &compiler.host, target));
176 &libtest_stamp(builder, compiler, target),
179 let libdir = builder.sysroot_libdir(compiler, target);
180 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
181 add_to_sysroot(builder, &libdir, &hostdir, &libtest_stamp(builder, compiler, target));
185 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
187 pub target: Interned<String>,
190 impl Step for Rustdoc {
192 const ONLY_HOSTS: bool = true;
193 const DEFAULT: bool = true;
195 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
196 run.path("src/tools/rustdoc")
199 fn make_run(run: RunConfig<'_>) {
200 run.builder.ensure(Rustdoc {
205 fn run(self, builder: &Builder<'_>) {
206 let compiler = builder.compiler(0, builder.config.build);
207 let target = self.target;
209 builder.ensure(Rustc { target });
211 let mut cargo = prepare_tool_cargo(builder,
220 let _folder = builder.fold_output(|| format!("stage{}-rustdoc", compiler.stage));
221 println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
224 &rustdoc_stamp(builder, compiler, target),
227 let libdir = builder.sysroot_libdir(compiler, target);
228 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
229 add_to_sysroot(&builder, &libdir, &hostdir, &rustdoc_stamp(builder, compiler, target));
230 builder.cargo(compiler, Mode::ToolRustc, target, "clean");
234 /// Cargo's output path for the standard library in a given stage, compiled
235 /// by a particular compiler for the specified target.
237 builder: &Builder<'_>,
239 target: Interned<String>,
241 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
244 /// Cargo's output path for libtest in a given stage, compiled by a particular
245 /// compiler for the specified target.
246 pub fn libtest_stamp(
247 builder: &Builder<'_>,
249 target: Interned<String>,
251 builder.cargo_out(compiler, Mode::Test, target).join(".libtest-check.stamp")
254 /// Cargo's output path for librustc in a given stage, compiled by a particular
255 /// compiler for the specified target.
256 pub fn librustc_stamp(
257 builder: &Builder<'_>,
259 target: Interned<String>,
261 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
264 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
265 /// compiler for the specified target and backend.
266 fn codegen_backend_stamp(builder: &Builder<'_>,
268 target: Interned<String>,
269 backend: Interned<String>) -> PathBuf {
270 builder.cargo_out(compiler, Mode::Codegen, target)
271 .join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
274 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
275 /// compiler for the specified target.
276 pub fn rustdoc_stamp(
277 builder: &Builder<'_>,
279 target: Interned<String>,
281 builder.cargo_out(compiler, Mode::ToolRustc, target)
282 .join(".rustdoc-check.stamp")