1 //! Implementation of compiling the compiler and standard library, in "check"-based modes.
3 use crate::compile::{run_cargo, std_cargo, test_cargo, rustc_cargo, rustc_cargo_env,
5 use crate::builder::{RunConfig, Builder, Kind, 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>,
16 fn args(kind: Kind) -> Vec<String> {
18 Kind::Clippy => vec!["--".to_owned(), "--cap-lints".to_owned(), "warn".to_owned()],
23 fn cargo_subcommand(kind: Kind) -> &'static str {
25 Kind::Check => "check",
26 Kind::Clippy => "clippy",
34 const DEFAULT: bool = true;
36 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
40 fn make_run(run: RunConfig<'_>) {
41 run.builder.ensure(Std {
46 fn run(self, builder: &Builder<'_>) {
47 let target = self.target;
48 let compiler = builder.compiler(0, builder.config.build);
50 let mut cargo = builder.cargo(compiler, Mode::Std, target, cargo_subcommand(builder.kind));
51 std_cargo(builder, &compiler, target, &mut cargo);
53 let _folder = builder.fold_output(|| format!("stage{}-std", compiler.stage));
54 builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
58 &libstd_stamp(builder, compiler, target),
61 let libdir = builder.sysroot_libdir(compiler, target);
62 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
63 add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
67 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
69 pub target: Interned<String>,
74 const ONLY_HOSTS: bool = true;
75 const DEFAULT: bool = true;
77 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
78 run.all_krates("rustc-main")
81 fn make_run(run: RunConfig<'_>) {
82 run.builder.ensure(Rustc {
87 /// Builds the compiler.
89 /// This will build the compiler for a particular stage of the build using
90 /// the `compiler` targeting the `target` architecture. The artifacts
91 /// created will also be linked into the sysroot directory.
92 fn run(self, builder: &Builder<'_>) {
93 let compiler = builder.compiler(0, builder.config.build);
94 let target = self.target;
96 builder.ensure(Test { target });
98 let mut cargo = builder.cargo(compiler, Mode::Rustc, target,
99 cargo_subcommand(builder.kind));
100 rustc_cargo(builder, &mut cargo);
102 let _folder = builder.fold_output(|| format!("stage{}-rustc", compiler.stage));
103 builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
107 &librustc_stamp(builder, compiler, target),
110 let libdir = builder.sysroot_libdir(compiler, target);
111 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
112 add_to_sysroot(&builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
116 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
117 pub struct CodegenBackend {
118 pub target: Interned<String>,
119 pub backend: Interned<String>,
122 impl Step for CodegenBackend {
124 const ONLY_HOSTS: bool = true;
125 const DEFAULT: bool = true;
127 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
128 run.all_krates("rustc_codegen_llvm")
131 fn make_run(run: RunConfig<'_>) {
132 let backend = run.builder.config.rust_codegen_backends.get(0);
133 let backend = backend.cloned().unwrap_or_else(|| {
134 INTERNER.intern_str("llvm")
136 run.builder.ensure(CodegenBackend {
142 fn run(self, builder: &Builder<'_>) {
143 let compiler = builder.compiler(0, builder.config.build);
144 let target = self.target;
145 let backend = self.backend;
147 builder.ensure(Rustc { target });
149 let mut cargo = builder.cargo(compiler, Mode::Codegen, target,
150 cargo_subcommand(builder.kind));
151 cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
152 rustc_cargo_env(builder, &mut cargo);
154 // We won't build LLVM if it's not available, as it shouldn't affect `check`.
156 let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
160 &codegen_backend_stamp(builder, compiler, target, backend),
165 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
167 pub target: Interned<String>,
172 const DEFAULT: bool = true;
174 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
175 run.all_krates("test")
178 fn make_run(run: RunConfig<'_>) {
179 run.builder.ensure(Test {
184 fn run(self, builder: &Builder<'_>) {
185 let compiler = builder.compiler(0, builder.config.build);
186 let target = self.target;
188 builder.ensure(Std { target });
190 let mut cargo = builder.cargo(compiler, Mode::Test, target, cargo_subcommand(builder.kind));
191 test_cargo(builder, &compiler, target, &mut cargo);
193 let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
194 builder.info(&format!("Checking test artifacts ({} -> {})", &compiler.host, target));
198 &libtest_stamp(builder, compiler, target),
201 let libdir = builder.sysroot_libdir(compiler, target);
202 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
203 add_to_sysroot(builder, &libdir, &hostdir, &libtest_stamp(builder, compiler, target));
207 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
209 pub target: Interned<String>,
212 impl Step for Rustdoc {
214 const ONLY_HOSTS: bool = true;
215 const DEFAULT: bool = true;
217 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
218 run.path("src/tools/rustdoc")
221 fn make_run(run: RunConfig<'_>) {
222 run.builder.ensure(Rustdoc {
227 fn run(self, builder: &Builder<'_>) {
228 let compiler = builder.compiler(0, builder.config.build);
229 let target = self.target;
231 builder.ensure(Rustc { target });
233 let mut cargo = prepare_tool_cargo(builder,
237 cargo_subcommand(builder.kind),
242 let _folder = builder.fold_output(|| format!("stage{}-rustdoc", compiler.stage));
243 println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
247 &rustdoc_stamp(builder, compiler, target),
250 let libdir = builder.sysroot_libdir(compiler, target);
251 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
252 add_to_sysroot(&builder, &libdir, &hostdir, &rustdoc_stamp(builder, compiler, target));
253 builder.cargo(compiler, Mode::ToolRustc, target, "clean");
257 /// Cargo's output path for the standard library in a given stage, compiled
258 /// by a particular compiler for the specified target.
260 builder: &Builder<'_>,
262 target: Interned<String>,
264 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
267 /// Cargo's output path for libtest in a given stage, compiled by a particular
268 /// compiler for the specified target.
269 pub fn libtest_stamp(
270 builder: &Builder<'_>,
272 target: Interned<String>,
274 builder.cargo_out(compiler, Mode::Test, target).join(".libtest-check.stamp")
277 /// Cargo's output path for librustc in a given stage, compiled by a particular
278 /// compiler for the specified target.
279 pub fn librustc_stamp(
280 builder: &Builder<'_>,
282 target: Interned<String>,
284 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
287 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
288 /// compiler for the specified target and backend.
289 fn codegen_backend_stamp(builder: &Builder<'_>,
291 target: Interned<String>,
292 backend: Interned<String>) -> PathBuf {
293 builder.cargo_out(compiler, Mode::Codegen, target)
294 .join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
297 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
298 /// compiler for the specified target.
299 pub fn rustdoc_stamp(
300 builder: &Builder<'_>,
302 target: Interned<String>,
304 builder.cargo_out(compiler, Mode::ToolRustc, target)
305 .join(".rustdoc-check.stamp")