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