Skip to content

Commit d10a8a3

Browse files
committed
bootstrap: Support passing --timings to cargo
Useful for optimizing the sequencing of the compiler's own build.
1 parent 3672a55 commit d10a8a3

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ impl Builder<'_> {
499499
build_stamp::clear_if_dirty(self, &out_dir, &backend);
500500
}
501501

502+
if self.config.cmd.timings() {
503+
cargo.arg("--timings");
504+
}
505+
502506
if cmd_kind == Kind::Doc {
503507
let my_out = match mode {
504508
// This is the intended out directory for compiler documentation.

src/bootstrap/src/core/builder/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ impl<'a> Builder<'a> {
12671267
pub fn new(build: &Build) -> Builder<'_> {
12681268
let paths = &build.config.paths;
12691269
let (kind, paths) = match build.config.cmd {
1270-
Subcommand::Build => (Kind::Build, &paths[..]),
1270+
Subcommand::Build { .. } => (Kind::Build, &paths[..]),
12711271
Subcommand::Check { .. } => (Kind::Check, &paths[..]),
12721272
Subcommand::Clippy { .. } => (Kind::Clippy, &paths[..]),
12731273
Subcommand::Fix => (Kind::Fix, &paths[..]),

src/bootstrap/src/core/config/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ impl Config {
13421342
Subcommand::Doc { .. } => {
13431343
flags_stage.or(build_doc_stage).unwrap_or(if download_rustc { 2 } else { 1 })
13441344
}
1345-
Subcommand::Build => {
1345+
Subcommand::Build { .. } => {
13461346
flags_stage.or(build_build_stage).unwrap_or(if download_rustc { 2 } else { 1 })
13471347
}
13481348
Subcommand::Test { .. } | Subcommand::Miri { .. } => {
@@ -1363,7 +1363,7 @@ impl Config {
13631363

13641364
// Now check that the selected stage makes sense, and if not, print a warning and end
13651365
match (config.stage, &config.cmd) {
1366-
(0, Subcommand::Build) => {
1366+
(0, Subcommand::Build { .. }) => {
13671367
eprintln!("ERROR: cannot build anything on stage 0. Use at least stage 1.");
13681368
exit!(1);
13691369
}
@@ -1392,7 +1392,7 @@ impl Config {
13921392
Subcommand::Test { .. }
13931393
| Subcommand::Miri { .. }
13941394
| Subcommand::Doc { .. }
1395-
| Subcommand::Build
1395+
| Subcommand::Build { .. }
13961396
| Subcommand::Bench { .. }
13971397
| Subcommand::Dist
13981398
| Subcommand::Install => {

src/bootstrap/src/core/config/flags.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fn normalize_args(args: &[String]) -> Vec<String> {
241241
it.collect()
242242
}
243243

244-
#[derive(Debug, Clone, Default, clap::Subcommand)]
244+
#[derive(Debug, Clone, clap::Subcommand)]
245245
pub enum Subcommand {
246246
#[command(aliases = ["b"], long_about = "\n
247247
Arguments:
@@ -256,8 +256,11 @@ pub enum Subcommand {
256256
./x.py build --stage 0
257257
./x.py build ")]
258258
/// Compile either the compiler or libraries
259-
#[default]
260-
Build,
259+
Build {
260+
#[arg(long)]
261+
/// Pass `--timings` to Cargo to get crate build timings
262+
timings: bool,
263+
},
261264
#[command(aliases = ["c"], long_about = "\n
262265
Arguments:
263266
This subcommand accepts a number of paths to directories to the crates
@@ -269,6 +272,9 @@ pub enum Subcommand {
269272
#[arg(long)]
270273
/// Check all targets
271274
all_targets: bool,
275+
#[arg(long)]
276+
/// Pass `--timings` to Cargo to get crate build timings
277+
timings: bool,
272278
},
273279
/// Run Clippy (uses rustup/cargo-installed clippy binary)
274280
#[command(long_about = "\n
@@ -494,11 +500,17 @@ Arguments:
494500
Perf(PerfArgs),
495501
}
496502

503+
impl Default for Subcommand {
504+
fn default() -> Self {
505+
Subcommand::Build { timings: false }
506+
}
507+
}
508+
497509
impl Subcommand {
498510
pub fn kind(&self) -> Kind {
499511
match self {
500512
Subcommand::Bench { .. } => Kind::Bench,
501-
Subcommand::Build => Kind::Build,
513+
Subcommand::Build { .. } => Kind::Build,
502514
Subcommand::Check { .. } => Kind::Check,
503515
Subcommand::Clippy { .. } => Kind::Clippy,
504516
Subcommand::Doc { .. } => Kind::Doc,
@@ -626,6 +638,13 @@ impl Subcommand {
626638
}
627639
}
628640

641+
pub fn timings(&self) -> bool {
642+
match *self {
643+
Subcommand::Build { timings, .. } | Subcommand::Check { timings, .. } => timings,
644+
_ => false,
645+
}
646+
}
647+
629648
pub fn vendor_versioned_dirs(&self) -> bool {
630649
match *self {
631650
Subcommand::Vendor { versioned_dirs, .. } => versioned_dirs,

0 commit comments

Comments
 (0)