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