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::compile::{add_to_sysroot, run_cargo, rustc_cargo, std_cargo};
5 use crate::config::TargetSelection;
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: TargetSelection,
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(
52 cargo_subcommand(builder.kind),
54 std_cargo(builder, target, compiler.stage, &mut cargo);
56 builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
61 &libstd_stamp(builder, compiler, target),
66 let libdir = builder.sysroot_libdir(compiler, target);
67 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
68 add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
72 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
74 pub target: TargetSelection,
79 const ONLY_HOSTS: bool = true;
80 const DEFAULT: bool = true;
82 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
83 run.all_krates("rustc-main")
86 fn make_run(run: RunConfig<'_>) {
87 run.builder.ensure(Rustc { target: run.target });
90 /// Builds the compiler.
92 /// This will build the compiler for a particular stage of the build using
93 /// the `compiler` targeting the `target` architecture. The artifacts
94 /// created will also be linked into the sysroot directory.
95 fn run(self, builder: &Builder<'_>) {
96 let compiler = builder.compiler(0, builder.config.build);
97 let target = self.target;
99 builder.ensure(Std { target });
101 let mut cargo = builder.cargo(
106 cargo_subcommand(builder.kind),
108 rustc_cargo(builder, &mut cargo, target);
110 builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
115 &librustc_stamp(builder, compiler, target),
120 let libdir = builder.sysroot_libdir(compiler, target);
121 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
122 add_to_sysroot(&builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
126 macro_rules! tool_check_step {
127 ($name:ident, $path:expr, $source_type:expr) => {
128 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
130 pub target: TargetSelection,
133 impl Step for $name {
135 const ONLY_HOSTS: bool = true;
136 const DEFAULT: bool = true;
138 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
142 fn make_run(run: RunConfig<'_>) {
143 run.builder.ensure($name { target: run.target });
146 fn run(self, builder: &Builder<'_>) {
147 let compiler = builder.compiler(0, builder.config.build);
148 let target = self.target;
150 builder.ensure(Rustc { target });
152 let cargo = prepare_tool_cargo(
157 cargo_subcommand(builder.kind),
164 "Checking {} artifacts ({} -> {})",
165 stringify!($name).to_lowercase(),
166 &compiler.host.triple,
173 &stamp(builder, compiler, target),
178 let libdir = builder.sysroot_libdir(compiler, target);
179 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
180 add_to_sysroot(&builder, &libdir, &hostdir, &stamp(builder, compiler, target));
182 /// Cargo's output path in a given stage, compiled by a particular
183 /// compiler for the specified target.
185 builder: &Builder<'_>,
187 target: TargetSelection,
190 .cargo_out(compiler, Mode::ToolRustc, target)
191 .join(format!(".{}-check.stamp", stringify!($name).to_lowercase()))
198 tool_check_step!(Rustdoc, "src/tools/rustdoc", SourceType::InTree);
199 // Clippy is a hybrid. It is an external tool, but uses a git subtree instead
200 // of a submodule. Since the SourceType only drives the deny-warnings
201 // behavior, treat it as in-tree so that any new warnings in clippy will be
203 tool_check_step!(Clippy, "src/tools/clippy", SourceType::InTree);
205 /// Cargo's output path for the standard library in a given stage, compiled
206 /// by a particular compiler for the specified target.
207 fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
208 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
211 /// Cargo's output path for librustc in a given stage, compiled by a particular
212 /// compiler for the specified target.
213 fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
214 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")