Skip to content

Commit

Permalink
improve the external clippy usage
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Aug 23, 2024
1 parent 4fe847a commit 7335cfc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 52 deletions.
9 changes: 2 additions & 7 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,10 @@
# 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 must be used together with `clippy-driver` below.
# Note that this option should be used together with `rustc` option above,
# otherwise clippy will most likely fail due to toolchain conflict.
#cargo-clippy = "/path/to/cargo-clippy"

# Instead of downloading the src/stage0 version of clippy-driver specified,
# use this clippy-driver binary instead as the stage0 snapshot clippy-driver.
#
# Note that this option must be used together with `cargo-clippy` above.
#clippy-driver = "/path/to/clippy-driver"

# 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
29 changes: 0 additions & 29 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,32 +1148,3 @@ impl<'a> Builder<'a> {
cmd
}
}

pub(crate) fn install_external_stage0_clippy(builder: &Builder<'_>) -> PathBuf {
if builder.config.dry_run() {
return PathBuf::default();
}

builder.info("Installing external clippy to stage0 sysroot.");

let (Some(external_cargo_clippy), Some(external_clippy_driver)) =
(&builder.config.external_cargo_clippy, &builder.config.external_clippy_driver)
else {
panic!("`build.cargo-clippy` and `build.clippy-driver` must be configured together.");
};

let host = builder.config.build;
let bindir = builder.out.join(host.triple).join("stage0/bin");
t!(fs::create_dir_all(&bindir));

let cargo_clippy_destination = bindir.join(exe("cargo-clippy", host));
let _ = fs::remove_file(&cargo_clippy_destination);
builder.copy_link(external_cargo_clippy, &cargo_clippy_destination);

let clippy_driver_destination = bindir.join(exe("clippy-driver", host));
let _ = fs::remove_file(&clippy_driver_destination);
builder.copy_link(external_clippy_driver, &clippy_driver_destination);

assert!(cargo_clippy_destination.exists());
cargo_clippy_destination
}
11 changes: 5 additions & 6 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,12 +1298,11 @@ impl<'a> Builder<'a> {

pub fn cargo_clippy_cmd(&self, run_compiler: Compiler) -> BootstrapCommand {
if run_compiler.stage == 0 {
let cargo_clippy = if self.config.external_cargo_clippy.is_some() {
tool::install_external_stage0_clippy(self)
} else {
// `ensure(Clippy { stage: 0 })` *builds* clippy with stage0, it doesn't use the beta 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);
Expand Down
18 changes: 8 additions & 10 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ 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>,

pub external_cargo_clippy: Option<PathBuf>,
pub external_clippy_driver: Option<PathBuf>,

#[cfg(not(test))]
Expand Down Expand Up @@ -830,7 +830,6 @@ define_config! {
rustc: Option<PathBuf> = "rustc",
rustfmt: Option<PathBuf> = "rustfmt",
cargo_clippy: Option<PathBuf> = "cargo-clippy",
clippy_driver: Option<PathBuf> = "clippy-driver",
docs: Option<bool> = "docs",
compiler_docs: Option<bool> = "compiler-docs",
library_docs_private_items: Option<bool> = "library-docs-private-items",
Expand Down Expand Up @@ -1426,7 +1425,6 @@ impl Config {
rustc,
rustfmt,
cargo_clippy,
clippy_driver,
docs,
compiler_docs,
library_docs_private_items,
Expand Down Expand Up @@ -1479,6 +1477,12 @@ 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_rustc = if let Some(rustc) = rustc {
if !flags.skip_stage0_validation {
config.check_stage0_version(&rustc, "rustc");
Expand Down Expand Up @@ -1509,13 +1513,7 @@ impl Config {
.join(exe("cargo", config.build))
};

assert_eq!(
cargo_clippy.is_some(),
clippy_driver.is_some(),
"`build.cargo-clippy` and `build.clippy-driver` must be configured together."
);
config.external_cargo_clippy = cargo_clippy;
config.external_clippy_driver = clippy_driver;
config.initial_cargo_clippy = cargo_clippy;

// NOTE: it's important this comes *after* we set `initial_rustc` just above.
if config.dry_run() {
Expand Down

0 comments on commit 7335cfc

Please sign in to comment.