]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/run.rs
Auto merge of #96451 - JakobDegen:dest-prop, r=tmiasko
[rust.git] / src / bootstrap / run.rs
1 use std::process::Command;
2
3 use crate::builder::{Builder, RunConfig, ShouldRun, Step};
4 use crate::config::TargetSelection;
5 use crate::dist::distdir;
6 use crate::test;
7 use crate::tool::{self, SourceType, Tool};
8 use crate::util::output;
9 use crate::Mode;
10
11 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
12 pub struct ExpandYamlAnchors;
13
14 impl Step for ExpandYamlAnchors {
15     type Output = ();
16
17     /// Runs the `expand-yaml_anchors` tool.
18     ///
19     /// This tool in `src/tools` reads the CI configuration files written in YAML and expands the
20     /// anchors in them, since GitHub Actions doesn't support them.
21     fn run(self, builder: &Builder<'_>) {
22         builder.info("Expanding YAML anchors in the GitHub Actions configuration");
23         try_run(
24             builder,
25             &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("generate").arg(&builder.src),
26         );
27     }
28
29     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
30         run.path("src/tools/expand-yaml-anchors")
31     }
32
33     fn make_run(run: RunConfig<'_>) {
34         run.builder.ensure(ExpandYamlAnchors);
35     }
36 }
37
38 fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
39     if !builder.fail_fast {
40         if !builder.try_run(cmd) {
41             let mut failures = builder.delayed_failures.borrow_mut();
42             failures.push(format!("{:?}", cmd));
43             return false;
44         }
45     } else {
46         builder.run(cmd);
47     }
48     true
49 }
50
51 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
52 pub struct BuildManifest;
53
54 impl Step for BuildManifest {
55     type Output = ();
56     const ONLY_HOSTS: bool = true;
57
58     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
59         run.path("src/tools/build-manifest")
60     }
61
62     fn make_run(run: RunConfig<'_>) {
63         run.builder.ensure(BuildManifest);
64     }
65
66     fn run(self, builder: &Builder<'_>) {
67         // This gets called by `promote-release`
68         // (https://github.com/rust-lang/promote-release).
69         let mut cmd = builder.tool_cmd(Tool::BuildManifest);
70         let sign = builder.config.dist_sign_folder.as_ref().unwrap_or_else(|| {
71             panic!("\n\nfailed to specify `dist.sign-folder` in `config.toml`\n\n")
72         });
73         let addr = builder.config.dist_upload_addr.as_ref().unwrap_or_else(|| {
74             panic!("\n\nfailed to specify `dist.upload-addr` in `config.toml`\n\n")
75         });
76
77         let today = output(Command::new("date").arg("+%Y-%m-%d"));
78
79         cmd.arg(sign);
80         cmd.arg(distdir(builder));
81         cmd.arg(today.trim());
82         cmd.arg(addr);
83         cmd.arg(&builder.config.channel);
84
85         builder.create_dir(&distdir(builder));
86         builder.run(&mut cmd);
87     }
88 }
89
90 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
91 pub struct BumpStage0;
92
93 impl Step for BumpStage0 {
94     type Output = ();
95     const ONLY_HOSTS: bool = true;
96
97     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
98         run.path("src/tools/bump-stage0")
99     }
100
101     fn make_run(run: RunConfig<'_>) {
102         run.builder.ensure(BumpStage0);
103     }
104
105     fn run(self, builder: &Builder<'_>) -> Self::Output {
106         let mut cmd = builder.tool_cmd(Tool::BumpStage0);
107         builder.run(&mut cmd);
108     }
109 }
110
111 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
112 pub struct ReplaceVersionPlaceholder;
113
114 impl Step for ReplaceVersionPlaceholder {
115     type Output = ();
116     const ONLY_HOSTS: bool = true;
117
118     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
119         run.path("src/tools/replace-version-placeholder")
120     }
121
122     fn make_run(run: RunConfig<'_>) {
123         run.builder.ensure(ReplaceVersionPlaceholder);
124     }
125
126     fn run(self, builder: &Builder<'_>) -> Self::Output {
127         let mut cmd = builder.tool_cmd(Tool::ReplaceVersionPlaceholder);
128         cmd.arg(&builder.src);
129         builder.run(&mut cmd);
130     }
131 }
132
133 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
134 pub struct Miri {
135     stage: u32,
136     host: TargetSelection,
137     target: TargetSelection,
138 }
139
140 impl Step for Miri {
141     type Output = ();
142     const ONLY_HOSTS: bool = false;
143
144     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
145         run.path("src/tools/miri")
146     }
147
148     fn make_run(run: RunConfig<'_>) {
149         run.builder.ensure(Miri {
150             stage: run.builder.top_stage,
151             host: run.build_triple(),
152             target: run.target,
153         });
154     }
155
156     fn run(self, builder: &Builder<'_>) {
157         let stage = self.stage;
158         let host = self.host;
159         let target = self.target;
160         let compiler = builder.compiler(stage, host);
161
162         let miri = builder
163             .ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() })
164             .expect("in-tree tool");
165         let miri_sysroot = test::Miri::build_miri_sysroot(builder, compiler, &miri, target);
166
167         // # Run miri.
168         // Running it via `cargo run` as that figures out the right dylib path.
169         // add_rustc_lib_path does not add the path that contains librustc_driver-<...>.so.
170         let mut miri = tool::prepare_tool_cargo(
171             builder,
172             compiler,
173             Mode::ToolRustc,
174             host,
175             "run",
176             "src/tools/miri",
177             SourceType::InTree,
178             &[],
179         );
180         miri.add_rustc_lib_path(builder, compiler);
181         // Forward arguments.
182         miri.arg("--").arg("--target").arg(target.rustc_target_arg());
183         miri.args(builder.config.cmd.args());
184
185         // miri tests need to know about the stage sysroot
186         miri.env("MIRI_SYSROOT", &miri_sysroot);
187
188         let mut miri = Command::from(miri);
189         builder.run(&mut miri);
190     }
191 }