]> git.proxmox.com Git - rustc.git/blob - src/bootstrap/run.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / bootstrap / run.rs
1 use std::path::PathBuf;
2 use std::process::Command;
3
4 use clap_complete::shells;
5
6 use crate::builder::{Builder, RunConfig, ShouldRun, Step};
7 use crate::config::TargetSelection;
8 use crate::dist::distdir;
9 use crate::flags::get_completion;
10 use crate::test;
11 use crate::tool::{self, SourceType, Tool};
12 use crate::util::output;
13 use crate::Mode;
14
15 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
16 pub struct ExpandYamlAnchors;
17
18 impl Step for ExpandYamlAnchors {
19 type Output = ();
20
21 /// Runs the `expand-yaml_anchors` tool.
22 ///
23 /// This tool in `src/tools` reads the CI configuration files written in YAML and expands the
24 /// anchors in them, since GitHub Actions doesn't support them.
25 fn run(self, builder: &Builder<'_>) {
26 builder.info("Expanding YAML anchors in the GitHub Actions configuration");
27 builder.run_delaying_failure(
28 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("generate").arg(&builder.src),
29 );
30 }
31
32 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
33 run.path("src/tools/expand-yaml-anchors")
34 }
35
36 fn make_run(run: RunConfig<'_>) {
37 run.builder.ensure(ExpandYamlAnchors);
38 }
39 }
40
41 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
42 pub struct BuildManifest;
43
44 impl Step for BuildManifest {
45 type Output = ();
46 const ONLY_HOSTS: bool = true;
47
48 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
49 run.path("src/tools/build-manifest")
50 }
51
52 fn make_run(run: RunConfig<'_>) {
53 run.builder.ensure(BuildManifest);
54 }
55
56 fn run(self, builder: &Builder<'_>) {
57 // This gets called by `promote-release`
58 // (https://github.com/rust-lang/promote-release).
59 let mut cmd = builder.tool_cmd(Tool::BuildManifest);
60 let sign = builder.config.dist_sign_folder.as_ref().unwrap_or_else(|| {
61 panic!("\n\nfailed to specify `dist.sign-folder` in `config.toml`\n\n")
62 });
63 let addr = builder.config.dist_upload_addr.as_ref().unwrap_or_else(|| {
64 panic!("\n\nfailed to specify `dist.upload-addr` in `config.toml`\n\n")
65 });
66
67 let today = output(Command::new("date").arg("+%Y-%m-%d"));
68
69 cmd.arg(sign);
70 cmd.arg(distdir(builder));
71 cmd.arg(today.trim());
72 cmd.arg(addr);
73 cmd.arg(&builder.config.channel);
74
75 builder.create_dir(&distdir(builder));
76 builder.run(&mut cmd);
77 }
78 }
79
80 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
81 pub struct BumpStage0;
82
83 impl Step for BumpStage0 {
84 type Output = ();
85 const ONLY_HOSTS: bool = true;
86
87 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
88 run.path("src/tools/bump-stage0")
89 }
90
91 fn make_run(run: RunConfig<'_>) {
92 run.builder.ensure(BumpStage0);
93 }
94
95 fn run(self, builder: &Builder<'_>) -> Self::Output {
96 let mut cmd = builder.tool_cmd(Tool::BumpStage0);
97 cmd.args(builder.config.args());
98 builder.run(&mut cmd);
99 }
100 }
101
102 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
103 pub struct ReplaceVersionPlaceholder;
104
105 impl Step for ReplaceVersionPlaceholder {
106 type Output = ();
107 const ONLY_HOSTS: bool = true;
108
109 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
110 run.path("src/tools/replace-version-placeholder")
111 }
112
113 fn make_run(run: RunConfig<'_>) {
114 run.builder.ensure(ReplaceVersionPlaceholder);
115 }
116
117 fn run(self, builder: &Builder<'_>) -> Self::Output {
118 let mut cmd = builder.tool_cmd(Tool::ReplaceVersionPlaceholder);
119 cmd.arg(&builder.src);
120 builder.run(&mut cmd);
121 }
122 }
123
124 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
125 pub struct Miri {
126 stage: u32,
127 host: TargetSelection,
128 target: TargetSelection,
129 }
130
131 impl Step for Miri {
132 type Output = ();
133 const ONLY_HOSTS: bool = false;
134
135 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
136 run.path("src/tools/miri")
137 }
138
139 fn make_run(run: RunConfig<'_>) {
140 run.builder.ensure(Miri {
141 stage: run.builder.top_stage,
142 host: run.build_triple(),
143 target: run.target,
144 });
145 }
146
147 fn run(self, builder: &Builder<'_>) {
148 let stage = self.stage;
149 let host = self.host;
150 let target = self.target;
151 let compiler = builder.compiler(stage, host);
152
153 let miri = builder
154 .ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() })
155 .expect("in-tree tool");
156 let miri_sysroot = test::Miri::build_miri_sysroot(builder, compiler, &miri, target);
157
158 // # Run miri.
159 // Running it via `cargo run` as that figures out the right dylib path.
160 // add_rustc_lib_path does not add the path that contains librustc_driver-<...>.so.
161 let mut miri = tool::prepare_tool_cargo(
162 builder,
163 compiler,
164 Mode::ToolRustc,
165 host,
166 "run",
167 "src/tools/miri",
168 SourceType::InTree,
169 &[],
170 );
171 miri.add_rustc_lib_path(builder, compiler);
172 // Forward arguments.
173 miri.arg("--").arg("--target").arg(target.rustc_target_arg());
174 miri.args(builder.config.args());
175
176 // miri tests need to know about the stage sysroot
177 miri.env("MIRI_SYSROOT", &miri_sysroot);
178
179 let mut miri = Command::from(miri);
180 builder.run(&mut miri);
181 }
182 }
183
184 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
185 pub struct CollectLicenseMetadata;
186
187 impl Step for CollectLicenseMetadata {
188 type Output = PathBuf;
189 const ONLY_HOSTS: bool = true;
190
191 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
192 run.path("src/tools/collect-license-metadata")
193 }
194
195 fn make_run(run: RunConfig<'_>) {
196 run.builder.ensure(CollectLicenseMetadata);
197 }
198
199 fn run(self, builder: &Builder<'_>) -> Self::Output {
200 let Some(reuse) = &builder.config.reuse else {
201 panic!("REUSE is required to collect the license metadata");
202 };
203
204 // Temporary location, it will be moved to src/etc once it's accurate.
205 let dest = builder.out.join("license-metadata.json");
206
207 let mut cmd = builder.tool_cmd(Tool::CollectLicenseMetadata);
208 cmd.env("REUSE_EXE", reuse);
209 cmd.env("DEST", &dest);
210 builder.run(&mut cmd);
211
212 dest
213 }
214 }
215
216 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
217 pub struct GenerateCopyright;
218
219 impl Step for GenerateCopyright {
220 type Output = PathBuf;
221 const ONLY_HOSTS: bool = true;
222
223 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
224 run.path("src/tools/generate-copyright")
225 }
226
227 fn make_run(run: RunConfig<'_>) {
228 run.builder.ensure(GenerateCopyright);
229 }
230
231 fn run(self, builder: &Builder<'_>) -> Self::Output {
232 let license_metadata = builder.ensure(CollectLicenseMetadata);
233
234 // Temporary location, it will be moved to the proper one once it's accurate.
235 let dest = builder.out.join("COPYRIGHT.md");
236
237 let mut cmd = builder.tool_cmd(Tool::GenerateCopyright);
238 cmd.env("LICENSE_METADATA", &license_metadata);
239 cmd.env("DEST", &dest);
240 builder.run(&mut cmd);
241
242 dest
243 }
244 }
245
246 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
247 pub struct GenerateWindowsSys;
248
249 impl Step for GenerateWindowsSys {
250 type Output = ();
251 const ONLY_HOSTS: bool = true;
252
253 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
254 run.path("src/tools/generate-windows-sys")
255 }
256
257 fn make_run(run: RunConfig<'_>) {
258 run.builder.ensure(GenerateWindowsSys);
259 }
260
261 fn run(self, builder: &Builder<'_>) {
262 let mut cmd = builder.tool_cmd(Tool::GenerateWindowsSys);
263 cmd.arg(&builder.src);
264 builder.run(&mut cmd);
265 }
266 }
267
268 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
269 pub struct GenerateCompletions;
270
271 impl Step for GenerateCompletions {
272 type Output = ();
273
274 /// Uses `clap_complete` to generate shell completions.
275 fn run(self, builder: &Builder<'_>) {
276 // FIXME(clubby789): enable zsh when clap#4898 is fixed
277 let [bash, fish, powershell] = ["x.py.sh", "x.py.fish", "x.py.ps1"]
278 .map(|filename| builder.src.join("src/etc/completions").join(filename));
279 if let Some(comp) = get_completion(shells::Bash, &bash) {
280 std::fs::write(&bash, comp).expect("writing bash completion");
281 }
282 if let Some(comp) = get_completion(shells::Fish, &fish) {
283 std::fs::write(&fish, comp).expect("writing fish completion");
284 }
285 if let Some(comp) = get_completion(shells::PowerShell, &powershell) {
286 std::fs::write(&powershell, comp).expect("writing powershell completion");
287 }
288 }
289
290 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
291 run.alias("generate-completions")
292 }
293
294 fn make_run(run: RunConfig<'_>) {
295 run.builder.ensure(GenerateCompletions);
296 }
297 }