rust-lang / rust-lang/cargo

Report time spent in the linker for binary targets separately

Open
#10,643 1 comment 17 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-timings C-feature-request S-waiting-on-feedback
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

Problem

As a a developer working on large executables,
I would like cargo to report the time spent linking executables
so that I can make use the linker that gives me the shortest edit-build-run-tests feedback loop

Currently, i can synthetically achieve that with a hyperfine command that deletes the executable and re-runs cargo build using the total wall-time as an approximation of build time. However, I cannot know how much time it takes cargo to analyse the target/ dir and realise that only the link-step needs to be re-run.

For clean builds I have even less information about link-time alone.

Proposed Solution
  1. Start measuring the duration of the linker step for TargetKind::Bin

Add an optional field to TimingInfo in src/cargo/util/machine_message.rs similar to rmeta_time

    #[serde(skip_serializing_if = "Option::is_none")]
    pub link_time: Option<f64>,

Which is only populated for targets that required linking.

  1. In the timings report, separate linking from other build steps

Choose a colour for html and a field for JSON and make it visually obvious to people

Notes

Implementing this enables generating the "Use a different linker" actionable suggestion proposed here
https://github.com/rust-lang/cargo/issues/10542

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/cargo/util/machine_message.rs with TimingInfo and the existing rmeta_time field, then trace timing collection for TargetKind::Bin and the timings report output. Done means link_time is populated only when linking occurs and linking is visibly separated in both HTML and JSON reports.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.