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 cmd.args(builder.config.cmd.args());
109 builder.run(&mut cmd);
113 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
114 pub struct ReplaceVersionPlaceholder;
116 impl Step for ReplaceVersionPlaceholder {
118 const ONLY_HOSTS: bool = true;
120 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
121 run.path("src/tools/replace-version-placeholder")
124 fn make_run(run: RunConfig<'_>) {
125 run.builder.ensure(ReplaceVersionPlaceholder);
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);
135 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
138 host: TargetSelection,
139 target: TargetSelection,
144 const ONLY_HOSTS: bool = false;
146 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
147 run.path("src/tools/miri")
150 fn make_run(run: RunConfig<'_>) {
151 run.builder.ensure(Miri {
152 stage: run.builder.top_stage,
153 host: run.build_triple(),
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);
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);
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(
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());
187 // miri tests need to know about the stage sysroot
188 miri.env("MIRI_SYSROOT", &miri_sysroot);
190 let mut miri = Command::from(miri);
191 builder.run(&mut miri);
195 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
196 pub struct CollectLicenseMetadata;
198 impl Step for CollectLicenseMetadata {
199 type Output = PathBuf;
200 const ONLY_HOSTS: bool = true;
202 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
203 run.path("src/tools/collect-license-metadata")
206 fn make_run(run: RunConfig<'_>) {
207 run.builder.ensure(CollectLicenseMetadata);
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");
215 // Temporary location, it will be moved to src/etc once it's accurate.
216 let dest = builder.out.join("license-metadata.json");
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);
227 #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
228 pub struct GenerateCopyright;
230 impl Step for GenerateCopyright {
231 type Output = PathBuf;
232 const ONLY_HOSTS: bool = true;
234 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
235 run.path("src/tools/generate-copyright")
238 fn make_run(run: RunConfig<'_>) {
239 run.builder.ensure(GenerateCopyright);
242 fn run(self, builder: &Builder<'_>) -> Self::Output {
243 let license_metadata = builder.ensure(CollectLicenseMetadata);
245 // Temporary location, it will be moved to the proper one once it's accurate.
246 let dest = builder.out.join("COPYRIGHT.md");
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);