]> git.proxmox.com Git - rustc.git/blob - src/bootstrap/check.rs
New upstream version 1.45.0+dfsg1
[rustc.git] / src / bootstrap / check.rs
1 //! Implementation of compiling the compiler and standard library, in "check"-based modes.
2
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;
9
10 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
11 pub struct Std {
12 pub target: Interned<String>,
13 }
14
15 fn args(kind: Kind) -> Vec<String> {
16 match kind {
17 Kind::Clippy => vec!["--".to_owned(), "--cap-lints".to_owned(), "warn".to_owned()],
18 _ => Vec::new(),
19 }
20 }
21
22 fn cargo_subcommand(kind: Kind) -> &'static str {
23 match kind {
24 Kind::Check => "check",
25 Kind::Clippy => "clippy",
26 Kind::Fix => "fix",
27 _ => unreachable!(),
28 }
29 }
30
31 impl Step for Std {
32 type Output = ();
33 const DEFAULT: bool = true;
34
35 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
36 run.all_krates("test")
37 }
38
39 fn make_run(run: RunConfig<'_>) {
40 run.builder.ensure(Std { target: run.target });
41 }
42
43 fn run(self, builder: &Builder<'_>) {
44 let target = self.target;
45 let compiler = builder.compiler(0, builder.config.build);
46
47 let mut cargo = builder.cargo(compiler, Mode::Std, target, cargo_subcommand(builder.kind));
48 std_cargo(builder, target, compiler.stage, &mut cargo);
49
50 builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
51 run_cargo(
52 builder,
53 cargo,
54 args(builder.kind),
55 &libstd_stamp(builder, compiler, target),
56 vec![],
57 true,
58 );
59
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));
63 }
64 }
65
66 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
67 pub struct Rustc {
68 pub target: Interned<String>,
69 }
70
71 impl Step for Rustc {
72 type Output = ();
73 const ONLY_HOSTS: bool = true;
74 const DEFAULT: bool = true;
75
76 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
77 run.all_krates("rustc-main")
78 }
79
80 fn make_run(run: RunConfig<'_>) {
81 run.builder.ensure(Rustc { target: run.target });
82 }
83
84 /// Builds the compiler.
85 ///
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;
92
93 builder.ensure(Std { target });
94
95 let mut cargo =
96 builder.cargo(compiler, Mode::Rustc, target, cargo_subcommand(builder.kind));
97 rustc_cargo(builder, &mut cargo, target);
98
99 builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
100 run_cargo(
101 builder,
102 cargo,
103 args(builder.kind),
104 &librustc_stamp(builder, compiler, target),
105 vec![],
106 true,
107 );
108
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));
112 }
113 }
114
115 macro_rules! tool_check_step {
116 ($name:ident, $path:expr) => {
117 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
118 pub struct $name {
119 pub target: Interned<String>,
120 }
121
122 impl Step for $name {
123 type Output = ();
124 const ONLY_HOSTS: bool = true;
125 const DEFAULT: bool = true;
126
127 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
128 run.path($path)
129 }
130
131 fn make_run(run: RunConfig<'_>) {
132 run.builder.ensure($name { target: run.target });
133 }
134
135 fn run(self, builder: &Builder<'_>) {
136 let compiler = builder.compiler(0, builder.config.build);
137 let target = self.target;
138
139 builder.ensure(Rustc { target });
140
141 let cargo = prepare_tool_cargo(
142 builder,
143 compiler,
144 Mode::ToolRustc,
145 target,
146 cargo_subcommand(builder.kind),
147 $path,
148 SourceType::InTree,
149 &[],
150 );
151
152 println!(
153 "Checking {} artifacts ({} -> {})",
154 stringify!($name).to_lowercase(),
155 &compiler.host,
156 target
157 );
158 run_cargo(
159 builder,
160 cargo,
161 args(builder.kind),
162 &stamp(builder, compiler, target),
163 vec![],
164 true,
165 );
166
167 let libdir = builder.sysroot_libdir(compiler, target);
168 let hostdir = builder.sysroot_libdir(compiler, compiler.host);
169 add_to_sysroot(&builder, &libdir, &hostdir, &stamp(builder, compiler, target));
170
171 /// Cargo's output path in a given stage, compiled by a particular
172 /// compiler for the specified target.
173 fn stamp(
174 builder: &Builder<'_>,
175 compiler: Compiler,
176 target: Interned<String>,
177 ) -> PathBuf {
178 builder
179 .cargo_out(compiler, Mode::ToolRustc, target)
180 .join(format!(".{}-check.stamp", stringify!($name).to_lowercase()))
181 }
182 }
183 }
184 };
185 }
186
187 tool_check_step!(Rustdoc, "src/tools/rustdoc");
188 tool_check_step!(Clippy, "src/tools/clippy");
189
190 /// Cargo's output path for the standard library in a given stage, compiled
191 /// by a particular compiler for the specified target.
192 fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: Interned<String>) -> PathBuf {
193 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
194 }
195
196 /// Cargo's output path for librustc in a given stage, compiled by a particular
197 /// compiler for the specified target.
198 fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: Interned<String>) -> PathBuf {
199 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
200 }