Skip to content

Commit

Permalink
Rollup merge of rust-lang#129152 - onur-ozkan:custom-clippy, r=Kobzol
Browse files Browse the repository at this point in the history
custom/external clippy support for bootstrapping

Similar to cargo, rustc, and rustfmt, this adds the support of using custom clippy on bootstrap. It’s designed for those who want to test their own clippy builds or avoid downloading the stage0 clippy.

Closes rust-lang#121518
  • Loading branch information
matthiaskrgr authored Sep 3, 2024
2 parents 6199b69 + 1a991e5 commit 11398ed
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
7 changes: 7 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@
# use this rustfmt binary instead as the stage0 snapshot rustfmt.
#rustfmt = "/path/to/rustfmt"

# Instead of downloading the src/stage0 version of cargo-clippy specified,
# use this cargo-clippy binary instead as the stage0 snapshot cargo-clippy.
#
# Note that this option should be used with the same toolchain as the `rustc` option above.
# Otherwise, clippy is likely to fail due to a toolchain conflict.
#cargo-clippy = "/path/to/cargo-clippy"

# Whether to build documentation by default. If false, rustdoc and
# friends will still be compiled but they will not be used to generate any
# documentation.
Expand Down
8 changes: 6 additions & 2 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,12 @@ impl<'a> Builder<'a> {

pub fn cargo_clippy_cmd(&self, run_compiler: Compiler) -> BootstrapCommand {
if run_compiler.stage == 0 {
// `ensure(Clippy { stage: 0 })` *builds* clippy with stage0, it doesn't use the beta clippy.
let cargo_clippy = self.build.config.download_clippy();
let cargo_clippy = self
.config
.initial_cargo_clippy
.clone()
.unwrap_or_else(|| self.build.config.download_clippy());

let mut cmd = command(cargo_clippy);
cmd.env("CARGO", &self.initial_cargo);
return cmd;
Expand Down
11 changes: 11 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ pub struct Config {
// These are either the stage0 downloaded binaries or the locally installed ones.
pub initial_cargo: PathBuf,
pub initial_rustc: PathBuf,
pub initial_cargo_clippy: Option<PathBuf>,

#[cfg(not(test))]
initial_rustfmt: RefCell<RustfmtState>,
Expand Down Expand Up @@ -834,6 +835,7 @@ define_config! {
cargo: Option<PathBuf> = "cargo",
rustc: Option<PathBuf> = "rustc",
rustfmt: Option<PathBuf> = "rustfmt",
cargo_clippy: Option<PathBuf> = "cargo-clippy",
docs: Option<bool> = "docs",
compiler_docs: Option<bool> = "compiler-docs",
library_docs_private_items: Option<bool> = "library-docs-private-items",
Expand Down Expand Up @@ -1439,6 +1441,7 @@ impl Config {
cargo,
rustc,
rustfmt,
cargo_clippy,
docs,
compiler_docs,
library_docs_private_items,
Expand Down Expand Up @@ -1491,6 +1494,14 @@ impl Config {
config.out = absolute(&config.out).expect("can't make empty path absolute");
}

if cargo_clippy.is_some() && rustc.is_none() {
println!(
"WARNING: Using `build.cargo-clippy` without `build.rustc` usually fails due to toolchain conflict."
);
}

config.initial_cargo_clippy = cargo_clippy;

config.initial_rustc = if let Some(rustc) = rustc {
if !flags.skip_stage0_validation {
config.check_stage0_version(&rustc, "rustc");
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 @@ -235,4 +235,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "The `build.profiler` option now tries to use source code from `download-ci-llvm` if possible, instead of checking out the `src/llvm-project` submodule.",
},
ChangeInfo {
change_id: 129152,
severity: ChangeSeverity::Info,
summary: "New option `build.cargo-clippy` added for supporting the use of custom/external clippy.",
},
];

0 comments on commit 11398ed

Please sign in to comment.