Disable all incremental compilation for CARGO_BUILD_INCREMENTAL=false

This commit is contained in:
bjorn3 2023-05-29 13:18:41 +00:00
parent eb3e8bb7d7
commit 6b9af8cb36
3 changed files with 14 additions and 12 deletions

View File

@ -3,7 +3,7 @@
use super::path::{Dirs, RelPath};
use super::rustc_info::get_file_name;
use super::utils::{is_ci, is_ci_opt, CargoProject, Compiler};
use super::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler};
pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
@ -14,8 +14,7 @@ pub(crate) fn build_backend(
use_unstable_features: bool,
) -> PathBuf {
let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs);
cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode
maybe_incremental(&mut cmd);
let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default();
@ -23,9 +22,6 @@ pub(crate) fn build_backend(
// Deny warnings on CI
rustflags += " -Dwarnings";
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
cmd.env("CARGO_BUILD_INCREMENTAL", "false");
if !is_ci_opt() {
cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true");
cmd.env("CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS", "true");

View File

@ -5,7 +5,7 @@
use super::path::{Dirs, RelPath};
use super::rustc_info::{get_file_name, get_rustc_version};
use super::utils::{
is_ci, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler,
maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler,
};
use super::{CodegenBackend, SysrootKind};
@ -274,11 +274,7 @@ fn build_clif_sysroot_for_triple(
}
compiler.rustflags += &rustflags;
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
build_cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode
if is_ci() {
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
build_cmd.env("CARGO_BUILD_INCREMENTAL", "false");
}
maybe_incremental(&mut build_cmd);
if channel == "release" {
build_cmd.arg("--release");
}

View File

@ -258,3 +258,13 @@ pub(crate) fn is_ci() -> bool {
pub(crate) fn is_ci_opt() -> bool {
env::var("CI_OPT").is_ok()
}
pub(crate) fn maybe_incremental(cmd: &mut Command) {
if is_ci() || std::env::var("CARGO_BUILD_INCREMENTAL").map_or(false, |val| val == "false") {
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
cmd.env("CARGO_BUILD_INCREMENTAL", "false");
} else {
// Force incr comp even in release mode unless in CI or incremental builds are explicitly disabled
cmd.env("CARGO_BUILD_INCREMENTAL", "true");
}
}