Skip to content

Commit f95a0e4

Browse files
Rollup merge of #145379 - joshtriplett:bootstrap-timings, r=jieyouxu
bootstrap: Support passing `--timings` to cargo Useful for optimizing the sequencing of the compiler's own build.
2 parents 09662f2 + 3ecea53 commit f95a0e4

File tree

12 files changed

+47
-12
lines changed

12 files changed

+47
-12
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
@@ -1271,7 +1271,7 @@ impl<'a> Builder<'a> {
12711271
pub fn new(build: &Build) -> Builder<'_> {
12721272
let paths = &build.config.paths;
12731273
let (kind, paths) = match build.config.cmd {
1274-
Subcommand::Build => (Kind::Build, &paths[..]),
1274+
Subcommand::Build { .. } => (Kind::Build, &paths[..]),
12751275
Subcommand::Check { .. } => (Kind::Check, &paths[..]),
12761276
Subcommand::Clippy { .. } => (Kind::Clippy, &paths[..]),
12771277
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
}
@@ -1396,7 +1396,7 @@ impl Config {
13961396
Subcommand::Test { .. }
13971397
| Subcommand::Miri { .. }
13981398
| Subcommand::Doc { .. }
1399-
| Subcommand::Build
1399+
| Subcommand::Build { .. }
14001400
| Subcommand::Bench { .. }
14011401
| Subcommand::Dist
14021402
| 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,

src/etc/completions/x.fish

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ complete -c x -n "__fish_x_using_subcommand build" -l llvm-profile-use -d 'use P
9797
complete -c x -n "__fish_x_using_subcommand build" -l reproducible-artifact -d 'Additional reproducible artifacts that should be added to the reproducible artifacts archive' -r
9898
complete -c x -n "__fish_x_using_subcommand build" -l set -d 'override options in bootstrap.toml' -r -f
9999
complete -c x -n "__fish_x_using_subcommand build" -l ci -d 'Make bootstrap to behave as it\'s running on the CI environment or not' -r -f -a "{true\t'',false\t''}"
100+
complete -c x -n "__fish_x_using_subcommand build" -l timings -d 'Pass `--timings` to Cargo to get crate build timings'
100101
complete -c x -n "__fish_x_using_subcommand build" -s v -l verbose -d 'use verbose output (-vv for very verbose)'
101102
complete -c x -n "__fish_x_using_subcommand build" -s i -l incremental -d 'use incremental compilation'
102103
complete -c x -n "__fish_x_using_subcommand build" -l include-default-paths -d 'include default paths in addition to the provided ones'
@@ -133,6 +134,7 @@ complete -c x -n "__fish_x_using_subcommand check" -l reproducible-artifact -d '
133134
complete -c x -n "__fish_x_using_subcommand check" -l set -d 'override options in bootstrap.toml' -r -f
134135
complete -c x -n "__fish_x_using_subcommand check" -l ci -d 'Make bootstrap to behave as it\'s running on the CI environment or not' -r -f -a "{true\t'',false\t''}"
135136
complete -c x -n "__fish_x_using_subcommand check" -l all-targets -d 'Check all targets'
137+
complete -c x -n "__fish_x_using_subcommand check" -l timings -d 'Pass `--timings` to Cargo to get crate build timings'
136138
complete -c x -n "__fish_x_using_subcommand check" -s v -l verbose -d 'use verbose output (-vv for very verbose)'
137139
complete -c x -n "__fish_x_using_subcommand check" -s i -l incremental -d 'use incremental compilation'
138140
complete -c x -n "__fish_x_using_subcommand check" -l include-default-paths -d 'include default paths in addition to the provided ones'

src/etc/completions/x.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Register-ArgumentCompleter -Native -CommandName 'x' -ScriptBlock {
102102
[CompletionResult]::new('--reproducible-artifact', '--reproducible-artifact', [CompletionResultType]::ParameterName, 'Additional reproducible artifacts that should be added to the reproducible artifacts archive')
103103
[CompletionResult]::new('--set', '--set', [CompletionResultType]::ParameterName, 'override options in bootstrap.toml')
104104
[CompletionResult]::new('--ci', '--ci', [CompletionResultType]::ParameterName, 'Make bootstrap to behave as it''s running on the CI environment or not')
105+
[CompletionResult]::new('--timings', '--timings', [CompletionResultType]::ParameterName, 'Pass `--timings` to Cargo to get crate build timings')
105106
[CompletionResult]::new('-v', '-v', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)')
106107
[CompletionResult]::new('--verbose', '--verbose', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)')
107108
[CompletionResult]::new('-i', '-i', [CompletionResultType]::ParameterName, 'use incremental compilation')
@@ -145,6 +146,7 @@ Register-ArgumentCompleter -Native -CommandName 'x' -ScriptBlock {
145146
[CompletionResult]::new('--set', '--set', [CompletionResultType]::ParameterName, 'override options in bootstrap.toml')
146147
[CompletionResult]::new('--ci', '--ci', [CompletionResultType]::ParameterName, 'Make bootstrap to behave as it''s running on the CI environment or not')
147148
[CompletionResult]::new('--all-targets', '--all-targets', [CompletionResultType]::ParameterName, 'Check all targets')
149+
[CompletionResult]::new('--timings', '--timings', [CompletionResultType]::ParameterName, 'Pass `--timings` to Cargo to get crate build timings')
148150
[CompletionResult]::new('-v', '-v', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)')
149151
[CompletionResult]::new('--verbose', '--verbose', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)')
150152
[CompletionResult]::new('-i', '-i', [CompletionResultType]::ParameterName, 'use incremental compilation')

src/etc/completions/x.py.fish

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ complete -c x.py -n "__fish_x.py_using_subcommand build" -l llvm-profile-use -d
9797
complete -c x.py -n "__fish_x.py_using_subcommand build" -l reproducible-artifact -d 'Additional reproducible artifacts that should be added to the reproducible artifacts archive' -r
9898
complete -c x.py -n "__fish_x.py_using_subcommand build" -l set -d 'override options in bootstrap.toml' -r -f
9999
complete -c x.py -n "__fish_x.py_using_subcommand build" -l ci -d 'Make bootstrap to behave as it\'s running on the CI environment or not' -r -f -a "{true\t'',false\t''}"
100+
complete -c x.py -n "__fish_x.py_using_subcommand build" -l timings -d 'Pass `--timings` to Cargo to get crate build timings'
100101
complete -c x.py -n "__fish_x.py_using_subcommand build" -s v -l verbose -d 'use verbose output (-vv for very verbose)'
101102
complete -c x.py -n "__fish_x.py_using_subcommand build" -s i -l incremental -d 'use incremental compilation'
102103
complete -c x.py -n "__fish_x.py_using_subcommand build" -l include-default-paths -d 'include default paths in addition to the provided ones'
@@ -133,6 +134,7 @@ complete -c x.py -n "__fish_x.py_using_subcommand check" -l reproducible-artifac
133134
complete -c x.py -n "__fish_x.py_using_subcommand check" -l set -d 'override options in bootstrap.toml' -r -f
134135
complete -c x.py -n "__fish_x.py_using_subcommand check" -l ci -d 'Make bootstrap to behave as it\'s running on the CI environment or not' -r -f -a "{true\t'',false\t''}"
135136
complete -c x.py -n "__fish_x.py_using_subcommand check" -l all-targets -d 'Check all targets'
137+
complete -c x.py -n "__fish_x.py_using_subcommand check" -l timings -d 'Pass `--timings` to Cargo to get crate build timings'
136138
complete -c x.py -n "__fish_x.py_using_subcommand check" -s v -l verbose -d 'use verbose output (-vv for very verbose)'
137139
complete -c x.py -n "__fish_x.py_using_subcommand check" -s i -l incremental -d 'use incremental compilation'
138140
complete -c x.py -n "__fish_x.py_using_subcommand check" -l include-default-paths -d 'include default paths in addition to the provided ones'

src/etc/completions/x.py.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
102102
[CompletionResult]::new('--reproducible-artifact', '--reproducible-artifact', [CompletionResultType]::ParameterName, 'Additional reproducible artifacts that should be added to the reproducible artifacts archive')
103103
[CompletionResult]::new('--set', '--set', [CompletionResultType]::ParameterName, 'override options in bootstrap.toml')
104104
[CompletionResult]::new('--ci', '--ci', [CompletionResultType]::ParameterName, 'Make bootstrap to behave as it''s running on the CI environment or not')
105+
[CompletionResult]::new('--timings', '--timings', [CompletionResultType]::ParameterName, 'Pass `--timings` to Cargo to get crate build timings')
105106
[CompletionResult]::new('-v', '-v', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)')
106107
[CompletionResult]::new('--verbose', '--verbose', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)')
107108
[CompletionResult]::new('-i', '-i', [CompletionResultType]::ParameterName, 'use incremental compilation')
@@ -145,6 +146,7 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
145146
[CompletionResult]::new('--set', '--set', [CompletionResultType]::ParameterName, 'override options in bootstrap.toml')
146147
[CompletionResult]::new('--ci', '--ci', [CompletionResultType]::ParameterName, 'Make bootstrap to behave as it''s running on the CI environment or not')
147148
[CompletionResult]::new('--all-targets', '--all-targets', [CompletionResultType]::ParameterName, 'Check all targets')
149+
[CompletionResult]::new('--timings', '--timings', [CompletionResultType]::ParameterName, 'Pass `--timings` to Cargo to get crate build timings')
148150
[CompletionResult]::new('-v', '-v', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)')
149151
[CompletionResult]::new('--verbose', '--verbose', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)')
150152
[CompletionResult]::new('-i', '-i', [CompletionResultType]::ParameterName, 'use incremental compilation')

src/etc/completions/x.py.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ _x.py() {
458458
return 0
459459
;;
460460
x.py__build)
461-
opts="-v -i -j -h --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --json-output --compile-time-deps --color --bypass-bootstrap-lock --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --ci --skip-std-check-if-no-download-rustc --help [PATHS]... [ARGS]..."
461+
opts="-v -i -j -h --timings --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --json-output --compile-time-deps --color --bypass-bootstrap-lock --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --ci --skip-std-check-if-no-download-rustc --help [PATHS]... [ARGS]..."
462462
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
463463
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
464464
return 0
@@ -644,7 +644,7 @@ _x.py() {
644644
return 0
645645
;;
646646
x.py__check)
647-
opts="-v -i -j -h --all-targets --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --json-output --compile-time-deps --color --bypass-bootstrap-lock --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --ci --skip-std-check-if-no-download-rustc --help [PATHS]... [ARGS]..."
647+
opts="-v -i -j -h --all-targets --timings --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --json-output --compile-time-deps --color --bypass-bootstrap-lock --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --ci --skip-std-check-if-no-download-rustc --help [PATHS]... [ARGS]..."
648648
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
649649
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
650650
return 0

src/etc/completions/x.py.zsh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ _arguments "${_arguments_options[@]}" : \
9090
'*--reproducible-artifact=[Additional reproducible artifacts that should be added to the reproducible artifacts archive]:REPRODUCIBLE_ARTIFACT:_default' \
9191
'*--set=[override options in bootstrap.toml]:section.option=value:' \
9292
'--ci=[Make bootstrap to behave as it'\''s running on the CI environment or not]:bool:(true false)' \
93+
'--timings[Pass \`--timings\` to Cargo to get crate build timings]' \
9394
'*-v[use verbose output (-vv for very verbose)]' \
9495
'*--verbose[use verbose output (-vv for very verbose)]' \
9596
'-i[use incremental compilation]' \
@@ -135,6 +136,7 @@ _arguments "${_arguments_options[@]}" : \
135136
'*--set=[override options in bootstrap.toml]:section.option=value:' \
136137
'--ci=[Make bootstrap to behave as it'\''s running on the CI environment or not]:bool:(true false)' \
137138
'--all-targets[Check all targets]' \
139+
'--timings[Pass \`--timings\` to Cargo to get crate build timings]' \
138140
'*-v[use verbose output (-vv for very verbose)]' \
139141
'*--verbose[use verbose output (-vv for very verbose)]' \
140142
'-i[use incremental compilation]' \

0 commit comments

Comments
 (0)