1 //! Implementation of compiling the compiler and standard library, in "check"-based modes.
3 use crate::compile::{run_cargo, std_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<'_> {
37 run.all_krates("test")
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),
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(Std { target });
98 let mut cargo = builder.cargo(compiler, Mode::Rustc, target,
99 cargo_subcommand(builder.kind));
100 rustc_cargo(builder, &mut cargo);
102 builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
106 &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`.
159 &codegen_backend_stamp(builder, compiler, target, backend),
165 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
167 pub target: Interned<String>,
170 impl Step for Rustdoc {
172 const ONLY_HOSTS: bool = true;
173 const DEFAULT: bool = true;
175 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
176 run.path("src/tools/rustdoc")
179 fn make_run(run: RunConfig<'_>) {
180 run.builder.ensure(Rustdoc {
185 fn run(self, builder: &Builder<'_>) {
186 let compiler = builder.compiler(0, builder.config.build);
187 let target = self.target;
189 builder.ensure(Rustc { target });
191 let cargo = prepare_tool_cargo(builder,
195 cargo_subcommand(builder.kind),
200 println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
204 &rustdoc_stamp(builder, compiler, target),
208 let libdir = builder.sysroot_libdir(compiler, target);
209 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
210 add_to_sysroot(&builder, &libdir, &hostdir, &rustdoc_stamp(builder, compiler, target));
214 /// Cargo's output path for the standard library in a given stage, compiled
215 /// by a particular compiler for the specified target.
217 builder: &Builder<'_>,
219 target: Interned<String>,
221 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
224 /// Cargo's output path for librustc in a given stage, compiled by a particular
225 /// compiler for the specified target.
226 pub fn librustc_stamp(
227 builder: &Builder<'_>,
229 target: Interned<String>,
231 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
234 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
235 /// compiler for the specified target and backend.
236 fn codegen_backend_stamp(builder: &Builder<'_>,
238 target: Interned<String>,
239 backend: Interned<String>) -> PathBuf {
240 builder.cargo_out(compiler, Mode::Codegen, target)
241 .join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
244 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
245 /// compiler for the specified target.
246 pub fn rustdoc_stamp(
247 builder: &Builder<'_>,
249 target: Interned<String>,
251 builder.cargo_out(compiler, Mode::ToolRustc, target)
252 .join(".rustdoc-check.stamp")