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