Skip to content

Commit 4507266

Browse files
committed
refactor(timings): render context stop referencing to buildrunner
1 parent a236d24 commit 4507266

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

src/cargo/core/compiler/timings/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,21 @@ impl<'gctx> Timings<'gctx> {
380380
let filename = timings_path.join(format!("cargo-timing-{}.html", timestamp));
381381
let mut f = BufWriter::new(paths::create(&filename)?);
382382

383+
let rustc_version = build_runner
384+
.bcx
385+
.rustc()
386+
.verbose_version
387+
.lines()
388+
.next()
389+
.expect("rustc version");
390+
let requested_targets = &build_runner
391+
.bcx
392+
.build_config
393+
.requested_kinds
394+
.iter()
395+
.map(|kind| build_runner.bcx.target_data.short_name(kind))
396+
.collect::<Vec<_>>();
397+
383398
let ctx = report::HtmlRenderContext {
384399
start: self.start,
385400
start_str: &self.start_str,
@@ -390,8 +405,12 @@ impl<'gctx> Timings<'gctx> {
390405
unit_times: &self.unit_times,
391406
concurrency: &self.concurrency,
392407
cpu_usage: &self.cpu_usage,
408+
rustc_version,
409+
host: &build_runner.bcx.rustc().host,
410+
requested_targets,
411+
jobs: build_runner.bcx.jobs(),
393412
};
394-
report::report_html(ctx, &mut f, build_runner, error)?;
413+
report::report_html(ctx, &mut f, error)?;
395414

396415
let unstamped_filename = timings_path.join("cargo-timing.html");
397416
paths::link_or_copy(&filename, &unstamped_filename)?;

src/cargo/core/compiler/timings/report.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ use std::time::Instant;
77
use itertools::Itertools as _;
88

99
use crate::CargoResult;
10-
use crate::core::compiler::BuildContext;
11-
use crate::core::compiler::BuildRunner;
1210
use crate::core::compiler::CompilationSection;
1311
use crate::core::compiler::Unit;
1412

@@ -71,13 +69,20 @@ pub struct HtmlRenderContext<'a> {
7169
/// recording was taken and second element is percentage usage of the
7270
/// system.
7371
pub cpu_usage: &'a [(f64, f64)],
72+
/// Compiler version info, i.e., `rustc 1.92.0-beta.2 (0a411606e 2025-10-31)`.
73+
pub rustc_version: &'a str,
74+
/// The host triple (arch-platform-OS).
75+
pub host: &'a str,
76+
/// The requested target platforms of compilation for this build.
77+
pub requested_targets: &'a [&'a str],
78+
/// The number of jobs specified for this build.
79+
pub jobs: u32,
7480
}
7581

7682
/// Save HTML report to disk.
7783
pub(super) fn report_html(
7884
ctx: HtmlRenderContext<'_>,
7985
f: &mut impl Write,
80-
build_runner: &BuildRunner<'_, '_>,
8186
error: &Option<anyhow::Error>,
8287
) -> CargoResult<()> {
8388
let duration = ctx.start.elapsed().as_secs_f64();
@@ -87,7 +92,7 @@ pub(super) fn report_html(
8792
.map(|(name, _targets)| name.as_str())
8893
.collect();
8994
f.write_all(HTML_TMPL.replace("{ROOTS}", &roots.join(", ")).as_bytes())?;
90-
write_summary_table(&ctx, f, duration, build_runner.bcx, error)?;
95+
write_summary_table(&ctx, f, duration, error)?;
9196
f.write_all(HTML_CANVAS.as_bytes())?;
9297
write_unit_table(&ctx, f)?;
9398
// It helps with pixel alignment to use whole numbers.
@@ -116,7 +121,6 @@ fn write_summary_table(
116121
ctx: &HtmlRenderContext<'_>,
117122
f: &mut impl Write,
118123
duration: f64,
119-
bcx: &BuildContext<'_, '_>,
120124
error: &Option<anyhow::Error>,
121125
) -> CargoResult<()> {
122126
let targets: Vec<String> = ctx
@@ -135,12 +139,12 @@ fn write_summary_table(
135139
let total_time = format!("{:.1}s{}", duration, time_human);
136140

137141
let max_concurrency = ctx.concurrency.iter().map(|c| c.active).max().unwrap();
138-
let jobs = bcx.jobs();
139142
let num_cpus = std::thread::available_parallelism()
140143
.map(|x| x.get().to_string())
141144
.unwrap_or_else(|_| "n/a".into());
142145

143-
let rustc_info = render_rustc_info(bcx);
146+
let requested_targets = ctx.requested_targets.join(", ");
147+
144148
let error_msg = match error {
145149
Some(e) => format!(r#"<tr><td class="error-text">Error:</td><td>{e}</td></tr>"#),
146150
None => "".to_string(),
@@ -151,6 +155,9 @@ fn write_summary_table(
151155
profile,
152156
total_fresh,
153157
total_dirty,
158+
rustc_version,
159+
host,
160+
jobs,
154161
..
155162
} = &ctx;
156163

@@ -183,7 +190,7 @@ fn write_summary_table(
183190
<td>Total time:</td><td>{total_time}</td>
184191
</tr>
185192
<tr>
186-
<td>rustc:</td><td>{rustc_info}</td>
193+
<td>rustc:</td><td>{rustc_version}<br>Host: {host}<br>Target: {requested_targets}</td>
187194
</tr>
188195
{error_msg}
189196
</table>
@@ -347,28 +354,6 @@ fn write_unit_table(ctx: &HtmlRenderContext<'_>, f: &mut impl Write) -> CargoRes
347354
Ok(())
348355
}
349356

350-
fn render_rustc_info(bcx: &BuildContext<'_, '_>) -> String {
351-
let version = bcx
352-
.rustc()
353-
.verbose_version
354-
.lines()
355-
.next()
356-
.expect("rustc version");
357-
let requested_target = bcx
358-
.build_config
359-
.requested_kinds
360-
.iter()
361-
.map(|kind| bcx.target_data.short_name(kind))
362-
.collect::<Vec<_>>()
363-
.join(", ");
364-
format!(
365-
"{}<br>Host: {}<br>Target: {}",
366-
version,
367-
bcx.rustc().host,
368-
requested_target
369-
)
370-
}
371-
372357
fn to_unit_data(unit_times: &[UnitTime]) -> Vec<UnitData> {
373358
// Create a map to link indices of unlocked units.
374359
let unit_map: HashMap<Unit, usize> = unit_times

0 commit comments

Comments
 (0)