Skip to content

Commit 7fe3c70

Browse files
committed
Disable all incremental compilation for CARGO_BUILD_INCREMENTAL=false
1 parent 0f9a492 commit 7fe3c70

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

build_system/build_backend.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::PathBuf;
33

44
use super::path::{Dirs, RelPath};
55
use super::rustc_info::get_file_name;
6-
use super::utils::{is_ci, is_ci_opt, CargoProject, Compiler};
6+
use super::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler};
77

88
pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
99

@@ -14,18 +14,14 @@ pub(crate) fn build_backend(
1414
use_unstable_features: bool,
1515
) -> PathBuf {
1616
let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs);
17-
18-
cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode
17+
maybe_incremental(&mut cmd);
1918

2019
let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default();
2120

2221
if is_ci() {
2322
// Deny warnings on CI
2423
rustflags += " -Dwarnings";
2524

26-
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
27-
cmd.env("CARGO_BUILD_INCREMENTAL", "false");
28-
2925
if !is_ci_opt() {
3026
cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true");
3127
cmd.env("CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS", "true");

build_system/build_sysroot.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::process::{self, Command};
55
use super::path::{Dirs, RelPath};
66
use super::rustc_info::{get_file_name, get_rustc_version};
77
use super::utils::{
8-
is_ci, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler,
8+
maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler,
99
};
1010
use super::{CodegenBackend, SysrootKind};
1111

@@ -274,11 +274,7 @@ fn build_clif_sysroot_for_triple(
274274
}
275275
compiler.rustflags += &rustflags;
276276
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
277-
build_cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode
278-
if is_ci() {
279-
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
280-
build_cmd.env("CARGO_BUILD_INCREMENTAL", "false");
281-
}
277+
maybe_incremental(&mut build_cmd);
282278
if channel == "release" {
283279
build_cmd.arg("--release");
284280
}

build_system/utils.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,13 @@ pub(crate) fn is_ci() -> bool {
258258
pub(crate) fn is_ci_opt() -> bool {
259259
env::var("CI_OPT").is_ok()
260260
}
261+
262+
pub(crate) fn maybe_incremental(cmd: &mut Command) {
263+
if is_ci() || std::env::var("CARGO_BUILD_INCREMENTAL").map_or(false, |val| val == "false") {
264+
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
265+
cmd.env("CARGO_BUILD_INCREMENTAL", "false");
266+
} else {
267+
// Force incr comp even in release mode unless in CI or incremental builds are explicitly disabled
268+
cmd.env("CARGO_BUILD_INCREMENTAL", "true");
269+
}
270+
}

0 commit comments

Comments
 (0)