diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index 874a758bd9b38..0acbcd64f067c 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -194,8 +194,8 @@ pub fn ensure_version_or_cargo_install( // use --force to ensure that if the required version is bumped, we update it. // use --target-dir to ensure we have a build cache so repeated invocations aren't slow. // modify PATH so that cargo doesn't print a warning telling the user to modify the path. - let cargo_exit_code = Command::new(cargo) - .args(["install", "--locked", "--force", "--quiet"]) + let mut cmd = Command::new(cargo); + cmd.args(["install", "--locked", "--force", "--quiet"]) .arg("--root") .arg(&tool_root_dir) .arg("--target-dir") @@ -208,10 +208,16 @@ pub fn ensure_version_or_cargo_install( .chain(std::iter::once(tool_bin_dir.clone())), ) .expect("build dir contains invalid char"), - ) - .env("RUSTFLAGS", "-Copt-level=0") - .spawn()? - .wait()?; + ); + + // On CI, we set opt-level flag for quicker installation. + // Since lower opt-level decreases the tool's performance, + // we don't set this option on local. + if CiEnv::is_ci() { + cmd.env("RUSTFLAGS", "-Copt-level=0"); + } + + let cargo_exit_code = cmd.spawn()?.wait()?; if !cargo_exit_code.success() { return Err(io::Error::other("cargo install failed")); }