1 //! Implementation of compiling the compiler and standard library, in "check"-based modes.
3 use crate::compile::{run_cargo, std_cargo, rustc_cargo, add_to_sysroot};
4 use crate::builder::{RunConfig, Builder, Kind, ShouldRun, Step};
5 use crate::tool::{prepare_tool_cargo, SourceType};
6 use crate::{Compiler, Mode};
7 use crate::cache::Interned;
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 {
45 fn run(self, builder: &Builder<'_>) {
46 let target = self.target;
47 let compiler = builder.compiler(0, builder.config.build);
49 let mut cargo = builder.cargo(compiler, Mode::Std, target, cargo_subcommand(builder.kind));
50 std_cargo(builder, &compiler, target, &mut cargo);
52 builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
56 &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 {
86 /// Builds the compiler.
88 /// This will build the compiler for a particular stage of the build using
89 /// the `compiler` targeting the `target` architecture. The artifacts
90 /// created will also be linked into the sysroot directory.
91 fn run(self, builder: &Builder<'_>) {
92 let compiler = builder.compiler(0, builder.config.build);
93 let target = self.target;
95 builder.ensure(Std { target });
97 let mut cargo = builder.cargo(compiler, Mode::Rustc, target,
98 cargo_subcommand(builder.kind));
99 rustc_cargo(builder, &mut cargo, target);
101 builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
105 &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 {
135 fn run(self, builder: &Builder<'_>) {
136 let compiler = builder.compiler(0, builder.config.build);
137 let target = self.target;
139 builder.ensure(Rustc { target });
141 let cargo = prepare_tool_cargo(builder,
145 cargo_subcommand(builder.kind),
150 println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
154 &rustdoc_stamp(builder, compiler, target),
158 let libdir = builder.sysroot_libdir(compiler, target);
159 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
160 add_to_sysroot(&builder, &libdir, &hostdir, &rustdoc_stamp(builder, compiler, target));
164 /// Cargo's output path for the standard library in a given stage, compiled
165 /// by a particular compiler for the specified target.
167 builder: &Builder<'_>,
169 target: Interned<String>,
171 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
174 /// Cargo's output path for librustc in a given stage, compiled by a particular
175 /// compiler for the specified target.
176 pub fn librustc_stamp(
177 builder: &Builder<'_>,
179 target: Interned<String>,
181 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
184 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
185 /// compiler for the specified target.
186 pub fn rustdoc_stamp(
187 builder: &Builder<'_>,
189 target: Interned<String>,
191 builder.cargo_out(compiler, Mode::ToolRustc, target)
192 .join(".rustdoc-check.stamp")