Skip to content

Using cargo run with bootstrap uses the host rustfmt, not nightly rustfmt #95136

Closed
@jyn514

Description

@jyn514

rust/src/bootstrap/config.rs

Lines 1095 to 1106 in c7ce69f

config.initial_rustfmt = config.initial_rustfmt.or_else({
let build = config.build;
let initial_rustc = &config.initial_rustc;
move || {
// Cargo does not provide a RUSTFMT environment variable, so we
// synthesize it manually.
let rustfmt = initial_rustc.with_file_name(exe("rustfmt", build));
if rustfmt.exists() { Some(rustfmt) } else { None }
}
});

The proper fix is to check if we're going through the cargo run entrypoint instead of x.py, and if so, download rustfmt from the nightly toolchain listed in src/stage0.json:

rust/src/stage0.json

Lines 8 to 11 in c7ce69f

"rustfmt": {
"date": "2022-02-23",
"version": "nightly"
},

Ideally we would eventually be able to move this into rustup, but that requires not only for rustup to add and release this feature, but also for all contributors to start using it. It shouldn't be too much extra work for bootstrap to do it itself in the meantime.

cc #94829, #94806 (comment), #94830 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions