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 builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
57 &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(Test { target });
97 let mut cargo = builder.cargo(compiler, Mode::Rustc, target,
98 cargo_subcommand(builder.kind));
99 rustc_cargo(builder, &mut cargo);
101 builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
105 &librustc_stamp(builder, compiler, target),
108 let libdir = builder.sysroot_libdir(compiler, target);
109 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
110 add_to_sysroot(&builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
114 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
115 pub struct CodegenBackend {
116 pub target: Interned<String>,
117 pub backend: Interned<String>,
120 impl Step for CodegenBackend {
122 const ONLY_HOSTS: bool = true;
123 const DEFAULT: bool = true;
125 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
126 run.all_krates("rustc_codegen_llvm")
129 fn make_run(run: RunConfig<'_>) {
130 let backend = run.builder.config.rust_codegen_backends.get(0);
131 let backend = backend.cloned().unwrap_or_else(|| {
132 INTERNER.intern_str("llvm")
134 run.builder.ensure(CodegenBackend {
140 fn run(self, builder: &Builder<'_>) {
141 let compiler = builder.compiler(0, builder.config.build);
142 let target = self.target;
143 let backend = self.backend;
145 builder.ensure(Rustc { target });
147 let mut cargo = builder.cargo(compiler, Mode::Codegen, target,
148 cargo_subcommand(builder.kind));
149 cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
150 rustc_cargo_env(builder, &mut cargo);
152 // We won't build LLVM if it's not available, as it shouldn't affect `check`.
157 &codegen_backend_stamp(builder, compiler, target, backend),
162 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
164 pub target: Interned<String>,
169 const DEFAULT: bool = true;
171 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
172 run.all_krates("test")
175 fn make_run(run: RunConfig<'_>) {
176 run.builder.ensure(Test {
181 fn run(self, builder: &Builder<'_>) {
182 let compiler = builder.compiler(0, builder.config.build);
183 let target = self.target;
185 builder.ensure(Std { target });
187 let mut cargo = builder.cargo(compiler, Mode::Test, target, cargo_subcommand(builder.kind));
188 test_cargo(builder, &compiler, target, &mut cargo);
190 builder.info(&format!("Checking test artifacts ({} -> {})", &compiler.host, target));
194 &libtest_stamp(builder, compiler, target),
197 let libdir = builder.sysroot_libdir(compiler, target);
198 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
199 add_to_sysroot(builder, &libdir, &hostdir, &libtest_stamp(builder, compiler, target));
203 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
205 pub target: Interned<String>,
208 impl Step for Rustdoc {
210 const ONLY_HOSTS: bool = true;
211 const DEFAULT: bool = true;
213 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
214 run.path("src/tools/rustdoc")
217 fn make_run(run: RunConfig<'_>) {
218 run.builder.ensure(Rustdoc {
223 fn run(self, builder: &Builder<'_>) {
224 let compiler = builder.compiler(0, builder.config.build);
225 let target = self.target;
227 builder.ensure(Rustc { target });
229 let mut cargo = prepare_tool_cargo(builder,
233 cargo_subcommand(builder.kind),
238 println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
242 &rustdoc_stamp(builder, compiler, target),
245 let libdir = builder.sysroot_libdir(compiler, target);
246 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
247 add_to_sysroot(&builder, &libdir, &hostdir, &rustdoc_stamp(builder, compiler, target));
248 builder.cargo(compiler, Mode::ToolRustc, target, "clean");
252 /// Cargo's output path for the standard library in a given stage, compiled
253 /// by a particular compiler for the specified target.
255 builder: &Builder<'_>,
257 target: Interned<String>,
259 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
262 /// Cargo's output path for libtest in a given stage, compiled by a particular
263 /// compiler for the specified target.
264 pub fn libtest_stamp(
265 builder: &Builder<'_>,
267 target: Interned<String>,
269 builder.cargo_out(compiler, Mode::Test, target).join(".libtest-check.stamp")
272 /// Cargo's output path for librustc in a given stage, compiled by a particular
273 /// compiler for the specified target.
274 pub fn librustc_stamp(
275 builder: &Builder<'_>,
277 target: Interned<String>,
279 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
282 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
283 /// compiler for the specified target and backend.
284 fn codegen_backend_stamp(builder: &Builder<'_>,
286 target: Interned<String>,
287 backend: Interned<String>) -> PathBuf {
288 builder.cargo_out(compiler, Mode::Codegen, target)
289 .join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
292 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
293 /// compiler for the specified target.
294 pub fn rustdoc_stamp(
295 builder: &Builder<'_>,
297 target: Interned<String>,
299 builder.cargo_out(compiler, Mode::ToolRustc, target)
300 .join(".rustdoc-check.stamp")