]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/check.rs
Auto merge of #58972 - QuietMisdreavus:intra-doc-link-imports, r=GuillaumeGomez
[rust.git] / src / bootstrap / check.rs
1 //! Implementation of compiling the compiler and standard library, in "check" mode.
2
3 use crate::compile::{run_cargo, std_cargo, test_cargo, rustc_cargo, rustc_cargo_env,
4                      add_to_sysroot};
5 use crate::builder::{RunConfig, Builder, 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;
10
11 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
12 pub struct Std {
13     pub target: Interned<String>,
14 }
15
16 impl Step for Std {
17     type Output = ();
18     const DEFAULT: bool = true;
19
20     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
21         run.all_krates("std")
22     }
23
24     fn make_run(run: RunConfig<'_>) {
25         run.builder.ensure(Std {
26             target: run.target,
27         });
28     }
29
30     fn run(self, builder: &Builder<'_>) {
31         let target = self.target;
32         let compiler = builder.compiler(0, builder.config.build);
33
34         let mut cargo = builder.cargo(compiler, Mode::Std, target, "check");
35         std_cargo(builder, &compiler, target, &mut cargo);
36
37         let _folder = builder.fold_output(|| format!("stage{}-std", compiler.stage));
38         builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
39         run_cargo(builder,
40                   &mut cargo,
41                   &libstd_stamp(builder, compiler, target),
42                   true);
43
44         let libdir = builder.sysroot_libdir(compiler, target);
45         let hostdir = builder.sysroot_libdir(compiler, compiler.host);
46         add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
47     }
48 }
49
50 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
51 pub struct Rustc {
52     pub target: Interned<String>,
53 }
54
55 impl Step for Rustc {
56     type Output = ();
57     const ONLY_HOSTS: bool = true;
58     const DEFAULT: bool = true;
59
60     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
61         run.all_krates("rustc-main")
62     }
63
64     fn make_run(run: RunConfig<'_>) {
65         run.builder.ensure(Rustc {
66             target: run.target,
67         });
68     }
69
70     /// Builds the compiler.
71     ///
72     /// This will build the compiler for a particular stage of the build using
73     /// the `compiler` targeting the `target` architecture. The artifacts
74     /// created will also be linked into the sysroot directory.
75     fn run(self, builder: &Builder<'_>) {
76         let compiler = builder.compiler(0, builder.config.build);
77         let target = self.target;
78
79         builder.ensure(Test { target });
80
81         let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "check");
82         rustc_cargo(builder, &mut cargo);
83
84         let _folder = builder.fold_output(|| format!("stage{}-rustc", compiler.stage));
85         builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
86         run_cargo(builder,
87                   &mut cargo,
88                   &librustc_stamp(builder, compiler, target),
89                   true);
90
91         let libdir = builder.sysroot_libdir(compiler, target);
92         let hostdir = builder.sysroot_libdir(compiler, compiler.host);
93         add_to_sysroot(&builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
94     }
95 }
96
97 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
98 pub struct CodegenBackend {
99     pub target: Interned<String>,
100     pub backend: Interned<String>,
101 }
102
103 impl Step for CodegenBackend {
104     type Output = ();
105     const ONLY_HOSTS: bool = true;
106     const DEFAULT: bool = true;
107
108     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
109         run.all_krates("rustc_codegen_llvm")
110     }
111
112     fn make_run(run: RunConfig<'_>) {
113         let backend = run.builder.config.rust_codegen_backends.get(0);
114         let backend = backend.cloned().unwrap_or_else(|| {
115             INTERNER.intern_str("llvm")
116         });
117         run.builder.ensure(CodegenBackend {
118             target: run.target,
119             backend,
120         });
121     }
122
123     fn run(self, builder: &Builder<'_>) {
124         let compiler = builder.compiler(0, builder.config.build);
125         let target = self.target;
126         let backend = self.backend;
127
128         builder.ensure(Rustc { target });
129
130         let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "check");
131         cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
132         rustc_cargo_env(builder, &mut cargo);
133
134         // We won't build LLVM if it's not available, as it shouldn't affect `check`.
135
136         let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
137         run_cargo(builder,
138                   &mut cargo,
139                   &codegen_backend_stamp(builder, compiler, target, backend),
140                   true);
141     }
142 }
143
144 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
145 pub struct Test {
146     pub target: Interned<String>,
147 }
148
149 impl Step for Test {
150     type Output = ();
151     const DEFAULT: bool = true;
152
153     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
154         run.all_krates("test")
155     }
156
157     fn make_run(run: RunConfig<'_>) {
158         run.builder.ensure(Test {
159             target: run.target,
160         });
161     }
162
163     fn run(self, builder: &Builder<'_>) {
164         let compiler = builder.compiler(0, builder.config.build);
165         let target = self.target;
166
167         builder.ensure(Std { target });
168
169         let mut cargo = builder.cargo(compiler, Mode::Test, target, "check");
170         test_cargo(builder, &compiler, target, &mut cargo);
171
172         let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
173         builder.info(&format!("Checking test artifacts ({} -> {})", &compiler.host, target));
174         run_cargo(builder,
175                   &mut cargo,
176                   &libtest_stamp(builder, compiler, target),
177                   true);
178
179         let libdir = builder.sysroot_libdir(compiler, target);
180         let hostdir = builder.sysroot_libdir(compiler, compiler.host);
181         add_to_sysroot(builder, &libdir, &hostdir, &libtest_stamp(builder, compiler, target));
182     }
183 }
184
185 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
186 pub struct Rustdoc {
187     pub target: Interned<String>,
188 }
189
190 impl Step for Rustdoc {
191     type Output = ();
192     const ONLY_HOSTS: bool = true;
193     const DEFAULT: bool = true;
194
195     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
196         run.path("src/tools/rustdoc")
197     }
198
199     fn make_run(run: RunConfig<'_>) {
200         run.builder.ensure(Rustdoc {
201             target: run.target,
202         });
203     }
204
205     fn run(self, builder: &Builder<'_>) {
206         let compiler = builder.compiler(0, builder.config.build);
207         let target = self.target;
208
209         builder.ensure(Rustc { target });
210
211         let mut cargo = prepare_tool_cargo(builder,
212                                            compiler,
213                                            Mode::ToolRustc,
214                                            target,
215                                            "check",
216                                            "src/tools/rustdoc",
217                                            SourceType::InTree,
218                                            &[]);
219
220         let _folder = builder.fold_output(|| format!("stage{}-rustdoc", compiler.stage));
221         println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
222         run_cargo(builder,
223                   &mut cargo,
224                   &rustdoc_stamp(builder, compiler, target),
225                   true);
226
227         let libdir = builder.sysroot_libdir(compiler, target);
228         let hostdir = builder.sysroot_libdir(compiler, compiler.host);
229         add_to_sysroot(&builder, &libdir, &hostdir, &rustdoc_stamp(builder, compiler, target));
230         builder.cargo(compiler, Mode::ToolRustc, target, "clean");
231     }
232 }
233
234 /// Cargo's output path for the standard library in a given stage, compiled
235 /// by a particular compiler for the specified target.
236 pub fn libstd_stamp(
237     builder: &Builder<'_>,
238     compiler: Compiler,
239     target: Interned<String>,
240 ) -> PathBuf {
241     builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
242 }
243
244 /// Cargo's output path for libtest in a given stage, compiled by a particular
245 /// compiler for the specified target.
246 pub fn libtest_stamp(
247     builder: &Builder<'_>,
248     compiler: Compiler,
249     target: Interned<String>,
250 ) -> PathBuf {
251     builder.cargo_out(compiler, Mode::Test, target).join(".libtest-check.stamp")
252 }
253
254 /// Cargo's output path for librustc in a given stage, compiled by a particular
255 /// compiler for the specified target.
256 pub fn librustc_stamp(
257     builder: &Builder<'_>,
258     compiler: Compiler,
259     target: Interned<String>,
260 ) -> PathBuf {
261     builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
262 }
263
264 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
265 /// compiler for the specified target and backend.
266 fn codegen_backend_stamp(builder: &Builder<'_>,
267                          compiler: Compiler,
268                          target: Interned<String>,
269                          backend: Interned<String>) -> PathBuf {
270     builder.cargo_out(compiler, Mode::Codegen, target)
271          .join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
272 }
273
274 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
275 /// compiler for the specified target.
276 pub fn rustdoc_stamp(
277     builder: &Builder<'_>,
278     compiler: Compiler,
279     target: Interned<String>,
280 ) -> PathBuf {
281     builder.cargo_out(compiler, Mode::ToolRustc, target)
282         .join(".rustdoc-check.stamp")
283 }