1 //! Implementation of compiling the compiler and standard library, in "check"-based modes.
3 use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
4 use crate::cache::Interned;
5 use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, std_cargo};
6 use crate::tool::{prepare_tool_cargo, SourceType};
7 use crate::{Compiler, Mode};
8 use std::path::PathBuf;
10 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
12 pub target: Interned<String>,
15 fn args(kind: Kind) -> Vec<String> {
17 Kind::Clippy => vec!["--".to_owned(), "--cap-lints".to_owned(), "warn".to_owned()],
22 fn cargo_subcommand(kind: Kind) -> &'static str {
24 Kind::Check => "check",
25 Kind::Clippy => "clippy",
33 const DEFAULT: bool = true;
35 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
36 run.all_krates("test")
39 fn make_run(run: RunConfig<'_>) {
40 run.builder.ensure(Std { target: run.target });
43 fn run(self, builder: &Builder<'_>) {
44 let target = self.target;
45 let compiler = builder.compiler(0, builder.config.build);
47 let mut cargo = builder.cargo(compiler, Mode::Std, target, cargo_subcommand(builder.kind));
48 std_cargo(builder, &compiler, target, &mut cargo);
50 builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
55 &libstd_stamp(builder, compiler, target),
60 let libdir = builder.sysroot_libdir(compiler, target);
61 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
62 add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
66 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
68 pub target: Interned<String>,
73 const ONLY_HOSTS: bool = true;
74 const DEFAULT: bool = true;
76 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
77 run.all_krates("rustc-main")
80 fn make_run(run: RunConfig<'_>) {
81 run.builder.ensure(Rustc { target: run.target });
84 /// Builds the compiler.
86 /// This will build the compiler for a particular stage of the build using
87 /// the `compiler` targeting the `target` architecture. The artifacts
88 /// created will also be linked into the sysroot directory.
89 fn run(self, builder: &Builder<'_>) {
90 let compiler = builder.compiler(0, builder.config.build);
91 let target = self.target;
93 builder.ensure(Std { target });
96 builder.cargo(compiler, Mode::Rustc, target, cargo_subcommand(builder.kind));
97 rustc_cargo(builder, &mut cargo, target);
99 builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
104 &librustc_stamp(builder, compiler, target),
109 let libdir = builder.sysroot_libdir(compiler, target);
110 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
111 add_to_sysroot(&builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
115 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
117 pub target: Interned<String>,
120 impl Step for Rustdoc {
122 const ONLY_HOSTS: bool = true;
123 const DEFAULT: bool = true;
125 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
126 run.path("src/tools/rustdoc")
129 fn make_run(run: RunConfig<'_>) {
130 run.builder.ensure(Rustdoc { target: run.target });
133 fn run(self, builder: &Builder<'_>) {
134 let compiler = builder.compiler(0, builder.config.build);
135 let target = self.target;
137 builder.ensure(Rustc { target });
139 let cargo = prepare_tool_cargo(
144 cargo_subcommand(builder.kind),
150 println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
155 &rustdoc_stamp(builder, compiler, target),
160 let libdir = builder.sysroot_libdir(compiler, target);
161 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
162 add_to_sysroot(&builder, &libdir, &hostdir, &rustdoc_stamp(builder, compiler, target));
166 /// Cargo's output path for the standard library in a given stage, compiled
167 /// by a particular compiler for the specified target.
169 builder: &Builder<'_>,
171 target: Interned<String>,
173 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
176 /// Cargo's output path for librustc in a given stage, compiled by a particular
177 /// compiler for the specified target.
178 pub fn librustc_stamp(
179 builder: &Builder<'_>,
181 target: Interned<String>,
183 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
186 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
187 /// compiler for the specified target.
188 pub fn rustdoc_stamp(
189 builder: &Builder<'_>,
191 target: Interned<String>,
193 builder.cargo_out(compiler, Mode::ToolRustc, target).join(".rustdoc-check.stamp")