]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/check.rs
Rollup merge of #67336 - GuillaumeGomez:fix-js-error, r=Dylan-DPC
[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, add_to_sysroot};
4 use crate::builder::{RunConfig, Builder, Kind, ShouldRun, Step};
5 use crate::tool::{prepare_tool_cargo, SourceType};
6 use crate::{Compiler, Mode};
7 use crate::cache::Interned;
8 use std::path::PathBuf;
9
10 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
11 pub struct Std {
12     pub target: Interned<String>,
13 }
14
15 fn args(kind: Kind) -> Vec<String> {
16     match kind {
17         Kind::Clippy => vec!["--".to_owned(), "--cap-lints".to_owned(), "warn".to_owned()],
18         _ => Vec::new()
19     }
20 }
21
22 fn cargo_subcommand(kind: Kind) -> &'static str {
23     match kind {
24         Kind::Check => "check",
25         Kind::Clippy => "clippy",
26         Kind::Fix => "fix",
27         _ => unreachable!()
28     }
29 }
30
31 impl Step for Std {
32     type Output = ();
33     const DEFAULT: bool = true;
34
35     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
36         run.all_krates("test")
37     }
38
39     fn make_run(run: RunConfig<'_>) {
40         run.builder.ensure(Std {
41             target: run.target,
42         });
43     }
44
45     fn run(self, builder: &Builder<'_>) {
46         let target = self.target;
47         let compiler = builder.compiler(0, builder.config.build);
48
49         let mut cargo = builder.cargo(compiler, Mode::Std, target, cargo_subcommand(builder.kind));
50         std_cargo(builder, &compiler, target, &mut cargo);
51
52         builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
53         run_cargo(builder,
54                   cargo,
55                   args(builder.kind),
56                   &libstd_stamp(builder, compiler, target),
57                   vec![],
58                   true);
59
60         let libdir = builder.sysroot_libdir(compiler, target);
61         let hostdir = builder.sysroot_libdir(compiler, compiler.host);
62         add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
63     }
64 }
65
66 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
67 pub struct Rustc {
68     pub target: Interned<String>,
69 }
70
71 impl Step for Rustc {
72     type Output = ();
73     const ONLY_HOSTS: bool = true;
74     const DEFAULT: bool = true;
75
76     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
77         run.all_krates("rustc-main")
78     }
79
80     fn make_run(run: RunConfig<'_>) {
81         run.builder.ensure(Rustc {
82             target: run.target,
83         });
84     }
85
86     /// Builds the compiler.
87     ///
88     /// This will build the compiler for a particular stage of the build using
89     /// the `compiler` targeting the `target` architecture. The artifacts
90     /// created will also be linked into the sysroot directory.
91     fn run(self, builder: &Builder<'_>) {
92         let compiler = builder.compiler(0, builder.config.build);
93         let target = self.target;
94
95         builder.ensure(Std { target });
96
97         let mut cargo = builder.cargo(compiler, Mode::Rustc, target,
98             cargo_subcommand(builder.kind));
99         rustc_cargo(builder, &mut cargo, target);
100
101         builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
102         run_cargo(builder,
103                   cargo,
104                   args(builder.kind),
105                   &librustc_stamp(builder, compiler, target),
106                   vec![],
107                   true);
108
109         let libdir = builder.sysroot_libdir(compiler, target);
110         let hostdir = builder.sysroot_libdir(compiler, compiler.host);
111         add_to_sysroot(&builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
112     }
113 }
114
115 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
116 pub struct Rustdoc {
117     pub target: Interned<String>,
118 }
119
120 impl Step for Rustdoc {
121     type Output = ();
122     const ONLY_HOSTS: bool = true;
123     const DEFAULT: bool = true;
124
125     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
126         run.path("src/tools/rustdoc")
127     }
128
129     fn make_run(run: RunConfig<'_>) {
130         run.builder.ensure(Rustdoc {
131             target: run.target,
132         });
133     }
134
135     fn run(self, builder: &Builder<'_>) {
136         let compiler = builder.compiler(0, builder.config.build);
137         let target = self.target;
138
139         builder.ensure(Rustc { target });
140
141         let cargo = prepare_tool_cargo(builder,
142                                        compiler,
143                                        Mode::ToolRustc,
144                                        target,
145                                        cargo_subcommand(builder.kind),
146                                        "src/tools/rustdoc",
147                                        SourceType::InTree,
148                                        &[]);
149
150         println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
151         run_cargo(builder,
152                   cargo,
153                   args(builder.kind),
154                   &rustdoc_stamp(builder, compiler, target),
155                   vec![],
156                   true);
157
158         let libdir = builder.sysroot_libdir(compiler, target);
159         let hostdir = builder.sysroot_libdir(compiler, compiler.host);
160         add_to_sysroot(&builder, &libdir, &hostdir, &rustdoc_stamp(builder, compiler, target));
161     }
162 }
163
164 /// Cargo's output path for the standard library in a given stage, compiled
165 /// by a particular compiler for the specified target.
166 pub fn libstd_stamp(
167     builder: &Builder<'_>,
168     compiler: Compiler,
169     target: Interned<String>,
170 ) -> PathBuf {
171     builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
172 }
173
174 /// Cargo's output path for librustc in a given stage, compiled by a particular
175 /// compiler for the specified target.
176 pub fn librustc_stamp(
177     builder: &Builder<'_>,
178     compiler: Compiler,
179     target: Interned<String>,
180 ) -> PathBuf {
181     builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
182 }
183
184 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
185 /// compiler for the specified target.
186 pub fn rustdoc_stamp(
187     builder: &Builder<'_>,
188     compiler: Compiler,
189     target: Interned<String>,
190 ) -> PathBuf {
191     builder.cargo_out(compiler, Mode::ToolRustc, target)
192         .join(".rustdoc-check.stamp")
193 }