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