diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 2fc72a42b0e54..e35cd50204c45 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -18,7 +18,7 @@ use crate::core::builder::{ }; use crate::core::config::TargetSelection; use crate::utils::build_stamp::{self, BuildStamp}; -use crate::{CodegenBackendKind, Compiler, Mode, Subcommand, t}; +use crate::{CodegenBackendKind, Compiler, Mode, t}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Std { @@ -92,7 +92,7 @@ impl CommandLineStep for Std { ); std_cargo(builder, target, &mut cargo, &self.crates); - if matches!(builder.config.cmd, Subcommand::Fix) { + if builder.kind == Kind::Fix { // By default, cargo tries to fix all targets. Tell it not to fix tests until we've added `test` to the sysroot. cargo.arg("--lib"); } @@ -327,7 +327,7 @@ impl CommandLineStep for Rustc { run.builder.ensure(Rustc::new(run.builder, run.target, crates)); } - /// Check the compiler. + /// Run `cargo check` (or `cargo fix`) on one or more compiler crates. /// /// This will check the compiler for a particular stage of the build using /// the `compiler` targeting the `target` architecture. The artifacts @@ -344,7 +344,7 @@ impl CommandLineStep for Rustc { Mode::Rustc, SourceType::InTree, target, - Kind::Check, + builder.kind, ); rustc_cargo(builder, &mut cargo, target, &build_compiler, &self.crates); @@ -358,7 +358,7 @@ impl CommandLineStep for Rustc { } let _guard = builder.msg( - Kind::Check, + builder.kind, format_args!("compiler artifacts{}", crate_description(&self.crates)), Mode::Rustc, self.build_compiler.build_compiler(), diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index 3a1e4299b5475..47f95e06dd76b 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -12,7 +12,7 @@ use crate::utils::build_stamp; use crate::utils::helpers::{self, LldThreads, check_cfg_arg, linker_flags}; use crate::{ BootstrapCommand, CLang, Compiler, Config, DryRun, EXTRA_CHECK_CFGS, GitRepo, Mode, - RemapScheme, TargetSelection, command, prepare_behaviour_dump_dir, t, + RemapScheme, Subcommand, TargetSelection, command, prepare_behaviour_dump_dir, t, }; /// Represents flag values in `String` form with a `\x1f` delimiter to pass to the compiler later. @@ -706,6 +706,13 @@ impl Builder<'_> { } } + // Forward `./x fix --allow-dirty` from bootstrap to cargo. + if let Subcommand::Fix { allow_dirty } = self.config.cmd + && allow_dirty + { + cargo.arg("--allow-dirty"); + } + let build_compiler_stage = if compiler.stage == 0 && self.local_rebuild { // Assume the local-rebuild rustc already has stage1 features. 1 diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 030dff229e9fb..606e727cf4b95 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -1130,7 +1130,7 @@ impl<'a> Builder<'a> { Subcommand::Build { .. } => (Kind::Build, &paths[..]), Subcommand::Check { .. } => (Kind::Check, &paths[..]), Subcommand::Clippy { .. } => (Kind::Clippy, &paths[..]), - Subcommand::Fix => (Kind::Fix, &paths[..]), + Subcommand::Fix { .. } => (Kind::Fix, &paths[..]), Subcommand::Doc { .. } => (Kind::Doc, &paths[..]), Subcommand::Test { .. } => (Kind::Test, &paths[..]), Subcommand::Miri { .. } => (Kind::Miri, &paths[..]), diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index f56de744883b8..0b8bd715cc8bb 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -2835,9 +2835,9 @@ mod snapshot { [build] llvm [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 - [check] rustc 1 -> rustc 2 [build] rustc 0 -> clippy-driver 1 [build] rustc 0 -> cargo-clippy 1 + [check] rustc 1 -> rustc 2 [clippy] rustc 1 -> miri 2 "); } diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 81a425fba1cab..f56bee1932def 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -1186,8 +1186,7 @@ impl Config { let download_rustc = download_rustc_commit.is_some(); let stage = match flags_cmd { - Subcommand::Check { .. } => flags_stage.or(build_check_stage).unwrap_or(1), - Subcommand::Clippy { .. } | Subcommand::Fix => { + Subcommand::Check { .. } | Subcommand::Clippy { .. } | Subcommand::Fix { .. } => { flags_stage.or(build_check_stage).unwrap_or(1) } // `download-rustc` only has a speed-up for stage2 builds. Default to stage2 unless explicitly overridden. @@ -1260,7 +1259,7 @@ impl Config { exit!(1); } - if matches!(flags_cmd, Subcommand::Fix) { + if matches!(flags_cmd, Subcommand::Fix { .. }) { eprintln!( "WARNING: `x fix` is provided on a best-effort basis and does not support all `cargo fix` options correctly." ); @@ -1286,7 +1285,7 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to Subcommand::Clean { .. } | Subcommand::Check { .. } | Subcommand::Clippy { .. } - | Subcommand::Fix + | Subcommand::Fix { .. } | Subcommand::Run { .. } | Subcommand::Setup { .. } | Subcommand::Format { .. } diff --git a/src/bootstrap/src/core/config/flags.rs b/src/bootstrap/src/core/config/flags.rs index fba3a9fe74705..f43a6fddfd557 100644 --- a/src/bootstrap/src/core/config/flags.rs +++ b/src/bootstrap/src/core/config/flags.rs @@ -310,6 +310,7 @@ pub enum Subcommand { #[arg(global = true, short = 'F', action = clap::ArgAction::Append, value_name = "LINT")] forbid: Vec, }, + /// Run cargo fix #[command(long_about = "\n Arguments: @@ -317,7 +318,14 @@ pub enum Subcommand { and/or artifacts to run `cargo fix` against. For example: ./x.py fix library/core ./x.py fix library/core library/proc_macro")] - Fix, + Fix { + /// Pass `--allow-dirty` to `cargo fix`, allowing it to run even if the + /// current git checkout has uncommitted changes. + #[arg(long)] + allow_dirty: bool, + }, + + /// Run rustfmt #[command( name = "fmt", long_about = "\n @@ -327,7 +335,6 @@ pub enum Subcommand { ./x.py fmt ./x.py fmt --check" )] - /// Run rustfmt Format { /// check formatting instead of applying #[arg(long)] diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index 25c0963aa4191..a4c30ee2ce985 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -671,4 +671,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Warning, summary: "The `override-allocator` option has been renamed: The global setting is now `build.allocator` and the per-target setting is `target..allocator`. It can now be set to 'system' to explicitly request the system allocator.", }, + ChangeInfo { + change_id: 160417, + severity: ChangeSeverity::Info, + summary: "`./x fix` should now work properly on compiler crates, and now understands the `--allow-dirty` flag.", + }, ]; diff --git a/src/etc/completions/x.fish b/src/etc/completions/x.fish index 4d40b28414677..3afa7032b3697 100644 --- a/src/etc/completions/x.fish +++ b/src/etc/completions/x.fish @@ -296,6 +296,7 @@ complete -c x -n "__fish_x_using_subcommand fix" -l llvm-profile-use -d 'use PGO complete -c x -n "__fish_x_using_subcommand fix" -l reproducible-artifact -d 'Additional reproducible artifacts that should be added to the reproducible artifacts archive' -r complete -c x -n "__fish_x_using_subcommand fix" -l set -d 'override options in bootstrap.toml' -r -f complete -c x -n "__fish_x_using_subcommand fix" -l ci -d 'Make bootstrap to behave as it\'s running on the CI environment or not' -r -f -a "{true\t'',false\t''}" +complete -c x -n "__fish_x_using_subcommand fix" -l allow-dirty -d 'Pass `--allow-dirty` to `cargo fix`, allowing it to run even if the current git checkout has uncommitted changes' complete -c x -n "__fish_x_using_subcommand fix" -s v -l verbose -d 'use verbose output (-vv for very verbose)' complete -c x -n "__fish_x_using_subcommand fix" -s q -l quiet -d 'use quiet output' complete -c x -n "__fish_x_using_subcommand fix" -s i -l incremental -d 'use incremental compilation' diff --git a/src/etc/completions/x.ps1 b/src/etc/completions/x.ps1 index f9bebb22b916f..fce6898dd0069 100644 --- a/src/etc/completions/x.ps1 +++ b/src/etc/completions/x.ps1 @@ -342,6 +342,7 @@ Register-ArgumentCompleter -Native -CommandName 'x' -ScriptBlock { [CompletionResult]::new('--reproducible-artifact', '--reproducible-artifact', [CompletionResultType]::ParameterName, 'Additional reproducible artifacts that should be added to the reproducible artifacts archive') [CompletionResult]::new('--set', '--set', [CompletionResultType]::ParameterName, 'override options in bootstrap.toml') [CompletionResult]::new('--ci', '--ci', [CompletionResultType]::ParameterName, 'Make bootstrap to behave as it''s running on the CI environment or not') + [CompletionResult]::new('--allow-dirty', '--allow-dirty', [CompletionResultType]::ParameterName, 'Pass `--allow-dirty` to `cargo fix`, allowing it to run even if the current git checkout has uncommitted changes') [CompletionResult]::new('-v', '-v', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)') [CompletionResult]::new('--verbose', '--verbose', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)') [CompletionResult]::new('-q', '-q', [CompletionResultType]::ParameterName, 'use quiet output') diff --git a/src/etc/completions/x.py.fish b/src/etc/completions/x.py.fish index b098de6e7daff..6474cecae92a1 100644 --- a/src/etc/completions/x.py.fish +++ b/src/etc/completions/x.py.fish @@ -296,6 +296,7 @@ complete -c x.py -n "__fish_x.py_using_subcommand fix" -l llvm-profile-use -d 'u complete -c x.py -n "__fish_x.py_using_subcommand fix" -l reproducible-artifact -d 'Additional reproducible artifacts that should be added to the reproducible artifacts archive' -r complete -c x.py -n "__fish_x.py_using_subcommand fix" -l set -d 'override options in bootstrap.toml' -r -f complete -c x.py -n "__fish_x.py_using_subcommand fix" -l ci -d 'Make bootstrap to behave as it\'s running on the CI environment or not' -r -f -a "{true\t'',false\t''}" +complete -c x.py -n "__fish_x.py_using_subcommand fix" -l allow-dirty -d 'Pass `--allow-dirty` to `cargo fix`, allowing it to run even if the current git checkout has uncommitted changes' complete -c x.py -n "__fish_x.py_using_subcommand fix" -s v -l verbose -d 'use verbose output (-vv for very verbose)' complete -c x.py -n "__fish_x.py_using_subcommand fix" -s q -l quiet -d 'use quiet output' complete -c x.py -n "__fish_x.py_using_subcommand fix" -s i -l incremental -d 'use incremental compilation' diff --git a/src/etc/completions/x.py.ps1 b/src/etc/completions/x.py.ps1 index 6c952de7eaac9..e50edbb800ec4 100644 --- a/src/etc/completions/x.py.ps1 +++ b/src/etc/completions/x.py.ps1 @@ -342,6 +342,7 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock { [CompletionResult]::new('--reproducible-artifact', '--reproducible-artifact', [CompletionResultType]::ParameterName, 'Additional reproducible artifacts that should be added to the reproducible artifacts archive') [CompletionResult]::new('--set', '--set', [CompletionResultType]::ParameterName, 'override options in bootstrap.toml') [CompletionResult]::new('--ci', '--ci', [CompletionResultType]::ParameterName, 'Make bootstrap to behave as it''s running on the CI environment or not') + [CompletionResult]::new('--allow-dirty', '--allow-dirty', [CompletionResultType]::ParameterName, 'Pass `--allow-dirty` to `cargo fix`, allowing it to run even if the current git checkout has uncommitted changes') [CompletionResult]::new('-v', '-v', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)') [CompletionResult]::new('--verbose', '--verbose', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)') [CompletionResult]::new('-q', '-q', [CompletionResultType]::ParameterName, 'use quiet output') diff --git a/src/etc/completions/x.py.sh b/src/etc/completions/x.py.sh index b2542b94b9468..1266f85addd8d 100644 --- a/src/etc/completions/x.py.sh +++ b/src/etc/completions/x.py.sh @@ -2160,7 +2160,7 @@ _x.py() { return 0 ;; x.py__fix) - opts="-v -q -i -j -h --verbose --quiet --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]..." + opts="-v -q -i -j -h --allow-dirty --verbose --quiet --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]..." if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 diff --git a/src/etc/completions/x.py.zsh b/src/etc/completions/x.py.zsh index 5199c6cbaf350..57c8080fa369f 100644 --- a/src/etc/completions/x.py.zsh +++ b/src/etc/completions/x.py.zsh @@ -335,6 +335,7 @@ _arguments "${_arguments_options[@]}" : \ '*--reproducible-artifact=[Additional reproducible artifacts that should be added to the reproducible artifacts archive]:REPRODUCIBLE_ARTIFACT:_default' \ '*--set=[override options in bootstrap.toml]:section.option=value:' \ '--ci=[Make bootstrap to behave as it'\''s running on the CI environment or not]:bool:(true false)' \ +'--allow-dirty[Pass \`--allow-dirty\` to \`cargo fix\`, allowing it to run even if the current git checkout has uncommitted changes]' \ '(-q --quiet)*-v[use verbose output (-vv for very verbose)]' \ '(-q --quiet)*--verbose[use verbose output (-vv for very verbose)]' \ '(-v --verbose)-q[use quiet output]' \ diff --git a/src/etc/completions/x.sh b/src/etc/completions/x.sh index 5740459a414d2..644c656514f6c 100644 --- a/src/etc/completions/x.sh +++ b/src/etc/completions/x.sh @@ -2160,7 +2160,7 @@ _x() { return 0 ;; x__fix) - opts="-v -q -i -j -h --verbose --quiet --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]..." + opts="-v -q -i -j -h --allow-dirty --verbose --quiet --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]..." if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 diff --git a/src/etc/completions/x.zsh b/src/etc/completions/x.zsh index 31d9e43ef8e89..66d41a91118f3 100644 --- a/src/etc/completions/x.zsh +++ b/src/etc/completions/x.zsh @@ -335,6 +335,7 @@ _arguments "${_arguments_options[@]}" : \ '*--reproducible-artifact=[Additional reproducible artifacts that should be added to the reproducible artifacts archive]:REPRODUCIBLE_ARTIFACT:_default' \ '*--set=[override options in bootstrap.toml]:section.option=value:' \ '--ci=[Make bootstrap to behave as it'\''s running on the CI environment or not]:bool:(true false)' \ +'--allow-dirty[Pass \`--allow-dirty\` to \`cargo fix\`, allowing it to run even if the current git checkout has uncommitted changes]' \ '(-q --quiet)*-v[use verbose output (-vv for very verbose)]' \ '(-q --quiet)*--verbose[use verbose output (-vv for very verbose)]' \ '(-v --verbose)-q[use quiet output]' \