|
3 | 3 | //! A bit of a hodge-podge as e.g. if a tool's a test fixture it should be in `build_steps::test`.
|
4 | 4 | //! If it can be reached from `./x.py run` it can go here.
|
5 | 5 |
|
6 |
| -use std::path::PathBuf; |
7 |
| -use std::process::Command; |
8 |
| - |
| 6 | +use crate::core::build_steps::compile::{Std, Sysroot}; |
9 | 7 | use crate::core::build_steps::dist::distdir;
|
10 | 8 | use crate::core::build_steps::test;
|
11 |
| -use crate::core::build_steps::tool::{self, SourceType, Tool}; |
| 9 | +use crate::core::build_steps::tool::{self, RustcPerf, SourceType, Tool}; |
12 | 10 | use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
|
13 | 11 | use crate::core::config::flags::get_completion;
|
14 |
| -use crate::core::config::TargetSelection; |
| 12 | +use crate::core::config::{DebuginfoLevel, TargetSelection}; |
15 | 13 | use crate::utils::helpers::output;
|
16 | 14 | use crate::Mode;
|
| 15 | +use std::path::PathBuf; |
| 16 | +use std::process::Command; |
17 | 17 |
|
18 | 18 | #[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
|
19 | 19 | pub struct BuildManifest;
|
@@ -283,3 +283,49 @@ impl Step for GenerateCompletions {
|
283 | 283 | run.builder.ensure(GenerateCompletions);
|
284 | 284 | }
|
285 | 285 | }
|
| 286 | + |
| 287 | +/// Helper wrapper tool for `rustc-perf`, located at `src/tools/rustc-perf-wrapper`. |
| 288 | +#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
| 289 | +pub struct RustfPerfWrapper; |
| 290 | + |
| 291 | +impl Step for RustfPerfWrapper { |
| 292 | + type Output = (); |
| 293 | + |
| 294 | + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { |
| 295 | + run.path("src/tools/rustc-perf-wrapper").alias("perf") |
| 296 | + } |
| 297 | + |
| 298 | + fn make_run(run: RunConfig<'_>) { |
| 299 | + run.builder.ensure(RustfPerfWrapper); |
| 300 | + } |
| 301 | + |
| 302 | + fn run(self, builder: &Builder<'_>) { |
| 303 | + let collector = builder.ensure(RustcPerf { |
| 304 | + compiler: builder.compiler(0, builder.config.build), |
| 305 | + target: builder.config.build, |
| 306 | + }); |
| 307 | + |
| 308 | + if builder.build.config.rust_debuginfo_level_rustc == DebuginfoLevel::None { |
| 309 | + builder.info(r#"WARNING: You are compiling rustc without debuginfo, this will make profiling less useful. |
| 310 | +Consider setting `rust.debuginfo-level = 1` in `config.toml`."#); |
| 311 | + } |
| 312 | + |
| 313 | + let compiler = builder.compiler(builder.top_stage, builder.config.build); |
| 314 | + builder.ensure(Std::new(compiler, builder.config.build)); |
| 315 | + let sysroot = builder.ensure(Sysroot::new(compiler)); |
| 316 | + let rustc = sysroot.join("bin/rustc"); |
| 317 | + |
| 318 | + let rustc_perf_dir = builder.build.tempdir().join("rustc-perf"); |
| 319 | + let profile_results_dir = rustc_perf_dir.join("results"); |
| 320 | + |
| 321 | + // We need to take args passed after `--` and pass them to `rustc-perf-wrapper` |
| 322 | + let args = std::env::args().skip_while(|a| a != "--").skip(1); |
| 323 | + |
| 324 | + let mut cmd = builder.tool_cmd(Tool::RustcPerfWrapper); |
| 325 | + cmd.env("PERF_RUSTC", rustc) |
| 326 | + .env("PERF_COLLECTOR", collector) |
| 327 | + .env("PERF_RESULT_DIR", profile_results_dir) |
| 328 | + .args(args); |
| 329 | + builder.run(&mut cmd); |
| 330 | + } |
| 331 | +} |
0 commit comments