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