1 use std::path::PathBuf;
2 use std::process::Command;
4 use crate::builder::{Builder, RunConfig, ShouldRun, Step};
5 use crate::config::TargetSelection;
6 use crate::dist::distdir;
8 use crate::tool::{self, SourceType, Tool};
9 use crate::util::output;
12 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
13 pub struct ExpandYamlAnchors;
15 impl Step for ExpandYamlAnchors {
18 /// Runs the `expand-yaml_anchors` tool.
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");
26 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("generate").arg(&builder.src),
30 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
31 run.path("src/tools/expand-yaml-anchors")
34 fn make_run(run: RunConfig<'_>) {
35 run.builder.ensure(ExpandYamlAnchors);
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));
52 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
53 pub struct BuildManifest;
55 impl Step for BuildManifest {
57 const ONLY_HOSTS: bool = true;
59 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
60 run.path("src/tools/build-manifest")
63 fn make_run(run: RunConfig<'_>) {
64 run.builder.ensure(BuildManifest);
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")
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")
78 let today = output(Command::new("date").arg("+%Y-%m-%d"));
81 cmd.arg(distdir(builder));
82 cmd.arg(today.trim());
84 cmd.arg(&builder.config.channel);
86 builder.create_dir(&distdir(builder));
87 builder.run(&mut cmd);
91 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
92 pub struct BumpStage0;
94 impl Step for BumpStage0 {
96 const ONLY_HOSTS: bool = true;
98 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
99 run.path("src/tools/bump-stage0")
102 fn make_run(run: RunConfig<'_>) {
103 run.builder.ensure(BumpStage0);
106 fn run(self, builder: &Builder<'_>) -> Self::Output {
107 let mut cmd = builder.tool_cmd(Tool::BumpStage0);
108 builder.run(&mut cmd);
112 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
113 pub struct ReplaceVersionPlaceholder;
115 impl Step for ReplaceVersionPlaceholder {
117 const ONLY_HOSTS: bool = true;
119 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
120 run.path("src/tools/replace-version-placeholder")
123 fn make_run(run: RunConfig<'_>) {
124 run.builder.ensure(ReplaceVersionPlaceholder);
127 fn run(self, builder: &Builder<'_>) -> Self::Output {
128 let mut cmd = builder.tool_cmd(Tool::ReplaceVersionPlaceholder);
129 cmd.arg(&builder.src);
130 builder.run(&mut cmd);
134 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
137 host: TargetSelection,
138 target: TargetSelection,
143 const ONLY_HOSTS: bool = false;
145 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
146 run.path("src/tools/miri")
149 fn make_run(run: RunConfig<'_>) {
150 run.builder.ensure(Miri {
151 stage: run.builder.top_stage,
152 host: run.build_triple(),
157 fn run(self, builder: &Builder<'_>) {
158 let stage = self.stage;
159 let host = self.host;
160 let target = self.target;
161 let compiler = builder.compiler(stage, host);
164 .ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() })
165 .expect("in-tree tool");
166 let miri_sysroot = test::Miri::build_miri_sysroot(builder, compiler, &miri, target);
169 // Running it via `cargo run` as that figures out the right dylib path.
170 // add_rustc_lib_path does not add the path that contains librustc_driver-<...>.so.
171 let mut miri = tool::prepare_tool_cargo(
181 miri.add_rustc_lib_path(builder, compiler);
182 // Forward arguments.
183 miri.arg("--").arg("--target").arg(target.rustc_target_arg());
184 miri.args(builder.config.cmd.args());
186 // miri tests need to know about the stage sysroot
187 miri.env("MIRI_SYSROOT", &miri_sysroot);
189 let mut miri = Command::from(miri);
190 builder.run(&mut miri);
194 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
195 pub struct CollectLicenseMetadata;
197 impl Step for CollectLicenseMetadata {
198 type Output = PathBuf;
199 const ONLY_HOSTS: bool = true;
201 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
202 run.path("src/tools/collect-license-metadata")
205 fn make_run(run: RunConfig<'_>) {
206 run.builder.ensure(CollectLicenseMetadata);
209 fn run(self, builder: &Builder<'_>) -> Self::Output {
210 let Some(reuse) = &builder.config.reuse else {
211 panic!("REUSE is required to collect the license metadata");
214 // Temporary location, it will be moved to src/etc once it's accurate.
215 let dest = builder.out.join("license-metadata.json");
217 let mut cmd = builder.tool_cmd(Tool::CollectLicenseMetadata);
218 cmd.env("REUSE_EXE", reuse);
219 cmd.env("DEST", &dest);
220 builder.run(&mut cmd);
226 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
227 pub struct GenerateCopyright;
229 impl Step for GenerateCopyright {
230 type Output = PathBuf;
231 const ONLY_HOSTS: bool = true;
233 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
234 run.path("src/tools/generate-copyright")
237 fn make_run(run: RunConfig<'_>) {
238 run.builder.ensure(GenerateCopyright);
241 fn run(self, builder: &Builder<'_>) -> Self::Output {
242 let license_metadata = builder.ensure(CollectLicenseMetadata);
244 // Temporary location, it will be moved to the proper one once it's accurate.
245 let dest = builder.out.join("COPYRIGHT.md");
247 let mut cmd = builder.tool_cmd(Tool::GenerateCopyright);
248 cmd.env("LICENSE_METADATA", &license_metadata);
249 cmd.env("DEST", &dest);
250 builder.run(&mut cmd);