Skip to content

Commit 89e0a0c

Browse files
committed
support custom clippy
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. Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent d626fbd commit 89e0a0c

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,3 +1148,32 @@ impl<'a> Builder<'a> {
11481148
cmd
11491149
}
11501150
}
1151+
1152+
pub(crate) fn install_external_stage0_clippy(builder: &Builder<'_>) -> PathBuf {
1153+
if builder.config.dry_run() {
1154+
return PathBuf::default();
1155+
}
1156+
1157+
builder.info("Installing external clippy to stage0 sysroot.");
1158+
1159+
let (Some(external_cargo_clippy), Some(external_clippy_driver)) =
1160+
(&builder.config.external_cargo_clippy, &builder.config.external_clippy_driver)
1161+
else {
1162+
panic!("`build.cargo-clippy` and `build.clippy-driver` must be configured together.");
1163+
};
1164+
1165+
let host = builder.config.build;
1166+
let bindir = builder.out.join(host.triple).join("stage0/bin");
1167+
t!(fs::create_dir_all(&bindir));
1168+
1169+
let cargo_clippy_destination = bindir.join(exe("cargo-clippy", host));
1170+
let _ = fs::remove_file(&cargo_clippy_destination);
1171+
builder.copy_link(external_cargo_clippy, &cargo_clippy_destination);
1172+
1173+
let clippy_driver_destination = bindir.join(exe("clippy-driver", host));
1174+
let _ = fs::remove_file(&clippy_driver_destination);
1175+
builder.copy_link(external_clippy_driver, &clippy_driver_destination);
1176+
1177+
assert!(cargo_clippy_destination.exists());
1178+
cargo_clippy_destination
1179+
}

src/bootstrap/src/core/builder.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,8 +1298,13 @@ impl<'a> Builder<'a> {
12981298

12991299
pub fn cargo_clippy_cmd(&self, run_compiler: Compiler) -> BootstrapCommand {
13001300
if run_compiler.stage == 0 {
1301-
// `ensure(Clippy { stage: 0 })` *builds* clippy with stage0, it doesn't use the beta clippy.
1302-
let cargo_clippy = self.build.config.download_clippy();
1301+
let cargo_clippy = if self.config.external_cargo_clippy.is_some() {
1302+
tool::install_external_stage0_clippy(self)
1303+
} else {
1304+
// `ensure(Clippy { stage: 0 })` *builds* clippy with stage0, it doesn't use the beta clippy.
1305+
self.build.config.download_clippy()
1306+
};
1307+
13031308
let mut cmd = command(cargo_clippy);
13041309
cmd.env("CARGO", &self.initial_cargo);
13051310
return cmd;

src/bootstrap/src/core/config/config.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ pub struct Config {
337337
pub initial_cargo: PathBuf,
338338
pub initial_rustc: PathBuf,
339339

340+
pub external_cargo_clippy: Option<PathBuf>,
341+
pub external_clippy_driver: Option<PathBuf>,
342+
340343
#[cfg(not(test))]
341344
initial_rustfmt: RefCell<RustfmtState>,
342345
#[cfg(test)]
@@ -826,6 +829,8 @@ define_config! {
826829
cargo: Option<PathBuf> = "cargo",
827830
rustc: Option<PathBuf> = "rustc",
828831
rustfmt: Option<PathBuf> = "rustfmt",
832+
cargo_clippy: Option<PathBuf> = "cargo-clippy",
833+
clippy_driver: Option<PathBuf> = "clippy-driver",
829834
docs: Option<bool> = "docs",
830835
compiler_docs: Option<bool> = "compiler-docs",
831836
library_docs_private_items: Option<bool> = "library-docs-private-items",
@@ -1420,6 +1425,8 @@ impl Config {
14201425
cargo,
14211426
rustc,
14221427
rustfmt,
1428+
cargo_clippy,
1429+
clippy_driver,
14231430
docs,
14241431
compiler_docs,
14251432
library_docs_private_items,
@@ -1502,6 +1509,14 @@ impl Config {
15021509
.join(exe("cargo", config.build))
15031510
};
15041511

1512+
assert_eq!(
1513+
cargo_clippy.is_some(),
1514+
clippy_driver.is_some(),
1515+
"`build.cargo-clippy` and `build.clippy-driver` must be configured together."
1516+
);
1517+
config.external_cargo_clippy = cargo_clippy;
1518+
config.external_clippy_driver = clippy_driver;
1519+
15051520
// NOTE: it's important this comes *after* we set `initial_rustc` just above.
15061521
if config.dry_run() {
15071522
let dir = config.out.join("tmp-dry-run");

0 commit comments

Comments
 (0)