Skip to content

Commit 8a31837

Browse files
committed
Set opt-level for installing tool only on CI
ensure_version_or_cargo_install uses -Copt-level=0 for quicker installation. However, the flag affects the tool's performance. For example, typos-cli with opt-level=0 takes 15 seconds for checking ./compiler, but the tool with default opt-level only takes less than 1 sec. This commit enables the option only when the test tidy is run on CI.
1 parent a0f398e commit 8a31837

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/tools/tidy/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ pub fn ensure_version_or_cargo_install(
194194
// use --force to ensure that if the required version is bumped, we update it.
195195
// use --target-dir to ensure we have a build cache so repeated invocations aren't slow.
196196
// modify PATH so that cargo doesn't print a warning telling the user to modify the path.
197-
let cargo_exit_code = Command::new(cargo)
198-
.args(["install", "--locked", "--force", "--quiet"])
197+
let mut cmd = Command::new(cargo);
198+
cmd.args(["install", "--locked", "--force", "--quiet"])
199199
.arg("--root")
200200
.arg(&tool_root_dir)
201201
.arg("--target-dir")
@@ -208,10 +208,16 @@ pub fn ensure_version_or_cargo_install(
208208
.chain(std::iter::once(tool_bin_dir.clone())),
209209
)
210210
.expect("build dir contains invalid char"),
211-
)
212-
.env("RUSTFLAGS", "-Copt-level=0")
213-
.spawn()?
214-
.wait()?;
211+
);
212+
213+
// On CI, we set opt-level flag for quicker installation.
214+
// Since lower opt-level decreases the tool's performance,
215+
// we don't set this option on local.
216+
if CiEnv::is_ci() {
217+
cmd.env("RUSTFLAGS", "-Copt-level=0");
218+
}
219+
220+
let cargo_exit_code = cmd.spawn()?.wait()?;
215221
if !cargo_exit_code.success() {
216222
return Err(io::Error::other("cargo install failed"));
217223
}

0 commit comments

Comments
 (0)