Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -92,7 +92,7 @@ impl CommandLineStep for Std {
);

std_cargo(builder, target, &mut cargo, &self.crates);
if matches!(builder.config.cmd, Subcommand::Fix) {

@Zalathar Zalathar Aug 3, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I would have had to update the match to Subcommand::Fix { .. }, but I instead changed it to check builder.kind == Kind::Fix to bring it in line with other uses of builder.kind in this function.

View changes since the review

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");
}
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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(),
Expand Down
9 changes: 8 additions & 1 deletion src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[..]),
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2835,9 +2835,9 @@ mod snapshot {
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[check] rustc 1 <host> -> rustc 2 <host>
[build] rustc 0 <host> -> clippy-driver 1 <host>
[build] rustc 0 <host> -> cargo-clippy 1 <host>
[check] rustc 1 <host> -> rustc 2 <host>
[clippy] rustc 1 <host> -> miri 2 <host>
");
}
Expand Down
7 changes: 3 additions & 4 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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."
);
Expand All @@ -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 { .. }
Expand Down
11 changes: 9 additions & 2 deletions src/bootstrap/src/core/config/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,22 @@ pub enum Subcommand {
#[arg(global = true, short = 'F', action = clap::ArgAction::Append, value_name = "LINT")]
forbid: Vec<String>,
},

/// Run cargo fix
#[command(long_about = "\n
Arguments:
This subcommand accepts a number of paths to directories to the crates
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)]
Comment thread
Zalathar marked this conversation as resolved.
allow_dirty: bool,
},

/// Run rustfmt
#[command(
name = "fmt",
long_about = "\n
Expand All @@ -327,7 +335,6 @@ pub enum Subcommand {
./x.py fmt
./x.py fmt --check"
)]
/// Run rustfmt
Format {
/// check formatting instead of applying
#[arg(long)]
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.<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.",
},
];
1 change: 1 addition & 0 deletions src/etc/completions/x.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions src/etc/completions/x.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions src/etc/completions/x.py.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions src/etc/completions/x.py.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/etc/completions/x.py.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/etc/completions/x.py.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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]' \
Expand Down
2 changes: 1 addition & 1 deletion src/etc/completions/x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/etc/completions/x.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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]' \
Expand Down
Loading