]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/check.rs
Rollup merge of #68279 - GuillaumeGomez:clean-up-e0198, 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::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
4 use crate::cache::Interned;
5 use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, std_cargo};
6 use crate::tool::{prepare_tool_cargo, SourceType};
7 use crate::{Compiler, Mode};
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 { target: run.target });
41     }
42
43     fn run(self, builder: &Builder<'_>) {
44         let target = self.target;
45         let compiler = builder.compiler(0, builder.config.build);
46
47         let mut cargo = builder.cargo(compiler, Mode::Std, target, cargo_subcommand(builder.kind));
48         std_cargo(builder, target, &mut cargo);
49
50         builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
51         run_cargo(
52             builder,
53             cargo,
54             args(builder.kind),
55             &libstd_stamp(builder, compiler, target),
56             vec![],
57             true,
58         );
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 { target: run.target });
82     }
83
84     /// Builds the compiler.
85     ///
86     /// This will build the compiler for a particular stage of the build using
87     /// the `compiler` targeting the `target` architecture. The artifacts
88     /// created will also be linked into the sysroot directory.
89     fn run(self, builder: &Builder<'_>) {
90         let compiler = builder.compiler(0, builder.config.build);
91         let target = self.target;
92
93         builder.ensure(Std { target });
94
95         let mut cargo =
96             builder.cargo(compiler, Mode::Rustc, target, cargo_subcommand(builder.kind));
97         rustc_cargo(builder, &mut cargo, target);
98
99         builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
100         run_cargo(
101             builder,
102             cargo,
103             args(builder.kind),
104             &librustc_stamp(builder, compiler, target),
105             vec![],
106             true,
107         );
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 { target: run.target });
131     }
132
133     fn run(self, builder: &Builder<'_>) {
134         let compiler = builder.compiler(0, builder.config.build);
135         let target = self.target;
136
137         builder.ensure(Rustc { target });
138
139         let cargo = prepare_tool_cargo(
140             builder,
141             compiler,
142             Mode::ToolRustc,
143             target,
144             cargo_subcommand(builder.kind),
145             "src/tools/rustdoc",
146             SourceType::InTree,
147             &[],
148         );
149
150         println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
151         run_cargo(
152             builder,
153             cargo,
154             args(builder.kind),
155             &rustdoc_stamp(builder, compiler, target),
156             vec![],
157             true,
158         );
159
160         let libdir = builder.sysroot_libdir(compiler, target);
161         let hostdir = builder.sysroot_libdir(compiler, compiler.host);
162         add_to_sysroot(&builder, &libdir, &hostdir, &rustdoc_stamp(builder, compiler, target));
163     }
164 }
165
166 /// Cargo's output path for the standard library in a given stage, compiled
167 /// by a particular compiler for the specified target.
168 pub fn libstd_stamp(
169     builder: &Builder<'_>,
170     compiler: Compiler,
171     target: Interned<String>,
172 ) -> PathBuf {
173     builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
174 }
175
176 /// Cargo's output path for librustc in a given stage, compiled by a particular
177 /// compiler for the specified target.
178 pub fn librustc_stamp(
179     builder: &Builder<'_>,
180     compiler: Compiler,
181     target: Interned<String>,
182 ) -> PathBuf {
183     builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
184 }
185
186 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
187 /// compiler for the specified target.
188 pub fn rustdoc_stamp(
189     builder: &Builder<'_>,
190     compiler: Compiler,
191     target: Interned<String>,
192 ) -> PathBuf {
193     builder.cargo_out(compiler, Mode::ToolRustc, target).join(".rustdoc-check.stamp")
194 }