]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/check.rs
Account for --remap-path-prefix in save-analysis
[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 mut cargo = builder.cargo(compiler, Mode::Codegen, target, "check");
141         let features = builder.rustc_features().to_string();
142         cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
143         rustc_cargo_env(builder, &mut cargo);
144
145         // We won't build LLVM if it's not available, as it shouldn't affect `check`.
146
147         let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
148         run_cargo(builder,
149                   cargo.arg("--features").arg(features),
150                   &codegen_backend_stamp(builder, compiler, target, backend),
151                   true);
152     }
153 }
154
155 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
156 pub struct Test {
157     pub target: Interned<String>,
158 }
159
160 impl Step for Test {
161     type Output = ();
162     const DEFAULT: bool = true;
163
164     fn should_run(run: ShouldRun) -> ShouldRun {
165         run.all_krates("test")
166     }
167
168     fn make_run(run: RunConfig) {
169         run.builder.ensure(Test {
170             target: run.target,
171         });
172     }
173
174     fn run(self, builder: &Builder) {
175         let compiler = builder.compiler(0, builder.config.build);
176         let target = self.target;
177
178         let out_dir = builder.stage_out(compiler, Mode::Test);
179         builder.clear_if_dirty(&out_dir, &libstd_stamp(builder, compiler, target));
180
181         let mut cargo = builder.cargo(compiler, Mode::Test, target, "check");
182         test_cargo(builder, &compiler, target, &mut cargo);
183
184         let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
185         println!("Checking test artifacts ({} -> {})", &compiler.host, target);
186         run_cargo(builder,
187                   &mut cargo,
188                   &libtest_stamp(builder, compiler, target),
189                   true);
190
191         let libdir = builder.sysroot_libdir(compiler, target);
192         add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target));
193     }
194 }
195
196 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
197 pub struct Rustdoc {
198     pub target: Interned<String>,
199 }
200
201 impl Step for Rustdoc {
202     type Output = ();
203     const ONLY_HOSTS: bool = true;
204     const DEFAULT: bool = true;
205
206     fn should_run(run: ShouldRun) -> ShouldRun {
207         run.path("src/tools/rustdoc")
208     }
209
210     fn make_run(run: RunConfig) {
211         run.builder.ensure(Rustdoc {
212             target: run.target,
213         });
214     }
215
216     fn run(self, builder: &Builder) {
217         let compiler = builder.compiler(0, builder.config.build);
218         let target = self.target;
219
220         let stage_out = builder.stage_out(compiler, Mode::ToolRustc);
221         builder.clear_if_dirty(&stage_out, &libstd_stamp(builder, compiler, target));
222         builder.clear_if_dirty(&stage_out, &libtest_stamp(builder, compiler, target));
223         builder.clear_if_dirty(&stage_out, &librustc_stamp(builder, compiler, target));
224
225         let mut cargo = prepare_tool_cargo(builder,
226                                            compiler,
227                                            Mode::ToolRustc,
228                                            target,
229                                            "check",
230                                            "src/tools/rustdoc",
231                                            SourceType::InTree);
232
233         let _folder = builder.fold_output(|| format!("stage{}-rustdoc", compiler.stage));
234         println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
235         run_cargo(builder,
236                   &mut cargo,
237                   &rustdoc_stamp(builder, compiler, target),
238                   true);
239
240         let libdir = builder.sysroot_libdir(compiler, target);
241         add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target));
242
243         builder.ensure(tool::CleanTools {
244             compiler,
245             target,
246             cause: Mode::Rustc,
247         });
248     }
249 }
250
251 /// Cargo's output path for the standard library in a given stage, compiled
252 /// by a particular compiler for the specified target.
253 pub fn libstd_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
254     builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
255 }
256
257 /// Cargo's output path for libtest in a given stage, compiled by a particular
258 /// compiler for the specified target.
259 pub fn libtest_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
260     builder.cargo_out(compiler, Mode::Test, target).join(".libtest-check.stamp")
261 }
262
263 /// Cargo's output path for librustc in a given stage, compiled by a particular
264 /// compiler for the specified target.
265 pub fn librustc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
266     builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
267 }
268
269 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
270 /// compiler for the specified target and backend.
271 fn codegen_backend_stamp(builder: &Builder,
272                          compiler: Compiler,
273                          target: Interned<String>,
274                          backend: Interned<String>) -> PathBuf {
275     builder.cargo_out(compiler, Mode::Codegen, target)
276          .join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
277 }
278
279 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
280 /// compiler for the specified target.
281 pub fn rustdoc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
282     builder.cargo_out(compiler, Mode::ToolRustc, target)
283         .join(".rustdoc-check.stamp")
284 }